public void SaveGameFile() { string filePath = FileManager.savPath + "savData/gameFiles/" + activeGameFileName + ".txt"; activeGameFile.chapterName = activeChapterFile; activeGameFile.chapterProgress = chapterProgress; activeGameFile.cachedLastSpeaker = cachedLastSpeaker; activeGameFile.currentTextSystemSpeakerNameText = DialogueSystem.instance.speakerNameText.text; activeGameFile.currentTextSystemDisplayText = DialogueSystem.instance.speechText.text; //get all the characters and save their stats. activeGameFile.charactersInScene.Clear(); for (int i = 0; i < CharacterManager.instance.characters.Count; i++) { Character character = CharacterManager.instance.characters[i]; GAMEFILE.CHARACTERDATA data = new GAMEFILE.CHARACTERDATA(character); activeGameFile.charactersInScene.Add(data); } //save the layers to disk BCFC b = BCFC.instance; activeGameFile.background = b.background.activeImage != null ? b.background.activeImage.texture : null; activeGameFile.cinematic = b.cinematic.activeImage != null ? b.cinematic.activeImage.texture : null; activeGameFile.foreground = b.foreground.activeImage != null ? b.foreground.activeImage.texture : null; //save the music to disk activeGameFile.music = AudioManager.activeSong != null ? AudioManager.activeSong.clip : null; //save the ambiance to disk if there is any playing. activeGameFile.ambiance = AudioManager.activeAmbianceClips; //save the tempvals to disk. for easy variable storage. activeGameFile.tempVals = CACHE.tempVals; //save a preview image (screenshot) to be viewed from the save load screen string screenShotPath = FileManager.savPath + "savData/gameFiles/" + activeGameFileName + ".png"; if (FileManager.TryCreateDirectoryFromPath(screenShotPath + ".png")) { GAMEFILE.activeFile.previewImage = ScreenCapture.CaptureScreenshotAsTexture(); byte[] textureData = activeGameFile.previewImage.EncodeToPNG(); FileManager.SaveComposingBytes(screenShotPath, textureData); } //save the data and time this file was created or modified. activeGameFile.modificationDate = System.DateTime.Now.ToString(); if (encryptGameFile) { FileManager.SaveEncryptedJSON(filePath, activeGameFile, keys); } else { FileManager.SaveJSON(filePath, activeGameFile); } }
public void LoadGameFile(string gameFileName) { activeGameFileName = gameFileName; string filePath = FileManager.savPath + "savData/gameFiles/" + activeGameFileName + ".txt"; if (!System.IO.File.Exists(filePath)) { activeGameFile = new GAMEFILE();//don't save because we want a new one to start whenever we hit new game. any save is manual. } else { if (encryptGameFile) { activeGameFile = FileManager.LoadEncryptedJSON <GAMEFILE>(filePath, keys); } else { activeGameFile = FileManager.LoadJSON <GAMEFILE>(filePath); } } //Load the file. Anything in the Resources folder should be loaded by Resources only. TextAsset chapterAsset = Resources.Load <TextAsset>("Story/" + activeGameFile.chapterName); data = FileManager.ReadTextAsset(chapterAsset); activeChapterFile = activeGameFile.chapterName; cachedLastSpeaker = activeGameFile.cachedLastSpeaker; DialogueSystem.instance.Open(activeGameFile.currentTextSystemSpeakerNameText, activeGameFile.currentTextSystemDisplayText); //Load all characters back into the scene for (int i = 0; i < activeGameFile.charactersInScene.Count; i++) { GAMEFILE.CHARACTERDATA data = activeGameFile.charactersInScene[i]; Character character = CharacterManager.instance.CreateCharacter(data.characterName, data.enabled); character.displayName = data.displayName; character.canvasGroup.alpha = 1;//any saved character should start with an alpha of 1 since they already entered at one point in time and any character that should have an alpha of zero would already have been removed. character.SetBody(data.bodyExpression); character.SetExpression(data.facialExpression); if (data.facingLeft) { character.FaceLeft(); } else { character.FaceRight(); } character.SetPosition(data.position); } //Load the layer images back into the scene if (activeGameFile.background != null) { BCFC.instance.background.SetTexture(activeGameFile.background); } if (activeGameFile.cinematic != null) { BCFC.instance.cinematic.SetTexture(activeGameFile.cinematic); } if (activeGameFile.foreground != null) { BCFC.instance.foreground.SetTexture(activeGameFile.foreground); } //start the music back up if (activeGameFile.music != null) { AudioManager.instance.PlaySong(activeGameFile.music); } //start the ambiance back up if (activeGameFile.ambiance.Count > 0) { foreach (AudioClip clip in activeGameFile.ambiance) { AudioManager.instance.PlayAmbiance(clip); } } //load the temporary variables back CACHE.tempVals = activeGameFile.tempVals; if (handlingChapterFile != null) { StopCoroutine(handlingChapterFile); } handlingChapterFile = StartCoroutine(HandlingChapterFile()); chapterProgress = activeGameFile.chapterProgress; }
public void LoadGameFile(string gameFileName) { string filePath = FileManager.savPath + "savData/gameFiles/" + activeGameFileName + ".txt"; if (!System.IO.File.Exists(filePath)) { FileManager.SaveJSON(filePath, new GAMEFILE()); } /* From stellar later. Above == my older (working?) system * if (!System.IO.File.Exists(filePath)) * { * activeGameFile = new GAMEFILE();//don't save because we want a new one to start whenever we hit new game. any save is manual. * } * else * { * activeGameFile = FileManager.LoadJSON<GAMEFILE>(filePath); * } */ //Load the file. Anything in the Resources folder should be loaded by Resources only. Debug.Log("***Loading chapter name: " + activeGameFile.chapterName); TextAsset chapterAsset = Resources.Load <TextAsset>("Story/" + activeGameFile.chapterName); data = FileManager.ReadTextAsset(chapterAsset); activeChapterFile = activeGameFile.chapterName; cachedLastSpeaker = activeGameFile.cachedLastSpeaker; DialogueSystem.instance.Open(activeGameFile.currentTextSystemSpeakerNameText, activeGameFile.currentTextSystemDisplayText); //Load all characters back into the scene for (int i = 0; i < activeGameFile.charactersInScene.Count; i++) { GAMEFILE.CHARACTERDATA data = activeGameFile.charactersInScene[i]; Character character = CharacterManager.instance.CreateCharacter(data.characterName, data.enabled); // character.SetBody(data.bodyExpression); // character.SetExpression(data.facialExpression); if (data.facingLeft) { character.FaceLeft(); } else { character.FaceRight(); } character.SetPosition(data.position); } //Load the layer images back into the scene if (activeGameFile.background != null) { BCFC.instance.background.SetTexture(activeGameFile.background); } if (activeGameFile.cinematic != null) { BCFC.instance.cinematic.SetTexture(activeGameFile.cinematic); } if (activeGameFile.foreground != null) { BCFC.instance.foreground.SetTexture(activeGameFile.foreground); } //start the music back up if (activeGameFile.music != null) { AudioManager.instance.PlaySong(activeGameFile.music); } if (handlingChapterFile != null) { StopCoroutine(handlingChapterFile); } handlingChapterFile = StartCoroutine(HandlingChapterFile()); chapterProgress = activeGameFile.chapterProgress; //I don't think I need this vvv But it makes me feel better having it there. It works without it, but... CACHE.tempVals = activeGameFile.cache; }