Created
January 11, 2018 22:44
-
-
Save mstevenson/52334cbda4baf0db242345c018621905 to your computer and use it in GitHub Desktop.
An idea for how to save and restore the state of an InklewriterSharp game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
break; | |
} | |
} | |
// 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. | |
player.CreateFirstChunkWithFlags(flags); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment