diff --git a/ink-engine-runtime/Story.cs b/ink-engine-runtime/Story.cs index 65145ab3..8574c79f 100644 --- a/ink-engine-runtime/Story.cs +++ b/ink-engine-runtime/Story.cs @@ -45,7 +45,7 @@ public List currentChoices public List currentErrors { get { return state.currentErrors; } } public bool hasError { get { return state.hasError; } } public VariablesState variablesState{ get { return state.variablesState; } } - internal StoryState state { get { return _state; } } + public StoryState state { get { return _state; } } // Warning: When creating a Story using this constructor, you need to // call ResetState on it before use. Intended for compiler use only. diff --git a/ink-engine-runtime/StoryState.cs b/ink-engine-runtime/StoryState.cs index 65217ad3..9dcc470b 100644 --- a/ink-engine-runtime/StoryState.cs +++ b/ink-engine-runtime/StoryState.cs @@ -7,31 +7,70 @@ namespace Ink.Runtime { - internal class StoryState + public class StoryState { - const int kInkSaveStateVersion = 1; + public const int kInkSaveStateVersion = 1; const int kMinCompatibleLoadVersion = 1; + /// + /// Exports the current state to json format, in order to save the game. + /// + /// The save state in json format. + /// Whether to 'pretty print' using whitespace. + public string ToJson(bool indented=false) { + return jsonToken.ToString (indented ? Formatting.Indented : Formatting.None); + } + + /// + /// Loads a previously saved state in JSON format. + /// + /// The JSON string to load. + public void LoadJson(string json) + { + jsonToken = JToken.Parse (json); + } + + /// + /// Gets the visit/read count of a particular Container at the given path. + /// For a knot or stitch, that path string will be in the form: + /// + /// knot + /// knot.stitch + /// + /// + /// The number of times the specific knot or stitch has + /// been enountered by the ink engine. + /// The dot-separated path string of + /// the specific knot or stitch. + internal int VisitCountAtPathString(string pathString) + { + int visitCountOut; + if (visitCounts.TryGetValue (pathString, out visitCountOut)) + return visitCountOut; + + return -1; + } + // REMEMBER! REMEMBER! REMEMBER! // When adding state, update the Copy method, and serialisation. // REMEMBER! REMEMBER! REMEMBER! - public List outputStream { get { return _outputStream; } } - public List currentChoices { get; private set; } - public List currentErrors { get; private set; } - public VariablesState variablesState { get; private set; } - public CallStack callStack { get; private set; } - public List evaluationStack { get; private set; } - public Runtime.Object divertedTargetObject { get; set; } - public Dictionary visitCounts { get; private set; } - public Dictionary turnIndices { get; private set; } - public int currentTurnIndex { get; private set; } - public int storySeed { get; private set; } - public bool didSafeExit { get; set; } - - public Story story { get; set; } - - public Path currentPath { + internal List outputStream { get { return _outputStream; } } + internal List currentChoices { get; private set; } + internal List currentErrors { get; private set; } + internal VariablesState variablesState { get; private set; } + internal CallStack callStack { get; private set; } + internal List evaluationStack { get; private set; } + internal Runtime.Object divertedTargetObject { get; set; } + internal Dictionary visitCounts { get; private set; } + internal Dictionary turnIndices { get; private set; } + internal int currentTurnIndex { get; private set; } + internal int storySeed { get; private set; } + internal bool didSafeExit { get; set; } + + internal Story story { get; set; } + + internal Path currentPath { get { if (currentContentObject == null) return null; @@ -46,7 +85,7 @@ public Path currentPath { } } - public Runtime.Object currentContentObject { + internal Runtime.Object currentContentObject { get { return callStack.currentElement.currentObject; @@ -56,20 +95,20 @@ public Runtime.Object currentContentObject { } } - public Container currentContainer { + internal Container currentContainer { get { return callStack.currentElement.currentContainer; } } - public bool hasError + internal bool hasError { get { return currentErrors != null && currentErrors.Count > 0; } } - public string currentText + internal string currentText { get { @@ -86,7 +125,7 @@ public string currentText } } - public bool inExpressionEvaluation { + internal bool inExpressionEvaluation { get { return callStack.currentElement.inExpressionEvaluation; } @@ -94,10 +133,8 @@ public bool inExpressionEvaluation { callStack.currentElement.inExpressionEvaluation = value; } } - - - - public StoryState (Story story) + + internal StoryState (Story story) { this.story = story; @@ -132,7 +169,7 @@ internal void GoToStart() // Runtime.Objects are treated as immutable after they've been set up. // (e.g. we don't edit a Runtime.Text after it's been created an added.) // I wonder if there's a sensible way to enforce that..?? - public StoryState Copy() + internal StoryState Copy() { var copy = new StoryState(story); @@ -246,39 +283,20 @@ internal JToken jsonToken } } } - - /// - /// Exports the current state to json format, in order to save the game. - /// - /// The save state in json format. - /// Whether to 'pretty print' using whitespace. - public string ToJson(bool indented=false) { - return jsonToken.ToString (indented ? Formatting.Indented : Formatting.None); - } - - /// - /// Loads a previously saved state in JSON format. - /// - /// The JSON string to load. - public void LoadJson(string json) - { - jsonToken = JToken.Parse (json); - } - - - public void ResetErrors() + + internal void ResetErrors() { currentErrors = null; } - public void ResetOutput() + internal void ResetOutput() { _outputStream.Clear (); } // Push to output stream, but split out newlines in text for consistency // in dealing with them later. - public void PushToOutputStream(Runtime.Object obj) + internal void PushToOutputStream(Runtime.Object obj) { var text = obj as Text; if (text) { @@ -294,26 +312,6 @@ public void PushToOutputStream(Runtime.Object obj) PushToOutputStreamIndividual (obj); } - /// - /// Gets the visit/read count of a particular Container at the given path. - /// For a knot or stitch, that path string will be in the form: - /// - /// knot - /// knot.stitch - /// - /// - /// The number of times the specific knot or stitch has - /// been enountered by the ink engine. - /// The dot-separated path string of - /// the specific knot or stitch. - public int VisitCountAtPathString(string pathString) - { - int visitCountOut; - if (visitCounts.TryGetValue (pathString, out visitCountOut)) - return visitCountOut; - - return -1; - } // At both the start and the end of the string, split out the new lines like so: // @@ -546,7 +544,7 @@ int currentGlueIndex { } } - public bool outputStreamEndsInNewline { + internal bool outputStreamEndsInNewline { get { if (_outputStream.Count > 0) { @@ -568,7 +566,7 @@ public bool outputStreamEndsInNewline { } } - public bool outputStreamContainsContent { + internal bool outputStreamContainsContent { get { foreach (var content in _outputStream) { if (content is Text) @@ -578,7 +576,7 @@ public bool outputStreamContainsContent { } } - public bool inStringEvaluation { + internal bool inStringEvaluation { get { for (int i = _outputStream.Count - 1; i >= 0; i--) { var cmd = _outputStream [i] as ControlCommand; @@ -591,24 +589,24 @@ public bool inStringEvaluation { } } - public void PushEvaluationStack(Runtime.Object obj) + internal void PushEvaluationStack(Runtime.Object obj) { evaluationStack.Add(obj); } - public Runtime.Object PopEvaluationStack() + internal Runtime.Object PopEvaluationStack() { var obj = evaluationStack [evaluationStack.Count - 1]; evaluationStack.RemoveAt (evaluationStack.Count - 1); return obj; } - public Runtime.Object PeekEvaluationStack() + internal Runtime.Object PeekEvaluationStack() { return evaluationStack [evaluationStack.Count - 1]; } - public List PopEvaluationStack(int numberOfObjects) + internal List PopEvaluationStack(int numberOfObjects) { if(numberOfObjects > evaluationStack.Count) { throw new System.Exception ("trying to pop too many objects"); @@ -620,7 +618,7 @@ public Runtime.Object PeekEvaluationStack() } - public void ForceEndFlow() + internal void ForceEndFlow() { currentContentObject = null; @@ -646,7 +644,7 @@ internal void SetChosenPath(Path path) currentTurnIndex++; } - public void AddError(string message) + internal void AddError(string message) { // TODO: Could just add to output? if (currentErrors == null) {