I would need to think about & test things before I could recommend a better method for simulating a “previous play-through” that could be used for debugging purposes, but some of the things I would likely consider are:
1: The Config.passages.start
setting.
This setting can be used in StoryInit
to control which Passage will be displayed when the runtime engine finishes its startup process.
<<set Config.passages.start to "Remembrance">>
There are a number of reasons why using that setting is better than calling <<goto>>
in StoryInit
, one of them being that the runtime engine still has things it needs to do after StoryInit
has been processed before setup is finished, so the Engine.play()
method the macro calls may be triggered too early. Using the setting allows the startup process to finish normally, just with a different Passage being shown.
2: Using the application’s “Test from Here” option and the Config.debug
flag.
The “Test from Here” option can be used to temporary control which Passage is first shown. It basically affects what Passage Name is assigned to the Config.passages.start
setting during the normal startup process, it also sets the Config.debug
flag to true. That “default” Passage Name can be overwritten if needed using the technique from point 1.
3: Using specifically tagged Passages to control which “Test Case” is run.
Currently you are storing specific “previous playthrough” related code in both Story JavaScript
and StoryInit
. Which makes both those areas more messy, and potentially means you need to comment out or remove that specific content before creating a release.
I think a better option would be to store all the code needed to setup a specific “playthrough” in a normal Passage, and then assign that Passage a specific Passage Tag (like debug
?) when you want to test that specific “playthrough”.
eg. Create a Passage named “Testing Remembrance” with content like…
/* Code for padding history with the required Moments */
...
/* Code for assigning alternative defaults to Story Variables */
<<set $cupsOfCoffeeDrank to 2>>
<<set $instantCoffeePackets to 0>>
/* Change which Passage is shown first, if not using "Test From Here" */
<<set Config.passages.start to "Remembrance">>
Code like the following can be added the end of your standard StoryInit
to look for, and process the content of, any Passage with a specific Passage Tag…
/* Run Test Case if one is found */
<<script>>
let testcase = Story.find( (p) => p.tags.includes("debug") );
if (testcase) {
jQuery.wikiPassage(testcase.name);
}
<</script>>
And then anytime you want to test a specific test case Passage you just need to temporary add the debug
Passage Tag to it.
note: I suggest you review the documentation of any of the above used methods you’re not aware of. The JavaScript could be placed a method definition like so…
setup.runTestCase = function () {
let testcase = Story.find( (p) => p.tags.includes("debug") );
if (testcase) {
jQuery.wikiPassage(testcase.name);
}
};
…and then replace the previous <<script>>
macro call with the following <<run>>
macro call..
/* Run Test Case if one is found */
<<run setup.runTestCase()>>
This way your testing code is isolated from your normal Story JavaScript
and StoryInit code.