-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* yarncommands for gdscript * add sample that registers commands and implements a simple view with GDScript * add GetVariantValue to InMemoryVariableStorage.cs, add more examples of cross language scripting * update CHANGELOG.md, update version to 0.2.14 * add GDScript options list view example * add example options array --------- Co-authored-by: Daniel Barry <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,568 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
See [here](https://docs.yarnspinner.dev/beginners-guide/making-a-game/yarn-spinner-for-godot) for installation. | ||
You can clone the repo at this tag, or download the below zip and use the addons/ folder inside it to follow the setup instructions. | ||
If you open the complete repository as a Godot project, you can try a variety of samples demonstrating code and end results of various features of YarnSpinner for Godot. | ||
|
||
## 👩🚒 Getting Help | ||
|
||
There are several places you can go to get help with Yarn Spinner. | ||
|
||
* Join the [Yarn Spinner Discord](https://discord.gg/yarnspinner) (`#godot` channel). | ||
* To report a bug, [file an issue on GitHub](https://github.com/YarnSpinnerTool/YarnSpinner-Godot/issues). | ||
|
||
* If you would like to support the development of this plugin, other open source contributions, and video games by the maintainer, | ||
consider donating at [ko-fi.com/decrepitgames](https://ko-fi.com/decrepitgames). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,3 +81,4 @@ Temporary Items | |
.import | ||
build | ||
*.csproj.old* | ||
*DotSettings.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Samples/GDScriptIntegration/CrossLanguageScriptingExample.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Demonstrates interacting with C# YarnSpinner-Godot | ||
# components from GDScript. | ||
|
||
extends Control | ||
@export var dialogue_runner: DialogueRunner | ||
@export var logo: Control | ||
@export var yarn_project: YarnProject | ||
func _ready() -> void: | ||
dialogue_runner.AddCommandHandlerCallable("show_logo", show_logo) | ||
dialogue_runner.onDialogueComplete.connect(on_dialogue_complete) | ||
var var_name : String = "$myVariableSetFromGDScript" | ||
dialogue_runner.variableStorage.SetValue( var_name, "Yay!") | ||
var var_value = dialogue_runner.variableStorage.GetVariantValue(var_name) | ||
print("Value of %s: %s" % [var_name, var_value]) | ||
|
||
func show_logo(logo_path) -> void: | ||
""" | ||
Async handler for the <<show_logo logo_path>> command. | ||
""" | ||
print("Showing logo...") | ||
var logo_load_error: Error = ResourceLoader.load_threaded_request(logo_path) | ||
if logo_load_error != OK: | ||
print("Failed to load logo %s: Error %s" % [logo_path, logo_load_error]) | ||
return | ||
|
||
var logo_load_status : ResourceLoader.ThreadLoadStatus = ResourceLoader.ThreadLoadStatus.THREAD_LOAD_IN_PROGRESS | ||
while logo_load_status == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_IN_PROGRESS: | ||
logo_load_status = ResourceLoader.load_threaded_get_status(logo_path) | ||
await get_tree().process_frame | ||
|
||
if logo_load_status != ResourceLoader.ThreadLoadStatus.THREAD_LOAD_LOADED: | ||
print("Failed to load %s. Error: %s" % [logo_path, logo_load_status]) | ||
return | ||
logo.texture = ResourceLoader.load_threaded_get(logo_path) | ||
logo.visible = true | ||
|
||
var tween := create_tween() | ||
tween.tween_property(logo, "modulate", Color.BLUE , 1.0) | ||
await tween.finished | ||
tween = create_tween() | ||
tween.tween_property(logo, "modulate", Color.WHITE , 1.0) | ||
await tween.finished | ||
await get_tree().create_timer(1.0).timeout | ||
print("Hiding logo...") | ||
logo.visible = false | ||
|
||
func on_dialogue_complete() -> void: | ||
print("Dialogue completed.") |
22 changes: 22 additions & 0 deletions
22
Samples/GDScriptIntegration/Dialogue/GDScriptIntegration.yarn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
title: GDScriptIntegration | ||
tags: | ||
--- | ||
<<declare $myVariableSetFromGDScript to "" as string>> | ||
Gary: So, can I use [fx type="wave"]GDScript[/fx] with YarnSpinner? #my_metadata #line:02fa0cd | ||
Derrick: Many features can be used with GDScript. For example, you can make a custom view like the one in this scene. #line:09c1c2c | ||
Derrick: You can also interact with DialogueRunner and variable storage nodes with cross-language scripting. #line:0b086af | ||
Derrick: And you can also write commands in GDScript by using AddCommandHandlerCallable. Your GDScript commands can even use 'await'. Look: #line:0c22e97 | ||
<<show_logo "res://addons/YarnSpinner-Godot/Editor/Icons/YarnSpinnerLogo.png">> | ||
Derrick: Do you know about options, too? You can make an "OptionsListView" with GDScript, too. | ||
-> Yes | ||
Derrick: Nice. | ||
<<jump GDScriptIntegrationFinish>> | ||
-> No | ||
Derrick: Well, you can prompt the player to pick an option. | ||
<<jump GDScriptIntegrationFinish>> | ||
=== | ||
|
||
title: GDScriptIntegrationFinish | ||
--- | ||
Gary: {$myVariableSetFromGDScript} That's cool. I will look at the GDScriptIntegration sample code to learn about this. #line:020bb2b | ||
=== |
14 changes: 14 additions & 0 deletions
14
Samples/GDScriptIntegration/Dialogue/GDScriptIntegration.yarn.import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[remap] | ||
|
||
importer="yarnscript" | ||
type="Resource" | ||
uid="uid://bfoa7hr2oeryv" | ||
path="res://.godot/imported/GDScriptIntegration.yarn-db27ea88bc8a407b72b6da1ec02824b9.tres" | ||
|
||
[deps] | ||
|
||
source_file="res://Samples/GDScriptIntegration/Dialogue/GDScriptIntegration.yarn" | ||
dest_files=["res://.godot/imported/GDScriptIntegration.yarn-db27ea88bc8a407b72b6da1ec02824b9.tres"] | ||
|
||
[params] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
[gd_scene load_steps=12 format=3 uid="uid://hvtydqjfdlf5"] | ||
|
||
[ext_resource type="Script" path="res://addons/YarnSpinner-Godot/Runtime/DialogueRunner.cs" id="1_1er8s"] | ||
[ext_resource type="Resource" uid="uid://c0qdj0h48fu6a" path="res://Samples/GDScriptIntegration/GDScriptIntegration.yarnproject" id="2_15buf"] | ||
[ext_resource type="Resource" uid="uid://c631us202ijmk" path="res://Samples/MarkupPalette/example_markup_palette.tres" id="3_3qr8r"] | ||
[ext_resource type="Script" path="res://Samples/GDScriptIntegration/CrossLanguageScriptingExample.gd" id="3_05a7h"] | ||
[ext_resource type="Script" path="res://addons/YarnSpinner-Godot/Runtime/Views/GDScriptViewAdapter.cs" id="3_8do86"] | ||
[ext_resource type="Script" path="res://Samples/ReturnOnComplete.cs" id="4_6b5el"] | ||
[ext_resource type="Script" path="res://Samples/GDScriptIntegration/SimpleGDScriptLineView.gd" id="4_ixyx4"] | ||
[ext_resource type="Script" path="res://addons/YarnSpinner-Godot/Runtime/Views/OptionsListView.cs" id="5_jois6"] | ||
[ext_resource type="PackedScene" uid="uid://b56ngcrq31nc5" path="res://addons/YarnSpinner-Godot/Scenes/OptionView.tscn" id="6_0v15m"] | ||
[ext_resource type="Script" path="res://addons/YarnSpinner-Godot/Runtime/InMemoryVariableStorage.cs" id="8_fijq0"] | ||
[ext_resource type="Script" path="res://addons/YarnSpinner-Godot/Runtime/LineProviders/TextLineProvider.cs" id="9_a8pi7"] | ||
|
||
[node name="PaletteSample" type="Node2D"] | ||
|
||
[node name="CanvasLayer" type="CanvasLayer" parent="."] | ||
layer = 0 | ||
|
||
[node name="BackgroundColor" type="ColorRect" parent="CanvasLayer"] | ||
z_index = -7 | ||
z_as_relative = false | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
mouse_filter = 2 | ||
color = Color(0.00260118, 0.121715, 0.193433, 1) | ||
|
||
[node name="GDScriptYarnSpinnerCanvasLayer" type="CanvasLayer" parent="."] | ||
|
||
[node name="DialogueRunner" type="Control" parent="GDScriptYarnSpinnerCanvasLayer" node_paths=PackedStringArray("variableStorage", "dialogueViews", "lineProvider")] | ||
layout_mode = 3 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
mouse_filter = 2 | ||
script = ExtResource("1_1er8s") | ||
yarnProject = ExtResource("2_15buf") | ||
variableStorage = NodePath("../InMemoryVariableStorage") | ||
dialogueViews = [NodePath("../LineViewAdapter"), NodePath("../OptionsListView")] | ||
startNode = "GDScriptIntegration" | ||
lineProvider = NodePath("../TextLineProvider") | ||
|
||
[node name="CrossLanguageScriptingExample" type="Control" parent="GDScriptYarnSpinnerCanvasLayer" node_paths=PackedStringArray("dialogue_runner")] | ||
layout_mode = 3 | ||
anchors_preset = 0 | ||
offset_right = 40.0 | ||
offset_bottom = 40.0 | ||
script = ExtResource("3_05a7h") | ||
dialogue_runner = NodePath("../DialogueRunner") | ||
|
||
[node name="VariableDebugText" type="RichTextLabel" parent="GDScriptYarnSpinnerCanvasLayer"] | ||
|
||
[node name="LineViewAdapter" type="Control" parent="GDScriptYarnSpinnerCanvasLayer" node_paths=PackedStringArray("GDScriptView")] | ||
layout_mode = 3 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
mouse_filter = 2 | ||
script = ExtResource("3_8do86") | ||
GDScriptView = NodePath("SimpleGDScriptLineView") | ||
|
||
[node name="ViewControl" type="Control" parent="GDScriptYarnSpinnerCanvasLayer/LineViewAdapter"] | ||
layout_mode = 1 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="LineText" type="RichTextLabel" parent="GDScriptYarnSpinnerCanvasLayer/LineViewAdapter/ViewControl"] | ||
layout_mode = 1 | ||
anchors_preset = 8 | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
offset_left = -610.0 | ||
offset_top = -352.0 | ||
offset_right = 640.0 | ||
offset_bottom = 193.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
theme_override_font_sizes/bold_italics_font_size = 36 | ||
theme_override_font_sizes/italics_font_size = 36 | ||
theme_override_font_sizes/mono_font_size = 36 | ||
theme_override_font_sizes/normal_font_size = 36 | ||
theme_override_font_sizes/bold_font_size = 36 | ||
bbcode_enabled = true | ||
text = "The dialogue text should appear here!" | ||
|
||
[node name="ColorRect" type="ColorRect" parent="GDScriptYarnSpinnerCanvasLayer/LineViewAdapter/ViewControl/LineText"] | ||
modulate = Color(0.203922, 0.192157, 0.192157, 0.458824) | ||
show_behind_parent = true | ||
layout_mode = 1 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
offset_left = -1.0 | ||
offset_right = -12.0 | ||
offset_bottom = -158.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="CharacterNameText" type="RichTextLabel" parent="GDScriptYarnSpinnerCanvasLayer/LineViewAdapter/ViewControl"] | ||
self_modulate = Color(0.321569, 0.87451, 0.254902, 1) | ||
layout_mode = 1 | ||
anchors_preset = 8 | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
offset_left = -607.0 | ||
offset_top = -415.0 | ||
offset_right = 279.0 | ||
offset_bottom = -362.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
theme_override_font_sizes/bold_italics_font_size = 36 | ||
theme_override_font_sizes/italics_font_size = 36 | ||
theme_override_font_sizes/mono_font_size = 36 | ||
theme_override_font_sizes/normal_font_size = 36 | ||
theme_override_font_sizes/bold_font_size = 36 | ||
bbcode_enabled = true | ||
text = "Character Name" | ||
|
||
[node name="ColorRect" type="ColorRect" parent="GDScriptYarnSpinnerCanvasLayer/LineViewAdapter/ViewControl/CharacterNameText"] | ||
modulate = Color(0.203922, 0.192157, 0.192157, 0.458824) | ||
show_behind_parent = true | ||
layout_mode = 0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
|
||
[node name="ContinueButton" type="Button" parent="GDScriptYarnSpinnerCanvasLayer/LineViewAdapter/ViewControl"] | ||
layout_mode = 1 | ||
anchors_preset = 7 | ||
anchor_left = 0.5 | ||
anchor_top = 1.0 | ||
anchor_right = 0.5 | ||
anchor_bottom = 1.0 | ||
offset_left = 337.0 | ||
offset_top = -463.0 | ||
offset_right = 569.0 | ||
offset_bottom = -363.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 0 | ||
mouse_default_cursor_shape = 2 | ||
theme_override_font_sizes/font_size = 36 | ||
text = "Continue" | ||
|
||
[node name="SimpleGDScriptLineView" type="Control" parent="GDScriptYarnSpinnerCanvasLayer/LineViewAdapter" node_paths=PackedStringArray("continue_button")] | ||
anchors_preset = 0 | ||
offset_right = 40.0 | ||
offset_bottom = 40.0 | ||
script = ExtResource("4_ixyx4") | ||
continue_button = NodePath("../ViewControl/ContinueButton") | ||
|
||
[node name="OptionsListView" type="Control" parent="GDScriptYarnSpinnerCanvasLayer" node_paths=PackedStringArray("lastLineCharacterNameText", "lastLineText", "viewControl", "boxContainer")] | ||
layout_mode = 3 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
mouse_filter = 2 | ||
script = ExtResource("5_jois6") | ||
optionViewPrefab = ExtResource("6_0v15m") | ||
palette = ExtResource("3_3qr8r") | ||
lastLineCharacterNameText = NodePath("ViewControl/LastLineCharacterNameText") | ||
lastLineText = NodePath("ViewControl/LastLineText") | ||
viewControl = NodePath("ViewControl") | ||
boxContainer = NodePath("ViewControl/VBoxContainer") | ||
|
||
[node name="ViewControl" type="Control" parent="GDScriptYarnSpinnerCanvasLayer/OptionsListView"] | ||
layout_mode = 1 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="VBoxContainer" type="VBoxContainer" parent="GDScriptYarnSpinnerCanvasLayer/OptionsListView/ViewControl"] | ||
custom_minimum_size = Vector2(160, 0) | ||
layout_mode = 1 | ||
anchors_preset = 8 | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
offset_left = -547.0 | ||
offset_top = -213.0 | ||
offset_right = 547.0 | ||
offset_bottom = 287.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="LastLineText" type="RichTextLabel" parent="GDScriptYarnSpinnerCanvasLayer/OptionsListView/ViewControl"] | ||
visible = false | ||
layout_mode = 1 | ||
anchors_preset = 5 | ||
anchor_left = 0.5 | ||
anchor_right = 0.5 | ||
offset_left = -610.0 | ||
offset_top = 100.0 | ||
offset_right = 279.0 | ||
offset_bottom = 185.0 | ||
grow_horizontal = 2 | ||
theme_override_font_sizes/bold_italics_font_size = 36 | ||
theme_override_font_sizes/italics_font_size = 36 | ||
theme_override_font_sizes/mono_font_size = 36 | ||
theme_override_font_sizes/normal_font_size = 36 | ||
theme_override_font_sizes/bold_font_size = 36 | ||
bbcode_enabled = true | ||
text = "The last line text goes here" | ||
scroll_active = false | ||
|
||
[node name="ColorRect" type="ColorRect" parent="GDScriptYarnSpinnerCanvasLayer/OptionsListView/ViewControl/LastLineText"] | ||
modulate = Color(0.203922, 0.192157, 0.192157, 0.458824) | ||
show_behind_parent = true | ||
layout_mode = 1 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="LastLineCharacterNameText" type="RichTextLabel" parent="GDScriptYarnSpinnerCanvasLayer/OptionsListView/ViewControl"] | ||
visible = false | ||
self_modulate = Color(0.321569, 0.87451, 0.254902, 1) | ||
layout_mode = 1 | ||
anchors_preset = 8 | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
offset_left = -608.0 | ||
offset_top = -416.0 | ||
offset_right = 278.0 | ||
offset_bottom = -363.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
theme_override_font_sizes/bold_italics_font_size = 36 | ||
theme_override_font_sizes/italics_font_size = 36 | ||
theme_override_font_sizes/mono_font_size = 36 | ||
theme_override_font_sizes/normal_font_size = 36 | ||
theme_override_font_sizes/bold_font_size = 36 | ||
bbcode_enabled = true | ||
text = "Character Name" | ||
|
||
[node name="ColorRect" type="ColorRect" parent="GDScriptYarnSpinnerCanvasLayer/OptionsListView/ViewControl/LastLineCharacterNameText"] | ||
modulate = Color(0.203922, 0.192157, 0.192157, 0.458824) | ||
show_behind_parent = true | ||
layout_mode = 0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
|
||
[node name="InMemoryVariableStorage" type="Node" parent="GDScriptYarnSpinnerCanvasLayer"] | ||
script = ExtResource("8_fijq0") | ||
|
||
[node name="TextLineProvider" type="Node2D" parent="GDScriptYarnSpinnerCanvasLayer"] | ||
script = ExtResource("9_a8pi7") | ||
|
||
[node name="ReturnOnComplete" type="Node2D" parent="." node_paths=PackedStringArray("dialogueRunner")] | ||
script = ExtResource("4_6b5el") | ||
dialogueRunner = NodePath("../GDScriptYarnSpinnerCanvasLayer/DialogueRunner") |
Oops, something went wrong.