Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore choice tags on state reloading #1023

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/engine/JsonSerialisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ export class JsonSerialisation {
choice.sourcePath = jObj["originalChoicePath"].toString();
choice.originalThreadIndex = parseInt(jObj["originalThreadIndex"]);
choice.pathStringOnChoice = jObj["targetPath"].toString();
if (jObj["tags"]) {
choice.tags = jObj["tags"];
}
return choice;
}

Expand All @@ -590,6 +593,17 @@ export class JsonSerialisation {
writer.WriteProperty("originalChoicePath", choice.sourcePath);
writer.WriteIntProperty("originalThreadIndex", choice.originalThreadIndex);
writer.WriteProperty("targetPath", choice.pathStringOnChoice);
if (choice.tags) {
writer.WriteProperty("tags", (w) => {
w.WriteArrayStart();
for (const tag of choice.tags!) {
w.WriteStringStart();
w.WriteStringInner(tag);
w.WriteStringEnd();
}
w.WriteArrayEnd();
});
}
writer.WriteObjectEnd();
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/inkfiles/compiled/inkjs/tests.ink.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/tests/inkfiles/original/inkjs/tests.ink
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ a bit of content
the next bit
-> DONE
= choicepoint
* choice 1
* choice 1 # a tag
* choice 2
- -> DONE

Expand Down
16 changes: 16 additions & 0 deletions src/tests/specs/inkjs/engine/Integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ describe("Integration", () => {
expect(context.story.currentChoices[0].text).toEqual("choice 1");
expect(context.story.currentChoices[1].text).toEqual("choice 2");
});

it("should restore choice tags", () => {
context.story.ChoosePathString("saveload.choicepoint");
context.story.Continue();
expect(context.story.currentChoices.length).toEqual(2);
expect(context.story.currentChoices[0].tags.length).toEqual(1);
expect(context.story.currentChoices[0].tags[0]).toEqual("a tag");
console.log(context.story.currentChoices[0].tags);

const save = context.story.state.ToJson();
context.story.state.LoadJson(save);

expect(context.story.currentChoices.length).toEqual(2);
expect(context.story.currentChoices[0].tags.length).toEqual(1);
expect(context.story.currentChoices[0].tags[0]).toEqual("a tag");
});
});

describe("debug tools", () => {
Expand Down