[Add] Menu with configs and size fix
This commit is contained in:
@@ -28,6 +28,8 @@ namespace Minesweeper.Infrastructure
|
||||
builder.RegisterInstance(GetConfig());
|
||||
var resolvedUiConfig = GetUiConfig();
|
||||
builder.RegisterInstance(resolvedUiConfig);
|
||||
builder.Register<PlayerPrefsGameSettingsStorage>(Lifetime.Singleton).As<IGameSettingsStorage>();
|
||||
builder.Register<GameSettingsService>(Lifetime.Singleton).As<IGameSettingsService>();
|
||||
builder.Register<GameStateService>(Lifetime.Singleton).As<IGameStateService>();
|
||||
builder.Register<BoardService>(Lifetime.Singleton).As<IBoardService>();
|
||||
builder.Register<GamePauseService>(Lifetime.Singleton).As<IGamePauseService>();
|
||||
@@ -86,7 +88,6 @@ namespace Minesweeper.Infrastructure
|
||||
builder.Register<ResumeCommandHandler>(Lifetime.Singleton);
|
||||
builder.Register<GoToMenuCommandHandler>(Lifetime.Singleton);
|
||||
builder.Register<GameCommandDispatcher>(Lifetime.Singleton).As<IGameCommandDispatcher>();
|
||||
builder.Register<RestartKeyInputService>(Lifetime.Singleton).As<ITickable>();
|
||||
|
||||
builder.Register<MainMenuPresenter>(Lifetime.Singleton);
|
||||
builder.Register<TopPanelPresenter>(Lifetime.Singleton);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using Minesweeper.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minesweeper.Infrastructure
|
||||
{
|
||||
public sealed class PlayerPrefsGameSettingsStorage : IGameSettingsStorage
|
||||
{
|
||||
private const string SizeXKey = "Minesweeper.Settings.SizeX";
|
||||
private const string SizeYKey = "Minesweeper.Settings.SizeY";
|
||||
private const string MinesCountKey = "Minesweeper.Settings.MinesCount";
|
||||
|
||||
public bool TryLoad(out GameSettingsValue value)
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(SizeXKey) || !PlayerPrefs.HasKey(SizeYKey) || !PlayerPrefs.HasKey(MinesCountKey))
|
||||
{
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
value = new GameSettingsValue(PlayerPrefs.GetInt(SizeXKey), PlayerPrefs.GetInt(SizeYKey), PlayerPrefs.GetInt(MinesCountKey));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Save(GameSettingsValue value)
|
||||
{
|
||||
PlayerPrefs.SetInt(SizeXKey, value.SizeX);
|
||||
PlayerPrefs.SetInt(SizeYKey, value.SizeY);
|
||||
PlayerPrefs.SetInt(MinesCountKey, value.MinesCount);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a001fc2e924d95643a075190b6cadda1
|
||||
@@ -1,50 +0,0 @@
|
||||
using Minesweeper.Commands;
|
||||
using Minesweeper.Config;
|
||||
using Minesweeper.Core;
|
||||
using UnityEngine.InputSystem;
|
||||
using VContainer.Unity;
|
||||
|
||||
namespace Minesweeper.Infrastructure
|
||||
{
|
||||
public sealed class RestartKeyInputService : ITickable
|
||||
{
|
||||
private readonly IGameCommandDispatcher commandDispatcher;
|
||||
private readonly MinesweeperGameConfig config;
|
||||
private readonly IGameStateService gameStateService;
|
||||
|
||||
public RestartKeyInputService(IGameCommandDispatcher commandDispatcher, MinesweeperGameConfig config, IGameStateService gameStateService)
|
||||
{
|
||||
this.commandDispatcher = commandDispatcher;
|
||||
this.config = config;
|
||||
this.gameStateService = gameStateService;
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
var keyboard = Keyboard.current;
|
||||
if (keyboard == null || !IsRestartPressed(keyboard))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameStateService.Current == GameState.FieldSelection)
|
||||
{
|
||||
commandDispatcher.Dispatch(new StartGameCommand());
|
||||
}
|
||||
else
|
||||
{
|
||||
commandDispatcher.Dispatch(new RestartCommand());
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsRestartPressed(Keyboard keyboard)
|
||||
{
|
||||
if (config.RestartKey == UnityEngine.KeyCode.R)
|
||||
{
|
||||
return keyboard.rKey.wasPressedThisFrame;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c87c15d092dd420b85a09cc786496948
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user