public void Save(string fileName) { EnsureDirectoryExists(fileName); var saveState = GetSaveState(); File.WriteAllText(fileName, SaveStateSerializer.Serialize(saveState)); _systemContainer.MessageSystem.Write("Saved!", Color.Blue); }
public void Load() { var directoryName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Saves"); var fileName = Path.Combine(directoryName, "saveFile.sav"); var loadedState = SaveStateSerializer.Deserialize(File.ReadAllText(fileName)); _systemContainer.TimeSystem.CurrentTime = loadedState.Time; _systemContainer.Seed = loadedState.Seed; _systemContainer.MapSystem.Initialise(); _systemContainer.EntityEngine.Initialise(_systemContainer); foreach (var savedEntity in loadedState.Entities) { var entity = EntitySerializer.Deserialize(_systemContainer, savedEntity); if (entity.Name == "Player") { _systemContainer.PlayerSystem.Player = entity; } } foreach (var savedMap in loadedState.Maps) { var map = MapSerializer.Deserialize(_systemContainer, savedMap); _systemContainer.MapSystem.MapCollection.Add(map.MapKey, map); } _systemContainer.MessageSystem.Initialise(); foreach (var savedMessage in loadedState.Messages) { var message = MessageSerializer.Deserialize(savedMessage); _systemContainer.MessageSystem.AllMessages.Add(message); } }