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

Choice tags are gone after state reloading #1022

Closed
Shepard opened this issue Jul 29, 2023 · 1 comment · Fixed by #1023
Closed

Choice tags are gone after state reloading #1022

Shepard opened this issue Jul 29, 2023 · 1 comment · Fixed by #1023

Comments

@Shepard
Copy link
Contributor

Shepard commented Jul 29, 2023

Describe the bug

I have a story with tags on choices. I can find these on the choice objects initially. But when saving the state at a choice to JSON and then later reloading the story state from that JSON (in a fresh Story object), there are no tags on the choice objects anymore.

To Reproduce

import inkjs from "inkjs";

const storyContent = `
Hello, world!
* [Make a choice # just some tag]
- Great choice!
`;

let inkStory = new inkjs.Compiler(storyContent).Compile();
inkStory.ContinueMaximally();
let choices = inkStory.currentChoices;
if (choices.length) {
  console.log("Choice text before save:", choices[0].text);
  console.log("Choice tags before save:", choices[0].tags);
}
const stateJson = inkStory.state.ToJson();

inkStory = new inkjs.Compiler(storyContent).Compile();
inkStory.state.LoadJson(stateJson);
choices = inkStory.currentChoices;
if (choices.length) {
  console.log("Choice text after save:", choices[0].text);
  console.log("Choice tags after save:", choices[0].tags);
}

Output:

Choice text before save: Make a choice
Choice tags before save: [ 'just some tag' ]
Choice text after save: Make a choice
Choice tags after save: null

Expected behavior

The console.log statements before and after state reloading should provide the same output. However choices[0].tags is [ 'just some tag' ] before and null after.

Environment

  • OS: Windows
  • Node.js version: v16.19.0
  • inkjs version: 2.2.1
@Shepard
Copy link
Contributor Author

Shepard commented Jul 29, 2023

I extended my example a bit. If I continue the story from the reloaded state, then later choices don't have the same problem. It's only the choice at which I saved the state.

import inkjs from "inkjs";

const storyContent = `
Hello, world!
* [Make a choice # just some tag]
- Great choice!
* [Make another choice # another tag]
- Not bad!
`;

let inkStory = new inkjs.Compiler(storyContent).Compile();
inkStory.ContinueMaximally();
let choices = inkStory.currentChoices;
if (choices.length) {
  console.log("Choice text before save:", choices[0].text);
  console.log("Choice tags before save:", choices[0].tags);
}
const stateJson = inkStory.state.ToJson();

inkStory = new inkjs.Compiler(storyContent).Compile();
inkStory.state.LoadJson(stateJson);
choices = inkStory.currentChoices;
if (choices.length) {
  console.log("Choice text after save:", choices[0].text);
  console.log("Choice tags after save:", choices[0].tags);
}

inkStory.ChooseChoiceIndex(0);
inkStory.ContinueMaximally();
choices = inkStory.currentChoices;
if (choices.length) {
  console.log("Choice text after save:", choices[0].text);
  console.log("Choice tags after save:", choices[0].tags);
}

Output:

Choice text before save: Make a choice
Choice tags before save: [ 'just some tag' ]
Choice text after save: Make a choice
Choice tags after save: null
Choice text after save: Make another choice
Choice tags after save: [ 'another tag' ]

Shepard added a commit to Shepard/inkjs that referenced this issue Aug 5, 2023
Choice tags were missing in serialisation and deserialisation of state to/from JSON.

Fixes y-lohse#1022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant