/// <summary> /// Received when a story has been loaded. This will load up the initial values from the database /// </summary> /// <param name="e"></param> void OnStoryLoadedEvent(Story.LoadedEvent e) { // Set the name and gender var playerName = Game.current.PlayerName; var playerGender = Game.current.Progress.GetStringValue("PlayerGender"); var playerWeek = Game.current.Progress.GetIntValue("week"); var currentRoom = Game.current.CurrentRoom.ToString(); reader.SetVariableValue("player_name", playerName); reader.SetVariableValue("player_gender", playerGender); reader.SetVariableValue("current_room", currentRoom); reader.SetVariableValue("week", playerWeek); // Set all initial values foreach (var pair in stats) { var name = pair.Value.name; var value = pair.Value.Get(); Trace.Script($"Setting {name} to {value}", this); reader.SetVariableValue(name, value); } // Set up variable observers after the story ends? reader.gameObject.Dispatch <Story.ObserveVariablesEvent>(new Story.ObserveVariablesEvent() { variableNames = statNames, variableObserver = ObserveVariable }); }
void OnStoryLoadedEvent(Story.LoadedEvent e) { if (ValidateStory(e)) { Activate(); } }
/// <summary> /// Loads a story from file /// </summary> /// <param name="storyFile"></param> private void LoadStory(TextAsset storyFile, bool restart = false, string knot = null) { Story newStory = null; // If this story has already been loaded, use the previous state bool previouslyLoaded = storySave.HasStory(storyFile); if (previouslyLoaded) { if (debug) { Trace.Script($"{storyFile.name} has already been loaded! Using the previous state."); } newStory = storySave.stories[storyFile.name]; LoadState(newStory); } // If the story hasn't been loaded yet else { if (debug) { Trace.Script($"{storyFile.name} has not been loaded yet. Constructing a new state."); } newStory = ConstructStory(storyFile); storySave.AddStory(newStory); } // Assign the story storySave.SetCurrentStory(newStory); //story = newStory; // If a knot was provided if (knot != null && knot.Length > 0) { if (!story.runtime.canContinue) { if (automaticRestart) { Restart(clearStateOnRestart); } else { Trace.Error($"The story {story.fileName} has already been ended, thus we can't jump to the knot!", this); } } JumpToKnot(knot); } else if (restart || automaticRestart) { Restart(clearStateOnRestart); } // Announce that we are loading the story var loadedEvent = new Story.LoadedEvent() { reader = this, story = this.story }; this.gameObject.Dispatch <Story.LoadedEvent>(loadedEvent); Scene.Dispatch <Story.LoadedEvent>(loadedEvent); // Invoke any subclass callbacks OnStoryLoaded(story); // Now start the story // If the story was previously loaded, we need not start from a new line this.StartStory(previouslyLoaded && story.started); }