scenarioworld / articy-js

Loads and allows for navigation of exported Articy JSON data (http://www.articy.com)
MIT License
8 stars 2 forks source link

Jumps not functioning correctly #165

Open Sp1d3rbite opened 1 year ago

Sp1d3rbite commented 1 year ago

Hi there,

I am still using your library with much pleasure! However I am unable to figure out how to get Jump nodes to work, and was hoping you could help.

Do you have any idea what the reason might be for the simple example below not to work? image

In short, what is supposed to happen is:

What happens in my build:

Even if I manually add "Jump" as a stopAtType, it won't detect it correctly and progress to the bottom row. And for completion sake, if I create a direct connection between Ruben and Kees, it obviously does work as intended, but I would like to use Jump nodes to keep my project a bit neater.

Is there anything obvious I am missing here?

Please let me know if you require further info regarding this problem.

Kind regards, Tony

brwarner commented 1 year ago

Hey there. That's very strange. I've used jump nodes many times with this library and they should work. Can you show me the code you're using to iterate?

Sp1d3rbite commented 1 year ago

Hi, thank you again for the swift response.

I have been investigating further because I also guessed that something as basic as a jump would work out of the box. Currently I have it narrowed down to something very strange, namely that it DOES work locally but not when build/packed.

For context, I am using the library in a React project with the build tool being Vite. For some strange reason in a build version, the jump is not detected and the node is marked as having a terminal branch.

Below is the line that is different when debugged. The value of node is filled in the local version, but undefined in the build one. let [nextState, node] = advanceGameFlowState(GameDB.db, currentConversation[currentConversation.length - 1], iterationConfig, 0);

I do not believe that this is necessarily related to your library, so I completely understand if you are not inclined to delve into debugging my issue.

Sp1d3rbite commented 1 year ago

Still trying to document my progression on the bug in the meantime.

I have since dumbed down my code a lot, trying to pinpoint exactly where is breaks. Unfortunately I am no closer to a conclusion yet...

Below is the most basic version of trying to run through the flow I could come up with.

const iterationConfig = {
    stopAtTypes: [
        "DialogueFragment"
    ]
};
let [initialState] = startupGameFlowState(GameDB.db, "0x0100000000001A7A", iterationConfig);

let index = 0;

let state = initialState;

console.log(index, GameDB.db.getObject(state.id, BaseFlowNode).properties.Text);

while (state.branches.length > 0) {
    let [newState] = advanceGameFlowState(GameDB.db, state, iterationConfig, 0);
    index++;

    console.log(index, GameDB.db.getObject(newState.id, BaseFlowNode).properties.Text);

    state = newState;
}

Still, in the debug version I am seeing:

And in the build version:

Sp1d3rbite commented 1 year ago

Hello again,

I am still breaking my head over this issue. I did manage to compress the breaking part even more, yet I'm still no closer to a solution.

const iterationConfig = {
    stopAtTypes: [ "DialogueFragment" ]
};

let [initialState] = startupGameFlowState(GameDB.db, "0x0100000000001A7A", iterationConfig);

const branches = refreshBranches(GameDB.db, initialState, iterationConfig)

console.log('branch count', branches.branches.length, branches);

This uses the exact same flow as in the screenshot. [DialogueFragment -> Jump -> DialogueFragment] In the dev environment I am seeing this being logged: image

Yet in the build/packed version I see: image

I have double checked that the database is loaded correctly, and they are identical to each other. This is also confirmed by checking if the connection is even found in the 'broken' database. Which it is, according to the image below: image

For some reason it fails to correctly find the branches in a build environment.

brwarner commented 1 year ago

The only thing I can think of as a reason it'd be different between build and dev is some kind of pruning by the build pipeline. I forget if you mentioned what toolset you were using to build. I always used webpack and never had any issues.

Are there any settings on your build pipeline where you can disable various optimizations? Might help narrow down what the cause is.

Sp1d3rbite commented 1 year ago

I have made a breakthrough today and managed to fix the issue, albeit in a way that doesn't really fix the underlying one.

It indeed has something to do with the way my bundler handles things.

The way I fixed it for now is by directly importing the articy-js functions into my scripts, like so:

import { Database } from "articy-js/dist/articy-js.cjs.production.min.js";

instead of

//import { Database } from "articy-js";

I know this is not the right way to do so, but it seems to evade the ESM compression or minifying my bundler does, by instead using the cjs code directly. My package (Vite) does have options regarding that, but now of them seemed to make it better.

To be completely fair, I have no clue if this has any negative effects that will bite me later, but for now the issue seems resolved. If you do though, please let me know.

brwarner commented 1 year ago

I'll keep the issue open in case anyone else has the same issue.... or maybe a better solution. Seems like it's clearly a bundler issue of some kind.

Glad you can move forward though!

Sp1d3rbite commented 1 year ago

Hi,

Thank you, and also thanks for the pointers you've given! Could you mark the post above as the answer for me, in case anyone stumbles upon the same issue?

brwarner commented 1 year ago

Can you mark something as an answer in an issue? Or is that just discussions? I don't see an option anywhere....

Sp1d3rbite commented 1 year ago

Oh you might be correct, I'm sorry. I didn't see an option either, so I thought that was only a thing the moderator could do.