Skip to content

Plugin for Godot

mifth edited this page Jan 28, 2024 · 14 revisions

Plugin for Godot

It's possible to use the Dialogue Creator as a plugin for your own games. Just follow instructions below to succeed.

Installation

  • Create a Godot 4.2+ project.
  • Copy dialoguecreatorgame folder to your "MyProject/addons" folder.
  • Enable the dialoguecreatorgame plugin in Project->ProjectSettings->Plugins.

image

Create Dialogue

Open the Dialogue Creator application and create such a setup and save to DialogueTest.json:
image

Or you can just save this text to DialogueTest.json file.

Run Dialogue in Your Godot Project

Create a scene and add such this DialogueTest.gd:

Then run the scene and as a result you will get such a log:

Start Node: StartNode
Start Name: Start Quest
Inputs: []
Outputs: [{ "Type": 0 }]
 
NEXT NODE: DCDialogueNode
CharacterID: 0
Main Text: 
Hi there! Are you looking for a job?
Text SLots: 
Yes, what can you propose?
Nevermind
Inputs: [{ "Type": 0 }, { "Type": 1 }, { "Type": 1 }, { "Type": 1 }]
Outputs: [{ "Type": 0 }, { "Type": 0 }, { "Type": 0 }]
 
NEXT NODE: DCActionNode
ActionName: MyAction
ActionText: 
{
"HasLevel": 8
}
Ports Names: 
Choice 1
Choice 2
Choice 3

SUCCESS!!!!!

Important Variables

The main script variables are dc_data(DCGDialogueData) and live_nodes_js.

dc_data

dc_data is DCGDialogueData class which parses a json file and stores data_js and nodes_by_name dictionaries.

data_js is parsed data from a json file. nodes_by_name is a dictionary of DCGDialogueData.NodeData objects which contain some information mainly for running dialogue nodes.

data_js and nodes_by_name should not be modified during running dialogues but you can always get any data from it.

live_nodes_js

live_nodes_js is a dictionary which contains copies of nodes from the data_js. These nodes can be modified during running dialogues (changed and replaced text slots, enable/disable texts, hide/unhide text slots).

live_nodes_js can contain new data for texts: ["TextSlots"][0]["LiveText"]. The "LiveText" is a modified text during running dialogues. To get current text in DialogueNode or ActionNode please always use this functions:

# For DialogueNode and ActionNode only!
if node_data.node_class_key in DCGUtils.live_nodes:
    var live_node_js = self.dc_data.get_live_node_js(node_data, self.live_nodes_js)

    var text_str
    if node_data.node_class_key == DCGUtils.DialogueNode
        text_str = self.dc_data.get_text_of_text_slot(live_node_js["TextSlots"][0])

        # Get Text By Language
        var text_slot_text = self.dc_data.get_text_by_lang(text_str, "Eng")

    elif node_data.node_class_key == DCGUtils.ActionNode:
        text_str = self.dc_data.get_text_of_text_slot(live_node_js["ActionText"])

Other Examples

There is also a nice example how dialogues running is done in the DialogueCreator application. Please, check out the DCPlayScene.gd file to get more information about the Godot plugin.