public void LoadGameStateEventHandler(LoadGameStateEvent e) { Log.Game.Write("Loading game state..."); if (_saveSlot == 0 && e.SaveSlot == 0) { Log.Game.WriteError("Can't load a game without specified slot!"); } else if (e.SaveSlot > 0) { _saveSlot = e.SaveSlot; } string serialized; try { serialized = _fileHelper.ReadTextFromFile(FileLocation.SaveFolder, GetSaveFileName(_saveSlot)); } catch (Exception ex) { Log.Game.WriteError($"Exception when loading game state: {ex.Message}"); return; } InnerStatesContainer = JsonConvert.DeserializeObject <StatesContainer>(serialized, settings); Log.Game.Write($"Load game state from file [{GetSaveFileName(_saveSlot)}]"); Log.Game.Write(InnerStatesContainer.ToString()); }
public StateManager(IGenericStateRepository <GridState> gridStateRepository, IEventsDispatcher eventsDispatcher, IFileHelper fileHelper) { _saveSlot = 0; InnerStatesContainer = new StatesContainer { GridStateRepository = gridStateRepository }; _fileHelper = fileHelper; eventsDispatcher.AddListener <SaveGameStateEvent>(SaveGameStateEventHandler); eventsDispatcher.AddListener <LoadGameStateEvent>(LoadGameStateEventHandler); }