Beispiel #1
0
    private void Update()
    {
        if (_informerGames != null && _informerGames.loaded)
        {
            dropdownGames.options = new List <Dropdown.OptionData>();
            dropdownGames.options.Add(new Dropdown.OptionData("Choose one"));
            foreach (JengaData data in _informerGames.data.games)
            {
                dropdownGames.options.Add(
                    new Dropdown.OptionData($"{data.id} - {new DateTime(data.date)}")
                    );
            }
            _currentData   = _informerGames.data;
            _informerGames = null;
            return;
        }

        if (!_loadGames)
        {
            return;
        }
        _loadGames     = false;
        _informerGames = Config.LoadGamesData();
    }
Beispiel #2
0
    /// <summary>
    /// Keeps going with the saving of the jenga game
    /// from where we left off on SaveJengaGame()
    /// </summary>
    private void KeepSavingJengaGame()
    {
        bool checkIfTheGameFinishedSaving = !_loadingData && _loadingSavedGamesData != null;

        if (checkIfTheGameFinishedSaving)
        {
            if (_loadingSavedGamesData.loaded || _loadingSavedGamesData.error)
            {
                _activator.LoadGames();
                _loadingSavedGamesData = null;
            }
        }
        bool checkIfThereIsDataLoadingOrSaving = !_loadingData || _loadingSavedGamesData == null;

        if (checkIfThereIsDataLoadingOrSaving)
        {
            return;
        }
        if (_loadingSavedGamesData.error)
        {
            _loadingData           = false;
            _loadingSavedGamesData = null;
            return;
        }
        if (!_loadingSavedGamesData.loaded)
        {
            return;
        }
        // This means that the GameData finished loading, so we must modify it
        // and save it with our new data
        SavedGamesData dataGame            = _loadingSavedGamesData.data;
        int            idWeAreSearchingFor = _data.id;
        int            idx = -1;

        Debug.Log(idWeAreSearchingFor);
        // Find if our game exists.
        for (int i = 0; i < dataGame.games.Length; ++i)
        {
            if (dataGame.games[i].id != idWeAreSearchingFor)
            {
                continue;
            }

            idx = i;
            break;
        }
        // If it does not exist add it into the game
        if (idx == -1)
        {
            int oldSize = dataGame.games.Length;
            Array.Resize(ref dataGame.games, oldSize + 1);
            dataGame.games[oldSize] = _data;
            LoadJengaConfig(dataGame.games[oldSize]);
        }
        // It exists
        else
        {
            dataGame.games[idx].jengas = _data.jengas;
            dataGame.games[idx].date   = _data.date;
            LoadJengaConfig(dataGame.games[idx]);
        }

        // Save again and get the informer so we can check on checkIfTheGameFinishedSaving
        _loadingSavedGamesData = SaveSystem.SaveOnAnotherThread("game_data.json", dataGame);
        _loadingData           = false;
    }