public void Initialize() { string currentPath; if (!File.Exists(Application.persistentDataPath + "\\CurrentSavePath")) { currentPath = Application.persistentDataPath + "\\TestSave"; } else { currentPath = File.ReadAllLines(Application.persistentDataPath + "\\CurrentSavePath")[0]; } if (File.Exists(currentPath)) { // Load string json = File.ReadAllText(currentPath); save = JsonUtility.FromJson <PlayerSave>(json); if (save.timePlayed != 0) { player.spawnPoint = save.position; } if (SectorManager.testJsonPath != null) { save.resourcePath = SectorManager.testJsonPath; } else if (save.resourcePath == "") { save.resourcePath = SectorManager.jsonPath; } player.cursave = save; SectorManager.instance.LoadSectorFile(save.resourcePath); taskManager.Initialize(true); // Re-init DialogueSystem.InitCanvases(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; if (save.currentPlayerBlueprint != null && save.currentPlayerBlueprint != "") { JsonUtility.FromJsonOverwrite(save.currentPlayerBlueprint, player.blueprint); } else { Debug.LogError("Save should have been given a currentPlayerBlueprint by now."); player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; } player.abilityCaps = save.abilityCaps; player.shards = save.shards; player.SetCredits(save.credits); player.reputation = save.reputation; if (save.presetBlueprints.Length != 5) { save.presetBlueprints = new string[5]; } Camera.main.GetComponent <CameraScript>().Initialize(player); taskManager.taskVariables.Clear(); for (int i = 0; i < save.taskVariableNames.Length; i++) { taskManager.taskVariables.Add(save.taskVariableNames[i], save.taskVariableValues[i]); } } else { Debug.LogError("There was not a save or test save that was ready on load."); save = new PlayerSave(); save.presetBlueprints = new string[5]; save.currentHealths = new float[] { 1000, 250, 500 }; save.partInventory = new List <EntityBlueprint.PartInfo>(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.cursave = save; player.abilityCaps = CoreUpgraderScript.minAbilityCap; } }
public void Initialize() { instance = this; string currentPath; var CurrentSavePath = System.IO.Path.Combine(Application.persistentDataPath, "CurrentSavePath"); if (!File.Exists(CurrentSavePath)) { currentPath = System.IO.Path.Combine(Application.persistentDataPath, "TestSave"); } else { currentPath = File.ReadAllLines(CurrentSavePath)[0]; } if (File.Exists(currentPath)) { // Load string json = File.ReadAllText(currentPath); save = JsonUtility.FromJson <PlayerSave>(json); if (save.timePlayed != 0) { player.spawnPoint = save.position; player.Dimension = save.lastDimension; } if (SectorManager.testJsonPath != null) { save.resourcePath = SectorManager.testJsonPath; } else if (save.resourcePath == "") { save.resourcePath = SectorManager.jsonPath; } player.cursave = save; if (save.factions != null) { for (int i = 0; i < save.factions.Length; i++) { FactionManager.SetFactionRelations(save.factions[i], save.relations[i]); } } SectorManager.instance.LoadSectorFile(save.resourcePath); save.missions.RemoveAll(m => !taskManager.questCanvasPaths.Exists(p => System.IO.Path.GetFileNameWithoutExtension(p) == m.name)); taskManager.Initialize(true); // Re-init DialogueSystem.InitCanvases(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; if (!string.IsNullOrEmpty(save.currentPlayerBlueprint)) { var print = SectorManager.TryGettingEntityBlueprint(save.currentPlayerBlueprint); player.blueprint = print; } else { Debug.LogError("Save should have been given a currentPlayerBlueprint by now."); player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; } player.abilityCaps = save.abilityCaps; player.shards = save.shards; player.SetCredits(save.credits); player.reputation = save.reputation; if (save.presetBlueprints.Length != 5) { save.presetBlueprints = new string[5]; } Camera.main.GetComponent <CameraScript>().Initialize(player); taskManager.taskVariables.Clear(); for (int i = 0; i < save.taskVariableNames.Length; i++) { taskManager.taskVariables.Add(save.taskVariableNames[i], save.taskVariableValues[i]); } } else { Debug.LogError("There was not a save or test save that was ready on load."); save = new PlayerSave(); save.presetBlueprints = new string[5]; save.currentHealths = new float[] { 1000, 250, 500 }; save.partInventory = new List <EntityBlueprint.PartInfo>(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.cursave = save; player.abilityCaps = CoreUpgraderScript.minAbilityCap; } }