public void Load() { CheckFileDir(); var jsonData = File.ReadAllText(FileLocation); try { var loadedData = JsonConvert.DeserializeObject <SavableGame>(jsonData); World = loadedData.World; CharacterData = loadedData.CharacterData; CharacterData.Load(); if (!File.Exists(FileLocation)) { throw new Exception($"Save file not found at: {FileLocation}"); } var wc = DI.Fetch <WorldController>(); wc.Data = World; DI.Register(this); } catch (Exception) { throw new Exception("File is broken"); } }
/// <summary> /// Creates new game with default values /// </summary> /// <param name="title">New games title + file name</param> /// <param name="seed">Generation seed</param> public void CreateNewGame(string title, [CanBeNull] string seed = null) { World = new WorldData { Title = title, DungeonFloor = 1 }; CharacterData = new SavableCharacter { HP = 100, MP = 20, Inventory = new[] { new SavableItem { Durability = 1, Grade = ItemGrade.E, ItemId = 214, LocalId = 1 }, new SavableItem { Durability = 1, Grade = ItemGrade.E, ItemId = 500, LocalId = 2 }, new SavableItem { Durability = 1, Grade = ItemGrade.E, ItemId = 501, LocalId = 3 } }, SavableEquipment = new List <int> { 1 }, Attributes = new AttributeData { Agility = 0, Luck = 0, Magic = 0, Points = 5, Resistance = 0, Strength = 0, Vitality = 0 } }; PlayerPrefs.SetString("CurrentGame", title); WorldController.PopulateFloorSeeds(World, seed); Save(); }