void Reset() { current = new GameProgressData(); current.uid = System.Guid.NewGuid().ToString(); current.createdDate = System.DateTime.Now.Ticks; current.isFreshSave = true; }
public bool LoadOrStartNew(IEnumerable <Savable> savables) { bool newGame = false; if (gameProgressStorage.IsSlotExists(currentGameSlotIndex)) { current = gameProgressStorage.Load(currentGameSlotIndex); if (!current.isFreshSave) { LoadToScene(savables); } else { newGame = true; } //if save corrupted(empty progress, reset progress) if (current == null) { Reset(); } current.isFreshSave = false; } else { ResetAndSave(); } return(newGame); }
GameProgressData DefaultData() { var data = new GameProgressData(); data.uid = System.Guid.NewGuid().ToString(); data.createdDate = System.DateTime.Now.Ticks; return(data); }
/// <summary> /// get signed data in similar to JWT format {base64:content}.{base64:signature} /// </summary> /// <returns></returns> string GetSignedData(GameProgressData data) { string signedDate = string.Empty; var unsignedData = JsonUtility.ToJson(data); string signature = GetSignature(unsignedData); signedDate = Convert.ToBase64String(Encoding.UTF8.GetBytes(unsignedData)) + splitter + signature; return(signedDate); }
/// <summary> /// Loads the game progress from file. /// </summary> public void LoadGameProgress() { if (File.Exists(Application.persistentDataPath + gameProgressFile) == true) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + gameProgressFile, FileMode.Open); progress = (GameProgressData)bf.Deserialize(file); file.Close(); } }
void IGameSimulation.OnClientGameBegin() { currentData = new GameProgressData { flagsRemaining = board.flagsRemaining }; OnClientGameUpdate(); state = GameState.InProgress; }
public void Save(int slotIndex, GameProgressData data) { if (slotIndex < 0) { throw new System.ArgumentException($"Invalid save file slot index: {slotIndex}"); } var path = GetSaveFilePath(slotIndex); File.WriteAllText(path, GetSignedData(data), Encoding.UTF8); //Debug.Log($"Data saved to '{path}'"); }
private void LoadData() { gamesPlayed = PlayerPrefs.GetInt(GAMES_PLAYED); gameProgressData = gameProgressDataInitializer.Load(); Adjust(gameProgressData, groupsDataInitializer.Data); groupIndex = GetGroupIndex(PlayerPrefs.GetString(GROUP_NAME)); drawingIndex = GetDrawingIndex(PlayerPrefs.GetString(DRAWING_NAME), groupIndex); mapIndex = PlayerPrefs.GetInt(MAP_INDEX); }
void SelectCharacter(string characterTag) { bool isUnLocked = GameProgressData.CharacterIsUnlocked(characterTag); if (!isUnLocked) { return; } PlayerPrefs.SetString(PlayerPrefsNames.SelectedCharacterTag, characterTag); PlayerPrefs.Save(); PlayableCharacters.Instance.SetCharacterToHumanControlled(characterTag, showChangeEffect: true); }
public bool IsIdentical(GameProgressData dataToTest) { var fields = this.GetType().GetFields(System.Reflection.BindingFlags.Public); foreach (var field in fields) { //this will work if we dont use reference types if (field.GetValue(this) != field.GetValue(dataToTest)) { return(false); } } return(true); }
private void Adjust(GameProgressData gameProgressData, GameData gameConfigData) { List <GroupProgressData> orderedData = new List <GroupProgressData>(gameConfigData.Groups.Length); foreach (var groupConfigData in gameConfigData.Groups) { GroupProgressData groupProgressData = GetByName(gameProgressData.Groups, groupConfigData.Name); Adjust(groupProgressData, groupConfigData); orderedData.Add(groupProgressData); } gameProgressData.Groups.Clear(); gameProgressData.Groups.AddRange(orderedData); }
public static void LoadProgress() { string json = PlayerPrefs.GetString(PlayerPrefsNames.Progress); if (string.IsNullOrWhiteSpace(json)) { CurrentProgress = new GameProgressData(); } else { CurrentProgress = JsonUtility.FromJson <GameProgressData>(json); } if (CurrentProgress.Version < GameProgressData.RequiredVersion) { CurrentProgress = new GameProgressData(); } }
public void Should_GameProgressDataIdentical_When_SaveAndLoad() { //Arrange int saveSlotIndex = 0; var data = DefaultData(); GameProgressData loadData = null; var sut = BuildSUT(); //Act sut.Save(saveSlotIndex, data); loadData = sut.Load(saveSlotIndex); //Assert var path = sut.GetSaveFilePath(saveSlotIndex); Assert.True(data.uid.IsValidGuid(), "Initial test data is not set"); Assert.True(data.IsIdentical(loadData), "Saved file is missing"); }
void CreateCharacters() { for (int i = 0; i < PlayableCharacters.Instance.CharacterPrefabList.CharacterPrefabs.Length; ++i) { var characterPrefab = PlayableCharacters.Instance.CharacterPrefabList.CharacterPrefabs[i]; var position = CharacterDefaultPositions[i].position; bool isUnlocked = GameProgressData.CharacterIsUnlocked(characterPrefab.tag); if (isUnlocked) { CreateCharacter(characterPrefab.tag, position); } else { CreateGhost(characterPrefab.tag, position); } } }
public void SetupSaveData() { GameProgressData data = SaveLoadManager.GetInstance.saveData.gameProgressData; _powerUpPickedUp = data.powerUpPickedUp; _healthUpgradesPickedUp = data.healthUpgradePickedUp; //debug string[] names = new string[] { "doublejumpItem-", "dashitem-", "walljumpItem-" }; string all = "PICKEDUP ITEMS : "; for (int i = 0; i < _powerUpPickedUp.Length; i++) { all += names[i] + _powerUpPickedUp[i] + ", "; } print(all); }
void OnPlayerNameUpdated() { ButtonPlayerNameOk.interactable = true; if (!string.IsNullOrEmpty(PlayFabFacade.Instance.LastError)) { PlayerNameErrorText.text = $"Error: {PlayFabFacade.Instance.LastError}"; PlayerNameErrorText.gameObject.SetActive(true); } else { GameProgressData.CurrentProgress.PlayerName = EnterNameInput.text; GameProgressData.SaveProgress(); PlayerNameText.text = GameProgressData.CurrentProgress.PlayerName; PlayerInfoScript.Instance.ShowInfo($"Welcome, {GameProgressData.CurrentProgress.PlayerName}", Color.green); EnterNameCanvas.gameObject.SetActive(false); } }
void ActivateLatestSelectedCharacter() { string startCharacterTag = PlayerPrefs.GetString(PlayerPrefsNames.SelectedCharacterTag); if (string.IsNullOrEmpty(startCharacterTag)) { startCharacterTag = "Character1"; } // When developing we might experience the selected character is no longer unlocked. Revert to default. bool isUnlocked = GameProgressData.CharacterIsUnlocked(startCharacterTag); if (!isUnlocked) { startCharacterTag = PlayableCharacters.Instance.CharacterPrefabList.CharacterPrefabs[0].tag; } PlayableCharacters.Instance.SetCharacterToHumanControlled(startCharacterTag); Helpers.SetCameraPositionToActivePlayer(); }
public void OnCollect() { completionPending_ = false; if (activateQuestOnButtonPress_) { CampScript.Instance.ActivateQuest(quest_.Id); } else { // Collecting reward progress_.CollectQuest(quest_.Id); SetQuest(quest_, progress_); QuestGiverScript.Instance.CompleteParticles.transform.position = this.transform.position; QuestGiverScript.Instance.CompleteParticles.Emit(21); AudioManager.Instance.PlaySfxClip(QuestGiverScript.Instance.CompleteSound, 5, 0, 1.0f); AudioManager.Instance.PlaySfxClip(QuestGiverScript.Instance.CompleteSound, 5, 0, 0.90f); AudioManager.Instance.PlaySfxClip(QuestGiverScript.Instance.CompleteSound, 5, 0, 1.1f); GameProgressData.SaveProgress(); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { SelectCharacter(PlayableCharacters.Instance.CharacterPrefabList.CharacterPrefabs[0].tag); } if (Input.GetKeyDown(KeyCode.Alpha2)) { SelectCharacter(PlayableCharacters.Instance.CharacterPrefabList.CharacterPrefabs[1].tag); } if (Input.GetKeyDown(KeyCode.Alpha3)) { SelectCharacter(PlayableCharacters.Instance.CharacterPrefabList.CharacterPrefabs[2].tag); } if (Input.GetKeyDown(KeyCode.F12)) { if (resetProgressCount++ > 5) { GameProgressData.RestartProgress(); PlayerInfoScript.Instance.ShowInfo("Progress Reset", Color.red); } } }
IEnumerator InCamp() { Time.timeScale = 1.0f; CampCanvas.gameObject.SetActive(true); CampfireSoundSource.enabled = true; LightingFadeTo(isInGraveyard_ ? GraveyardLightingSettings : CampLightingSettings, transitionSpeed: 20); IntroCanvas.enabled = false; StartCoroutine(SceneGlobals.Instance.AudioManager.SetAudioProfile(AudioManager.eScene.InGame)); ShowPlayerName(true); if (string.IsNullOrWhiteSpace(GameProgressData.CurrentProgress.PlayerName)) { GameProgressData.CurrentProgress.PlayerName = $"Anonymous-{Random.Range(100000, 999999)}"; GameProgressData.SaveProgress(); ShowEnterName(); } else { PlayerNameText.text = GameProgressData.CurrentProgress.PlayerName; PlayerInfoScript.Instance.ShowInfo($"Welcome back, {GameProgressData.CurrentProgress.PlayerName}", Color.green); } if (!ghostScript_.IsStarted) { ghostScript_.Wander(GhostPath, 2.0f + Random.value * 3); } SceneGlobals.Instance.AudioManager.StopMusic(); nextFlash = Time.time + 3 + Random.value * 3; while (true) { UpdateThunder(Time.time); // Quick hacky solution to prevent entering name from triggering other stuff. Skip the checks. if (EnterNameCanvas.gameObject.activeInHierarchy) { if (Input.GetKeyDown(KeyCode.Escape)) { CloseEnterName(saveName: false); } if (Input.GetKeyDown(KeyCode.Return)) { CloseEnterName(saveName: true); } yield return(null); } else { if (Input.GetKeyDown(KeyCode.N)) { ShowEnterName(); } if (Input.GetKeyDown(KeyCode.Escape)) { StartCoroutine(InMenu()); yield break; } else if (Input.GetKeyDown(KeyCode.M)) { StartCoroutine(ShowOptions()); yield break; } } yield return(null); } }
/// <summary> /// Delete file with saved game data. For debug only /// </summary> public void DeleteGameProgress() { File.Delete(Application.persistentDataPath + gameProgressFile); progress = new GameProgressData(); Debug.Log("Saved game progress deleted"); }
public void Should_AllGameProgressDataSuccessfulyLoad_When_SaveAndLoad() { //Arrange int saveSlotIndex = 0; string uid = System.Guid.NewGuid().ToString(); var dateTime = System.DateTime.Now; var playerPosition = new Vector3(1, 2, 3); var playerScaleX = -1;//direction //key 1 in slot 2 var key1ItemUid = StringResources.ObjectIds.Key_01; var itemSlot1Uid = StringResources.ObjectIds.ItemSlot1; var itemSlot1_ItemUid = key1ItemUid;//Key01 in inventory //key 2 in pillar 2 var pillar2Uid = StringResources.ObjectIds.KeyPillar_02; var key2ItemUid = StringResources.ObjectIds.Key_02; var data = new GameProgressData(); data.uid = uid; data.createdDate = dateTime.Ticks; data.playerPosition = new SerializableVector3(playerPosition); data.playerScaleX = playerScaleX; data.SaveItemSlot(itemSlot1Uid, itemSlot1_ItemUid); data.SaveItem(key1ItemUid, itemSlot1Uid, null); data.SaveItem(key2ItemUid, null, pillar2Uid); GameProgressData loadData = null; var sut = BuildSUT(); //Act sut.Save(saveSlotIndex, data); loadData = sut.Load(saveSlotIndex); //Assert Assert.AreEqual(uid, loadData.uid); Assert.AreEqual(dateTime.Ticks, loadData.createdDate); Assert.True(playerPosition == loadData.playerPosition, "playerPosition"); Assert.AreEqual(playerScaleX, data.playerScaleX, "playerScaleX"); //item slots Assert.NotNull(loadData.ItemSlots, "Item slots not saved"); var loadedSlot1 = loadData.ItemSlots.FirstOrDefault(i => i.uid == itemSlot1Uid); Assert.NotNull(loadedSlot1, "Item slots 1 not saved"); Assert.AreEqual(itemSlot1Uid, loadedSlot1.uid, "Item slot 1 data invalid (Slot Uid)"); Assert.AreEqual(itemSlot1_ItemUid, loadedSlot1.itemUid, "Item slot 1 data invalid (item Uid)"); //items Assert.NotNull(loadData.Items, "Items not saved"); //item1 (key1) in slot1 var loadedKey1 = loadData.Items.FirstOrDefault(i => i.uid == key1ItemUid); Assert.NotNull(loadedKey1, $"{nameof(loadedKey1)} not saved"); Assert.AreEqual(itemSlot1Uid, loadedKey1.slotUid, $"{nameof(loadedKey1)} data invalid (slot Uid)"); Assert.AreEqual(ItemState.InInventory, loadedKey1.state, $"{nameof(loadedKey1)} data invalid (state)"); //item 2(key2) inside pillar var loadedKey2 = loadData.Items.FirstOrDefault(i => i.uid == key2ItemUid); Assert.NotNull(loadedKey2, $"{nameof(loadedKey2)} not saved"); Assert.AreEqual(pillar2Uid, loadedKey2.dropTargetUid, $"{nameof(loadedKey2)} data invalid (dropTarget Uid)"); Assert.AreEqual(ItemState.PlacedOnDropTarget, loadedKey2.state, $"{nameof(loadedKey2)} data invalid (state)"); }
private void Awake() { Instance = this; GameProgressData.LoadProgress(); }
private void Awake() { Instance = this; GameProgressData.LoadProgress(); GameProgressData.EnableSave = true; }