Esempio n. 1
0
 void Reset()
 {
     current             = new GameProgressData();
     current.uid         = System.Guid.NewGuid().ToString();
     current.createdDate = System.DateTime.Now.Ticks;
     current.isFreshSave = true;
 }
Esempio n. 2
0
    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);
    }
Esempio n. 5
0
 /// <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();
     }
 }
Esempio n. 6
0
        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}'");
    }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
    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);
    }
Esempio n. 10
0
    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);
    }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
    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");
        }
Esempio n. 14
0
    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);
            }
        }
    }
Esempio n. 15
0
    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);
    }
Esempio n. 16
0
    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);
        }
    }
Esempio n. 17
0
    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();
    }
Esempio n. 18
0
    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();
        }
    }
Esempio n. 19
0
    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);
            }
        }
    }
Esempio n. 20
0
    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);
        }
    }
Esempio n. 21
0
 /// <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)");
        }
Esempio n. 23
0
 private void Awake()
 {
     Instance = this;
     GameProgressData.LoadProgress();
 }
Esempio n. 24
0
 private void Awake()
 {
     Instance = this;
     GameProgressData.LoadProgress();
     GameProgressData.EnableSave = true;
 }