Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An idea for how to save and restore the state of an InklewriterSharp game.
// Load story file
string storyJson = File.ReadAllText ("Stories/musgraveritual.json");
StoryModel model = StoryModel.Create (storyJson);
// Find the saved stitch and fast forward the story's initial stitch:
string restoredStitchName = "holmesResumedHis"; // load this from disk
foreach (var stitch in model.Story.Stitches) {
if (stitch.Name == restoredStitchName) {
// Fast forward the story to this stitch
model.Story.InitialStitch = stitch;
// Load story into player
StoryPlayer player = new StoryPlayer (model, new Inklewriter.MarkupConverters.ConsoleMarkupConverter ());
// Collect all saved flag strings
List<string> restoredFlagStrings = new List<string> { "a:1", "b:2", "c:3" }; // load this from disk
List<FlagValue> flags = new List<FlagValue>();
foreach (var flag in restoredFlagStrings)
// TODO Convert flag strings into FlagValue objects. There's not a clean API for this,
// but some code from StoryModel.ProcessFlagSettings could be recycled.
// Create our first Chunk using the InitialStitch that we previously set,
// and restore all of its saved flags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment