]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Signal/event_signal.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Signal / event_signal.gd
1 @tool
2 class_name DialogicSignalEvent
3 extends DialogicEvent
4
5 ## Event that emits the Dialogic.signal_event signal with an argument.
6 ## You can connect to this signal like this: `Dialogic.signal_event.connect(myfunc)`
7
8
9 ### Settings
10
11 enum ArgumentTypes {STRING, DICTIONARY}
12 var argument_type := ArgumentTypes.STRING
13
14 ## The argument that will be provided with the signal.
15 var argument: Variant = ""
16
17 ################################################################################
18 ##                                              EXECUTE
19 ################################################################################
20
21 func _execute() -> void:
22         if argument_type == ArgumentTypes.DICTIONARY:
23                 var result: Variant = JSON.parse_string(argument)
24                 if result != null:
25                         var dict := result as Dictionary
26                         dict.make_read_only()
27                         dialogic.emit_signal('signal_event', dict)
28                 else:
29                         push_error("[Dialogic] Encountered invalid dictionary in signal event.")
30         else:
31                 dialogic.emit_signal('signal_event', argument)
32         finish()
33
34
35 ################################################################################
36 ##                                              INITIALIZE
37 ################################################################################
38
39 func _init() -> void:
40         event_name = "Signal"
41         set_default_color('Color6')
42         event_category = "Logic"
43         event_sorting_index = 8
44         help_page_path = "https://docs.dialogic.pro/dialogic-signals.html#1-signal-event"
45
46
47
48 ################################################################################
49 ##                                              SAVING/LOADING
50 ################################################################################
51
52 func get_shortcode() -> String:
53         return "signal"
54
55
56 func get_shortcode_parameters() -> Dictionary:
57         return {
58                 #param_name : property_info
59                 "arg_type"      : {"property": "argument_type", "default": ArgumentTypes.STRING,
60                                                                                 "suggestions": func(): return {"String":{'value':ArgumentTypes.STRING, 'text_alt':['string']}, "Dictionary":{'value':ArgumentTypes.DICTIONARY, 'text_alt':['dict', 'dictionary']}}},
61                 "arg"           : {"property": "argument", "default": ""}
62         }
63
64 ################################################################################
65 ##                                              EDITOR REPRESENTATION
66 ################################################################################
67
68 func build_event_editor() -> void:
69         add_header_label("Emit dialogic signal with argument")
70         add_header_label("(Dictionary in body)", 'argument_type == ArgumentTypes.DICTIONARY')
71         add_header_edit('argument', ValueType.SINGLELINE_TEXT, {}, 'argument_type == ArgumentTypes.STRING')
72         add_body_edit('argument_type',ValueType.FIXED_OPTIONS, {'left_text':'Argument Type:', 'options': [
73                         {
74                                 'label': 'String',
75                                 'value': ArgumentTypes.STRING,
76                         },
77                         {
78                                 'label': 'Dictionary',
79                                 'value': ArgumentTypes.DICTIONARY,
80                         }
81                 ]})
82         add_body_line_break('argument_type == ArgumentTypes.DICTIONARY')
83         add_body_edit('argument', ValueType.DICTIONARY, {'left_text': 'Dictionary'},'argument_type == ArgumentTypes.DICTIONARY')