nathanhoad / godot_dialogue_manager

A powerful nonlinear dialogue system for Godot
MIT License
2.22k stars 170 forks source link

Provide a way to know if any mutations would be run as a result of `get_next_dialogue_line` #684

Closed gatomesa closed 1 month ago

gatomesa commented 1 month ago

Is your feature request related to a problem? Please describe. In my game, I have a system where an indicator arrow appears above any interactable object. Each interactable object uses a DialogueResource in which I specify dialogue lines, mutations, etc. Often, there are conditions which must be met to be able to interact with the object. A very simple example:

~ start
if ItemController.is_in_inventory("GLASS"):
    do ItemController.remove_key_item_with_id("GLASS")
        do appear()
=> END

If a certain condition is met, then interacting with the object does something (in this case, mutations are run). If the condition is not met, then interacting with the object doesn't do anything (no dialogue, no mutations). However, right now, even if nothing would happen, the arrow would still show up in my game, because I have no way to check if any mutations would be run.

Describe the solution you'd like The simplest solution to my problem would be for the plugin to provide a way to check if any mutations would be run (without running them). I think that it could be exposed as a variable in the DialogueLine returned by get_next_dialogue_line. Maybe a mutations int, or an array of Strings with the mutation names. In my particular case, even a would_run_a_mutation bool would be sufficient. Note that, since the purpose of this is to check if the dialogue would do anything, the variables I suggested should work even if the MutationBehaviour is Skip (since we don't want to do anything, just check if we should show the indicator arrow or not).

Describe alternatives you've considered I could turn each object's interactivity on and off through signals and bools in my code, but things rarely are as simple as the example above. Many times I'm checking a LOT more variables to decide the flow of the conversation. I did try this, but it's become a major headache.

nathanhoad commented 1 month ago

What you're asking is pretty game implementation specific but it is kind of already possible by using DialogueManager.get_line:

var peeked_next_line: DialogueLine = await DialogueManager.get_line(dialogue_resource, "some_title", [])

This will grab the next line at the given title/key no matter what type it is. If it is a mutation then it will return it without executing it.