Skip to content

Commit

Permalink
Add reset_state method. This allows to restart the story without relo…
Browse files Browse the repository at this point in the history
…ading the json.
  • Loading branch information
bladecoder committed Aug 12, 2024
1 parent 154187e commit 122a2c2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/src/story/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@ impl Story {
pub fn load_state(&mut self, json_state: &str) -> Result<(), StoryError> {
self.get_state_mut().load_json(json_state)
}

/// Reset the Story back to its initial state as it was when it was first constructed.
pub fn reset_state(&mut self) -> Result<(), StoryError> {
self.if_async_we_cant("ResetState")?;

self.state = StoryState::new(
self.main_content_container.clone(),
self.list_definitions.clone(),
);

self.reset_globals()?;

Ok(())
}
}

0 comments on commit 122a2c2

Please sign in to comment.