public override async Task LoadServiceStateAsync(GameStateMap stateMap) { await base.LoadServiceStateAsync(stateMap); var state = stateMap.GetState <GameState>(); if (state is null) { if (charIdToAvatarPathMap.Count > 0) { foreach (var charId in charIdToAvatarPathMap.Keys.ToList()) { RemoveAvatarTextureFor(charId); } } return; } // Remove non-existing avatar mappings. if (charIdToAvatarPathMap.Count > 0) { foreach (var charId in charIdToAvatarPathMap.Keys.ToList()) { if (!state.CharIdToAvatarPathMap.ContainsKey(charId)) { RemoveAvatarTextureFor(charId); } } } // Add new or changed avatar mappings. foreach (var kv in state.CharIdToAvatarPathMap) { SetAvatarTexturePathFor(kv.Key, kv.Value); } }
public virtual async UniTask LoadServiceStateAsync(GameStateMap stateMap) { var state = stateMap.GetState <GameState>(); if (state is null) { RemoveAllActors(); return; } // Remove actors that doesn't exist in the serialized state. if (ManagedActors.Count > 0) { foreach (var actorId in ManagedActors.Keys.ToList()) { if (!state.ActorsMap.ContainsKey(actorId)) { RemoveActor(actorId); } } } foreach (var kv in state.ActorsMap) { var actor = await GetOrAddActorAsync(kv.Key); kv.Value.ApplyToActor(actor); } }
public virtual async Task LoadServiceStateAsync(GameStateMap stateMap) { var state = stateMap.GetState <GameState>(); if (state is null) { RemoveAllActors(); return; } // Remove actors that doesn't exist in the serialized state. if (ManagedActors.Count > 0) { foreach (var actorId in ManagedActors.Keys.ToList()) { if (!state.ActorState.Exists(s => s.Id.EqualsFast(actorId))) { RemoveActor(actorId); } } } foreach (var actorState in state.ActorState) { var actor = await GetOrAddActorAsync(actorState.Id); actorState.ApplyToActor(actor); } }
public override async UniTask LoadServiceStateAsync(GameStateMap stateMap) { await base.LoadServiceStateAsync(stateMap); var state = stateMap.GetState <GameState>() ?? new GameState(); DefaultPrinterId = state.DefaultPrinterId ?? Configuration.DefaultPrinterId; }
public virtual async UniTask LoadServiceStateAsync(GameStateMap stateMap) { var state = stateMap.GetState <GameState>(); if (state is null) { ResetService(); return; } // Force stop and cancel all running commands to prevent state mutation while loading other services. Stop(); CancelCommands(); executedPlayedCommand = state.ExecutedPlayedCommand; if (state.Playing) // The playback is resumed (when necessary) after other services are loaded. { if (stateManager.RollbackInProgress) { stateManager.OnRollbackFinished += PlayAfterRollback; } else { stateManager.OnGameLoadFinished += PlayAfterLoad; } } if (state.GosubReturnSpots != null && state.GosubReturnSpots.Count > 0) { GosubReturnSpots = new Stack <PlaybackSpot>(state.GosubReturnSpots); } else { GosubReturnSpots.Clear(); } if (!string.IsNullOrEmpty(stateMap.PlaybackSpot.ScriptName)) { if (PlayedScript is null || !stateMap.PlaybackSpot.ScriptName.EqualsFast(PlayedScript.Name)) { PlayedScript = await scriptManager.LoadScriptAsync(stateMap.PlaybackSpot.ScriptName); Playlist = new ScriptPlaylist(PlayedScript, scriptManager); PlayedIndex = Playlist.IndexOf(stateMap.PlaybackSpot); Debug.Assert(PlayedIndex >= 0, $"Failed to load script player state: `{stateMap.PlaybackSpot}` doesn't exist in the current playlist."); var endIndex = providerConfig.ResourcePolicy == ResourcePolicy.Static ? Playlist.Count - 1 : Mathf.Min(PlayedIndex + providerConfig.DynamicPolicySteps, Playlist.Count - 1); await Playlist.PreloadResourcesAsync(PlayedIndex, endIndex); } else { PlayedIndex = Playlist.IndexOf(stateMap.PlaybackSpot); } }
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; } }