Exemple #1
0
        public Task SaveServiceStateAsync(GameStateMap stateMap)
        {
            var gameState = new GameState()
            {
                PlayedScriptName     = PlayedScript?.Name,
                PlayedIndex          = PlayedIndex,
                IsWaitingForInput    = IsWaitingForInput,
                LastGosubReturnSpots = LastGosubReturnSpots.Count > 0 ? LastGosubReturnSpots.Reverse().ToList() : null // Stack is reversed on enum.
            };

            stateMap.PlaybackSpot = PlaybackSpot;
            stateMap.SetState(gameState);
            return(Task.CompletedTask);
        }
Exemple #2
0
        public async Task LoadServiceStateAsync(GameStateMap stateMap)
        {
            var state = stateMap.GetState <GameState>();

            if (state is null)
            {
                ResetService();
                return;
            }

            Stop(true);

            PlayedIndex = state.PlayedIndex;
            SetWaitingForInputActive(state.IsWaitingForInput);
            if (state.LastGosubReturnSpots != null && state.LastGosubReturnSpots.Count > 0)
            {
                LastGosubReturnSpots = new Stack <PlaybackSpot>(state.LastGosubReturnSpots);
            }
            else
            {
                LastGosubReturnSpots.Clear();
            }

            if (!string.IsNullOrEmpty(state.PlayedScriptName))
            {
                if (PlayedScript is null || !state.PlayedScriptName.EqualsFast(PlayedScript.Name))
                {
                    PlayedScript = await scriptManager.LoadScriptAsync(state.PlayedScriptName);

                    Playlist = new ScriptPlaylist(PlayedScript);
                    var endIndex = providerManager.ResourcePolicy == ResourcePolicy.Static ? Playlist.Count - 1 :
                                   Mathf.Min(PlayedIndex + providerManager.DynamicPolicySteps, Playlist.Count - 1);
                    await Playlist.HoldResourcesAsync(PlayedIndex, endIndex);
                }

                // Start playback and force waiting for input to prevent looping same command when performing state rollback.
                if (stateManager.RollbackInProgress)
                {
                    SetWaitingForInputActive(true);
                    Play();
                }
            }
            else
            {
                Playlist.Clear();
                PlayedScript = null;
            }
        }