Thread.from constructor
Implementation
Thread.from(Map<String, dynamic> jThreadObj, Story storyContext) {
callstack = <Element>[];
threadIndex = jThreadObj['threadIndex'];
List<dynamic> jThreadCallstack = jThreadObj['callstack'];
for (var jElTok in jThreadCallstack) {
Map<String, dynamic> jElementObj = jElTok;
var pushPopType = PushPopType.values[jElementObj['type']];
var pointer = Pointer.Null;
String? currentContainerPathStr;
dynamic currentContainerPathStrToken;
currentContainerPathStrToken = jElementObj['cPath'];
if (currentContainerPathStrToken != null) {
currentContainerPathStr = currentContainerPathStrToken.toString();
var threadPointerResult =
storyContext.contentAtPath(Path(currentContainerPathStr));
pointer = Pointer(
container: threadPointerResult.container,
index: jElementObj['idx'] ?? -1);
if (threadPointerResult.obj == null) {
throw Exception(
"When loading state, internal story location couldn't be found: $currentContainerPathStr . Has the story changed since this save data was created?");
} else if (threadPointerResult.approximate) {
storyContext.warning(
"When loading state, exact internal story location couldn't be found: '$currentContainerPathStr', so it was approximated to '" +
pointer.container!.path.toString() +
"' to recover. Has the story changed since this save data was created?");
}
}
bool inExpressionEvaluation = jElementObj['exp'];
var el = Element(pushPopType, pointer,
inExpressionEvaluation: inExpressionEvaluation);
if (jElementObj.containsKey('temp')) {
el.temporaryVariables =
JsonSerialization.JObjectToDictionaryRuntimeObjs(
jElementObj['temp']);
} else {
el.temporaryVariables.clear();
}
callstack.add(el);
}
if (jThreadObj.containsKey('previousContentObject')) {
var prevPath = Path(jThreadObj['previousContentObject']);
previousPointer = storyContext.pointerAtPath(prevPath);
}
}