From d5e515e4c108ae58471661e8874a38fb42a2534d Mon Sep 17 00:00:00 2001 From: Bram Dingelstad Date: Sat, 20 Nov 2021 12:20:33 +0100 Subject: [PATCH] got general dialogue to work --- Dialogue.gd | 30 +++++++++++++++++++++++++++++- Dialogue.tscn | 6 ++++++ addons/Wol/Wol.gd | 4 +++- addons/Wol/core/dialogue/line.gd | 7 ++++--- addons/Wol/core/program/line.gd | 26 +++++++++++++------------- addons/Wol/core/program/program.gd | 18 +++++------------- addons/Wol/core/virtual_machine.gd | 4 +++- dialogue.yarn | 8 ++++---- 8 files changed, 67 insertions(+), 36 deletions(-) diff --git a/Dialogue.gd b/Dialogue.gd index 464dc2a..a899791 100644 --- a/Dialogue.gd +++ b/Dialogue.gd @@ -3,5 +3,33 @@ extends Control func _ready(): pass +func continue_dialogue(): + if $Tween.is_active(): + $Tween.remove_all() + $RichTextLabel.percent_visible = 1.0 + return + + $Wol.resume() + func _on_Wol_line(line): - prints('got a line', line) + print(var2str(line)) + $RichTextLabel.text = line.text + + $Tween.remove_all() + $Tween.interpolate_property( + $RichTextLabel, + 'percent_visible', + .0, + 1.0, + .02 * line.text.length() + ) + + $Tween.start() + +func _on_Wol_options(options): + prints('got some options', options) + +func _input(event): + if event is InputEventKey and event.scancode == KEY_ENTER and event.pressed: + print('Pressed enter!') + continue_dialogue() diff --git a/Dialogue.tscn b/Dialogue.tscn index 8e93037..30b4cff 100644 --- a/Dialogue.tscn +++ b/Dialogue.tscn @@ -28,6 +28,9 @@ custom_fonts/normal_font = ExtResource( 1 ) text = "Here is where the dialogue will go. Run the scene in order to see how \"wol\" works." +__meta__ = { +"_edit_use_anchors_": false +} [node name="VBoxContainer" type="VBoxContainer" parent="."] anchor_right = 1.0 @@ -45,4 +48,7 @@ margin_bottom = 66.0 custom_fonts/font = ExtResource( 1 ) text = "This is a dialogue option" +[node name="Tween" type="Tween" parent="."] + [connection signal="line" from="Wol" to="." method="_on_Wol_line"] +[connection signal="options" from="Wol" to="." method="_on_Wol_options"] diff --git a/addons/Wol/Wol.gd b/addons/Wol/Wol.gd index 8a4da3c..78895f1 100644 --- a/addons/Wol/Wol.gd +++ b/addons/Wol/Wol.gd @@ -68,7 +68,9 @@ func set_path(_path): path = _path func _handle_line(line): - call_deferred('emit_signal', 'line', line) + var id = line.id + var string = program.wolStrings[id] + call_deferred('emit_signal', 'line', string) return WolGlobals.HandlerState.PauseExecution func _handle_command(command): diff --git a/addons/Wol/core/dialogue/line.gd b/addons/Wol/core/dialogue/line.gd index 133268e..b18b471 100644 --- a/addons/Wol/core/dialogue/line.gd +++ b/addons/Wol/core/dialogue/line.gd @@ -1,7 +1,8 @@ extends Object +# class_name DialogueLine -var id : String -var substitutions : Array = []#String +var id = '' +var substitutions = [] -func _init(id: String): +func _init(id): self.id = id diff --git a/addons/Wol/core/program/line.gd b/addons/Wol/core/program/line.gd index bbac596..7c5d86a 100644 --- a/addons/Wol/core/program/line.gd +++ b/addons/Wol/core/program/line.gd @@ -1,16 +1,16 @@ extends Object +class_name WolLine -var text : String -var nodeName : String -var lineNumber : int -var fileName : String -var implicit : bool -var meta : Array = [] - -func _init(text:String, nodeName:String, lineNumber:int, fileName:String, implicit:bool, meta:Array): - self.text = text - self.nodeName = nodeName - self.fileName = fileName - self.implicit = implicit - self.meta = meta +var text = '' +var nodeName = '' +var lineNumber = -1 +var fileName = '' +var implicit = false +var meta = [] +func _init(text, nodeName, lineNumber, fileName, implicit, meta): + self.text = text + self.nodeName = nodeName + self.fileName = fileName + self.implicit = implicit + self.meta = meta diff --git a/addons/Wol/core/program/program.gd b/addons/Wol/core/program/program.gd index 16a8a95..fbb4ecd 100644 --- a/addons/Wol/core/program/program.gd +++ b/addons/Wol/core/program/program.gd @@ -1,19 +1,12 @@ extends Node -var programName : String -var wolStrings : Dictionary = {} -var wolNodes : Dictionary = {} +var programName = '' +var wolStrings = {} +var wolNodes = {} -func get_node_tags(name:String)->Array: +func get_node_tags(name): return wolNodes[name].tags -func get_wol_string(key:String)->String: - return wolStrings[key] - -func get_node_text(name:String)->String: - var key = wolNodes[name].sourceId - return get_wol_string(key) - #possible support for line tags func get_untagged_strings()->Dictionary: return {} @@ -25,6 +18,5 @@ func include(other): pass func dump(library): - print("not yet implemented") pass - + diff --git a/addons/Wol/core/virtual_machine.gd b/addons/Wol/core/virtual_machine.gd index e9e8880..9b9ac83 100644 --- a/addons/Wol/core/virtual_machine.gd +++ b/addons/Wol/core/virtual_machine.gd @@ -265,6 +265,7 @@ func run_instruction(instruction)->bool: var name : String = instruction.operands[0].value var loaded = _dialogue._variableStorage.get_value(name) _state.push_value(loaded) + WolGlobals.ByteCode.StoreVariable: #store top stack value to variable var top = _state.peek_value() @@ -298,13 +299,14 @@ func run_instruction(instruction)->bool: # add an option to current state var key = instruction.operands[0].value - var line = Line.new(key, _program.wolStrings[key]) + var line = Line.new(key) if instruction.operands.size() > 2: pass #formated text options # line to show and node name _state.currentOptions.append(SimpleEntry.new(line,instruction.operands[1].value)) + WolGlobals.ByteCode.ShowOptions: #show options - stop if none if _state.currentOptions.size() == 0: diff --git a/dialogue.yarn b/dialogue.yarn index 64241d5..9c1cb41 100644 --- a/dialogue.yarn +++ b/dialogue.yarn @@ -6,7 +6,7 @@ position: -1892,-1013 <> <> -Masami: Gina, this way! +Masami: Gina, this way! #line:5d7a7c Gina: Patience! I’m coming. >Still, she didn’t pick up her pace and kept hesitantly looking around.< Masami: Everything should be fine, let’s just go. We won. @@ -14,7 +14,7 @@ Masami: Unless you are planning on backstabbing me at the finish line, that is. Gina: How funny. You are not that special. Masami: Har har. Now start walking or I’ll carry you out the front door. Masami: I don’t want to give Monokuma the time to come up with a new death game for two while we are trying to get through the exit. -Gina: … +Gina: ... <> @@ -29,8 +29,8 @@ Masami: The reception desk? <> -Masami: A paper and… -Masami: … That’s a gun. +Masami: A paper and... +Masami: ... That’s a gun. Gina: A revolver, in fact. Such an old fashioned choice of firearm. Though, I appreciate the aesthetic. How pretty. Masami: I don’t like this. Why is it here? >I took the paper from the table and briskly unfolded it.<