@@ -5,12 +5,13 @@ var YarnScript = preload("yarn_script.gd") | |||||
export (Resource) var yarnScript | export (Resource) var yarnScript | ||||
var say_func : FuncRef = null | var say_func : FuncRef = null | ||||
var choices_func : FuncRef = null | |||||
func run_all(): | func run_all(): | ||||
var next_node = yarnScript.nodes["Start"] | var next_node = yarnScript.nodes["Start"] | ||||
while next_node != null: | while next_node != null: | ||||
print("-> Jump to " + next_node["title"]) | print("-> Jump to " + next_node["title"]) | ||||
var next_node_key = run_body(next_node["body"]) | |||||
var next_node_key = yield(run_body(next_node["body"]), "completed") | |||||
if (yarnScript.nodes.has(next_node_key)): | if (yarnScript.nodes.has(next_node_key)): | ||||
next_node = yarnScript.nodes[next_node_key] | next_node = yarnScript.nodes[next_node_key] | ||||
else: | else: | ||||
@@ -21,25 +22,26 @@ func run_body(body): | |||||
if element["type"] == "jump": | if element["type"] == "jump": | ||||
return element["node"] | return element["node"] | ||||
elif element["type"] == "choice_blocks": | elif element["type"] == "choice_blocks": | ||||
var block = decide_choice_block(element["blocks"]) | |||||
var block = yield(decide_choice_block(element["blocks"]), "completed") | |||||
print(block) | |||||
return block["node"] # todo change later with "-> choices" | return block["node"] # todo change later with "-> choices" | ||||
elif element["type"] == "condition_blocks": | elif element["type"] == "condition_blocks": | ||||
var block = decide_condition_block(element["blocks"]) | var block = decide_condition_block(element["blocks"]) | ||||
var next_node_key = run_body(block["body"]) | |||||
var next_node_key = yield(run_body(block["body"]), "completed") | |||||
if next_node_key != "": | if next_node_key != "": | ||||
return next_node_key | return next_node_key | ||||
else: | else: | ||||
if say_func == null or !say_func.is_valid(): | if say_func == null or !say_func.is_valid(): | ||||
print(element) | print(element) | ||||
else: | else: | ||||
say_func.call_func(element) | |||||
yield(say_func.call_func(element), "completed") | |||||
return "" | return "" | ||||
export var choice = 0 | |||||
func decide_choice_block(blocks): | func decide_choice_block(blocks): | ||||
return blocks[choice] | |||||
if choices_func == null or !choices_func.is_valid(): | |||||
return blocks[0] | |||||
else: | |||||
return yield(choices_func.call_func(blocks), "completed") | |||||
func decide_condition_block(blocks): | func decide_condition_block(blocks): | ||||
for block in blocks: | for block in blocks: | ||||
@@ -220,11 +220,6 @@ func get_preset_name(preset): | |||||
func get_import_options(preset): | func get_import_options(preset): | ||||
match preset: | match preset: | ||||
Presets.DEFAULT: | |||||
return [{ | |||||
"name": "use_red_anyway", | |||||
"default_value": false | |||||
}] | |||||
_: | _: | ||||
return [] | return [] | ||||
@@ -0,0 +1,13 @@ | |||||
[gd_scene load_steps=2 format=2] | |||||
[ext_resource path="res://main/scripts/ChoicesBox.gd" type="Script" id=1] | |||||
[node name="ChoicesBox" type="VBoxContainer"] | |||||
anchor_left = 0.3 | |||||
anchor_top = 0.1 | |||||
anchor_right = 0.7 | |||||
anchor_bottom = 0.45 | |||||
script = ExtResource( 1 ) | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} |
@@ -0,0 +1,34 @@ | |||||
[gd_scene load_steps=2 format=2] | |||||
[ext_resource path="res://main/scripts/LogPanel.gd" type="Script" id=1] | |||||
[node name="LogPanel" type="Control"] | |||||
anchor_right = 1.0 | |||||
anchor_bottom = 1.0 | |||||
script = ExtResource( 1 ) | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} | |||||
[node name="Panel" type="Panel" parent="."] | |||||
anchor_right = 1.0 | |||||
anchor_bottom = 1.0 | |||||
[node name="RichTextLabel" type="RichTextLabel" parent="."] | |||||
anchor_left = 0.02 | |||||
anchor_top = 0.05 | |||||
anchor_right = 0.98 | |||||
anchor_bottom = 0.95 | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} | |||||
[node name="TextButton" type="Button" parent="."] | |||||
modulate = Color( 1, 1, 1, 0.235294 ) | |||||
anchor_right = 1.0 | |||||
anchor_bottom = 1.0 | |||||
margin_right = -49.0 | |||||
flat = true | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} |
@@ -1,8 +1,10 @@ | |||||
[gd_scene load_steps=4 format=2] | |||||
[gd_scene load_steps=6 format=2] | |||||
[ext_resource path="res://main/scripts/test_viteuf.gd" type="Script" id=1] | [ext_resource path="res://main/scripts/test_viteuf.gd" type="Script" id=1] | ||||
[ext_resource path="res://main/dialogues/test.yarn" type="Resource" id=2] | [ext_resource path="res://main/dialogues/test.yarn" type="Resource" id=2] | ||||
[ext_resource path="res://addons/yarn_spinner/yarn_runner.gd" type="Script" id=3] | [ext_resource path="res://addons/yarn_spinner/yarn_runner.gd" type="Script" id=3] | ||||
[ext_resource path="res://main/scenes/LogPanel.tscn" type="PackedScene" id=4] | |||||
[ext_resource path="res://main/scenes/ChoicesBox.tscn" type="PackedScene" id=5] | |||||
[node name="Node" type="Control"] | [node name="Node" type="Control"] | ||||
anchor_right = 1.0 | anchor_right = 1.0 | ||||
@@ -16,6 +18,10 @@ __meta__ = { | |||||
script = ExtResource( 3 ) | script = ExtResource( 3 ) | ||||
yarnScript = ExtResource( 2 ) | yarnScript = ExtResource( 2 ) | ||||
[node name="RichTextLabel" type="RichTextLabel" parent="."] | |||||
anchor_right = 1.0 | |||||
[node name="LogPanel" parent="." instance=ExtResource( 4 )] | |||||
anchor_bottom = 0.6 | |||||
[node name="ChoicesBox" parent="." instance=ExtResource( 5 )] | |||||
anchor_top = 0.6 | |||||
anchor_bottom = 1.0 | anchor_bottom = 1.0 | ||||
alignment = 1 |
@@ -11,7 +11,7 @@ func on_choices(choices_list): | |||||
for choice in choices_list: | for choice in choices_list: | ||||
var choiceButton := Button.new() | var choiceButton := Button.new() | ||||
choiceButton.text = choice["text"] | choiceButton.text = choice["text"] | ||||
choiceButton.connect("pressed", self, "on_choice_made", [choice["marker"]]) | |||||
choiceButton.connect("pressed", self, "on_choice_made", [choice]) | |||||
add_child(choiceButton) | add_child(choiceButton) | ||||
var res = yield(self, "choice_made") | var res = yield(self, "choice_made") | ||||
hide() | hide() |
@@ -1,24 +1,28 @@ | |||||
extends Control | extends Control | ||||
func _ready(): | func _ready(): | ||||
$YarnRunner.say_func = funcref(self, "say") | |||||
$YarnRunner.run_all() | |||||
# $ChoicesBox.hide() | |||||
# $LogPanel.hide() | |||||
on_dialogue_start() | |||||
$YarnRunner.say_func = funcref(self, "on_new_line") | |||||
$YarnRunner.choices_func = funcref(self, "on_choices") | |||||
yield($YarnRunner.run_all(), "completed") | |||||
on_dialogue_end() | |||||
func say(element): | |||||
$RichTextLabel.text += str(element["raw"]) + "\n" | |||||
func on_dialogue_start(): | |||||
$LogPanel.show() | |||||
$ChoicesBox.show() | |||||
$LogPanel.clear() | |||||
$ChoicesBox.clear() | |||||
func exec(stri): | |||||
var expr := Expression.new() | |||||
print("input : " + stri) | |||||
var err := expr.parse(stri) | |||||
if err == OK: | |||||
var res = expr.execute() | |||||
print("res : " + str(res)) | |||||
else: | |||||
print("err : " + str(err)) | |||||
func jajoujaj(): | |||||
print("jaaaja") | |||||
func on_new_line(line): | |||||
yield($LogPanel.on_new_line(line["text"]), "completed") | |||||
var current_node = "Start" | |||||
var current_line = 0 | |||||
func on_choices(choices_list): | |||||
print(choices_list) | |||||
return yield($ChoicesBox.on_choices(choices_list), "completed") | |||||
func on_dialogue_end(): | |||||
pass | |||||
# $ChoicesBox.hide() | |||||
# $LogPanel.hide() |
@@ -12,12 +12,12 @@ _global_script_classes=[ { | |||||
"base": "VBoxContainer", | "base": "VBoxContainer", | ||||
"class": "ChoicesBox", | "class": "ChoicesBox", | ||||
"language": "GDScript", | "language": "GDScript", | ||||
"path": "res://yarn/scripts/ChoicesBox.gd" | |||||
"path": "res://main/scripts/ChoicesBox.gd" | |||||
}, { | }, { | ||||
"base": "Control", | "base": "Control", | ||||
"class": "LogPanel", | "class": "LogPanel", | ||||
"language": "GDScript", | "language": "GDScript", | ||||
"path": "res://yarn/scripts/LogPanel.gd" | |||||
"path": "res://main/scripts/LogPanel.gd" | |||||
}, { | }, { | ||||
"base": "Node", | "base": "Node", | ||||
"class": "YarnImporter", | "class": "YarnImporter", | ||||
@@ -1,7 +1,7 @@ | |||||
[gd_scene load_steps=4 format=2] | [gd_scene load_steps=4 format=2] | ||||
[ext_resource path="res://yarn/scripts/LogPanel.gd" type="Script" id=1] | |||||
[ext_resource path="res://yarn/scripts/ChoicesBox.gd" type="Script" id=2] | |||||
[ext_resource path="res://main/scenes/ChoicesBox.tscn" type="PackedScene" id=1] | |||||
[ext_resource path="res://main/scenes/LogPanel.tscn" type="PackedScene" id=2] | |||||
[ext_resource path="res://yarn/scripts/YarnSpinner.gd" type="Script" id=3] | [ext_resource path="res://yarn/scripts/YarnSpinner.gd" type="Script" id=3] | ||||
[node name="YarnSpinner" type="Control"] | [node name="YarnSpinner" type="Control"] | ||||
@@ -12,45 +12,6 @@ __meta__ = { | |||||
"_edit_use_anchors_": false | "_edit_use_anchors_": false | ||||
} | } | ||||
[node name="ChoicesBox" type="VBoxContainer" parent="."] | |||||
anchor_left = 0.3 | |||||
anchor_top = 0.1 | |||||
anchor_right = 0.7 | |||||
anchor_bottom = 0.45 | |||||
script = ExtResource( 2 ) | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} | |||||
[node name="ChoicesBox" parent="." instance=ExtResource( 1 )] | |||||
[node name="LogPanel" type="Control" parent="."] | |||||
anchor_top = 0.5 | |||||
anchor_right = 1.0 | |||||
anchor_bottom = 1.0 | |||||
script = ExtResource( 1 ) | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} | |||||
[node name="Panel" type="Panel" parent="LogPanel"] | |||||
anchor_right = 1.0 | |||||
anchor_bottom = 1.0 | |||||
[node name="RichTextLabel" type="RichTextLabel" parent="LogPanel"] | |||||
anchor_left = 0.02 | |||||
anchor_top = 0.05 | |||||
anchor_right = 0.98 | |||||
anchor_bottom = 0.95 | |||||
text = "Coucou je suis un text de test, ou bien l'inverse" | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} | |||||
[node name="TextButton" type="Button" parent="LogPanel"] | |||||
modulate = Color( 1, 1, 1, 0.235294 ) | |||||
anchor_right = 1.0 | |||||
anchor_bottom = 1.0 | |||||
margin_right = -20.0 | |||||
flat = true | |||||
__meta__ = { | |||||
"_edit_use_anchors_": false | |||||
} | |||||
[node name="LogPanel" parent="." instance=ExtResource( 2 )] |