flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.27k stars 910 forks source link

improvement(flame_jenny): Allow DialogueRunner to be cancelled #2657

Open projectitis opened 1 year ago

projectitis commented 1 year ago

What could be improved

A method to cleanly cancel an in-progress DialogueRunner. e.g. DialogRunner.cancelDialogue.

The cancelDialogue method should still trigger the proper DialogueView methods. For example onNodeComplete and onDialogueComplete - or - a new method could be introduced to DialogueView called onDialogueCancel. Cancelling should also still complete the future returned by startDialogue.

Thoughts on approach?

Why should this be improved

Suddenly cancelling a dialogue outside of normal flow might be necessary, for example, if the user exits to menu. It could also happen if there are NPC dialogues happening that need to be cancelled when the player leaves the scene. There are many other cases, too.

It doesn't seem possible to do this currently, unless I just haven't found it yet? According to the comments, the method called jumpToNode apparently would do this if called with a null node. However, this is an internal method and not accessible outside of the runner.

Any risks?

Since this would be a new method, the risks are lower. The risks are that the user would need to account for an abrupt cancel in the code and could not rely on the standard dialog flow always completing. For example, there could be a risk that onLineStart is immediately followed with onDialogueCancel, and the developer would need to account for it.

More information

I would be interested in contributing this improvement, but I would like guidance from the original developer(s) on the best way to approach this.

spydon commented 1 year ago

The original developer is @st-pasha and we haven't heard from him in a few months so I'm not sure you'll be able to get guidance from the original dev.

projectitis commented 1 year ago

No worries. I'll work on it anyway šŸ˜

projectitis commented 1 year ago

By the way, I've looked into this. Some notes:

Cancelling the dialog while a line is showing looks reasonably trivial. There is already a mechanism that allows this via the yarn script (a stop command). Using the same principle for an external stop should be ok.

However, cancelling the dialog while a choice is being prevented is less easy. The 'choice' methods would have to be rewritten to be similar to the 'line' methods - these use a 'pipeline' class that keeps track of the various futures and allows them to be managed easily.

I'm still thinking about best approach, and will likely get to this when I implement quit in my game menu šŸ˜›