From e40105e045a3aa298a91a0f109474350f44a1d6d Mon Sep 17 00:00:00 2001 From: dogboydog Date: Sun, 28 Apr 2024 13:14:40 -0400 Subject: [PATCH] fix #50 - errors calling Stop if the runner was running a command like wait fix #44 - show variable declarations in the yarn project inspector --- CHANGELOG.md | 5 ++ Samples/MarkupPalette/PaletteSample.tscn | 2 +- Samples/Space/SpaceSample.tscn | 2 +- .../Editor/YarnProjectInspectorPlugin.cs | 82 +++++++++++++++++-- .../Runtime/DialogueRunner.cs | 10 ++- .../Runtime/SerializedDeclaration.cs | 2 +- .../YarnSpinner-Godot/Runtime/YarnProject.cs | 2 +- addons/YarnSpinner-Godot/plugin.cfg | 2 +- 8 files changed, 95 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0602c89..52b631c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.2.5] 2024-04-28 +* fix #50 - errors calling Stop if the runner was running a command like wait +* fix #44 - show variable declarations in the yarn project inspector +* Add SQL Variable storage Sample (not delivered in the addons/ directory, open this repository as a Godot project to try this sample) + ## [0.2.4] 2024-04-17 * fix #46 - The Create Yarn Project menu item was not working in 4.1.2 * fix #45 - Add `#nullable disable` to the plugin's C# source files for compatibility with projects with nullable enabled diff --git a/Samples/MarkupPalette/PaletteSample.tscn b/Samples/MarkupPalette/PaletteSample.tscn index 0ccc394..554b380 100644 --- a/Samples/MarkupPalette/PaletteSample.tscn +++ b/Samples/MarkupPalette/PaletteSample.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=3 uid="uid://uxc1jm6ayoar"] [ext_resource type="PackedScene" uid="uid://bv42g323prh5f" path="res://addons/YarnSpinner-Godot/Scenes/DefaultDialogueSystem.tscn" id="1_luv5t"] -[ext_resource type="Resource" uid="uid://374uxyocig3s" path="res://Samples/MarkupPalette/Palette.yarnproject" id="2_yfv6n"] +[ext_resource type="Resource" uid="uid://rr8xlqj5fkjd" path="res://Samples/MarkupPalette/Palette.yarnproject" id="2_yfv6n"] [ext_resource type="Resource" uid="uid://c631us202ijmk" path="res://Samples/MarkupPalette/example_markup_palette.tres" id="3_1wwmk"] [ext_resource type="Script" path="res://Samples/ReturnOnComplete.cs" id="4_q6j15"] diff --git a/Samples/Space/SpaceSample.tscn b/Samples/Space/SpaceSample.tscn index 58f69cb..6b0d4b1 100644 --- a/Samples/Space/SpaceSample.tscn +++ b/Samples/Space/SpaceSample.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=18 format=3 uid="uid://ddbq27wcm6emj"] -[ext_resource type="Resource" uid="uid://cs4nr6ua3wimj" path="res://Samples/Space/Dialogue/SpaceYarnProject.yarnproject" id="1"] +[ext_resource type="Resource" uid="uid://d2lkhhnqha4qi" path="res://Samples/Space/Dialogue/SpaceYarnProject.yarnproject" id="1"] [ext_resource type="Texture2D" uid="uid://delt5hkois0xf" path="res://Samples/Space/Sprites/Ship-Face-Happy.png" id="2_3dm8d"] [ext_resource type="Script" path="res://Samples/Space/Scripts/SpaceSample.cs" id="3"] [ext_resource type="Texture2D" uid="uid://dsxwawdra77cw" path="res://Samples/Space/Sprites/Ship-Face-Neutral.png" id="3_b3htj"] diff --git a/addons/YarnSpinner-Godot/Editor/YarnProjectInspectorPlugin.cs b/addons/YarnSpinner-Godot/Editor/YarnProjectInspectorPlugin.cs index 726221c..71550f7 100644 --- a/addons/YarnSpinner-Godot/Editor/YarnProjectInspectorPlugin.cs +++ b/addons/YarnSpinner-Godot/Editor/YarnProjectInspectorPlugin.cs @@ -2,9 +2,11 @@ #if TOOLS using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Godot; using Microsoft.Extensions.FileSystemGlobbing; +using Yarn; using Yarn.Compiler; using YarnSpinnerGodot.Editor.UI; @@ -14,7 +16,6 @@ namespace YarnSpinnerGodot.Editor [Tool] public partial class YarnProjectInspectorPlugin : EditorInspectorPlugin { - private YarnCompileErrorsPropertyEditor _compileErrorsPropertyEditor; private ScrollContainer _parseErrorControl; private YarnProject _project; @@ -51,7 +52,7 @@ public override bool _ParseProperty(GodotObject @object, Variant.Type type, { return false; } - + if (IsTresYarnProject(project)) { return true; @@ -73,7 +74,6 @@ public override bool _ParseProperty(GodotObject @object, Variant.Type type, // can't use nameof for private fields here "_baseLocalizationJSON", "_lineMetadataJSON", - "_serializedDeclarationsJSON", "_listOfFunctionsJSON", }; if (hideProperties.Contains(path)) @@ -116,6 +116,79 @@ public override bool _ParseProperty(GodotObject @object, Variant.Type type, return true; } + if (path == "_serializedDeclarationsJSON") + { + var header = new HBoxContainer(); + header.AddChild(new Label + { + Text = " Story Variables", + SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, + SizeFlagsVertical = Control.SizeFlags.ExpandFill, + }); + header.AddChild(new Label + { + Text = _project.SerializedDeclarations == null || _project.SerializedDeclarations.Length == 0 + ? "None" + : _project.SerializedDeclarations.Length.ToString(CultureInfo.InvariantCulture), + SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, + SizeFlagsVertical = Control.SizeFlags.ExpandFill, + }); + AddCustomControl(header); + if (_project.SerializedDeclarations is {Length: >= 1}) + { + var scrollContainer = new ScrollContainer + { + SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, + SizeFlagsVertical = Control.SizeFlags.ExpandFill, + }; + + var vbox = new VBoxContainer + { + SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, + SizeFlagsVertical = Control.SizeFlags.ShrinkBegin, + }; + scrollContainer.AddChild(vbox); + foreach (var declaration in _project.SerializedDeclarations) + { + var labelText = $"{declaration.name} ({declaration.typeName})\n"; + if (declaration.isImplicit) + { + labelText += "Implicitly declared."; + } + else + { + labelText += $"Declared in {declaration.sourceYarnAssetPath}\n"; + } + + var typeName = declaration.typeName; + var defaultValue = ""; + if (typeName == BuiltinTypes.String.Name) + { + defaultValue = declaration.defaultValueString; + } + else if (typeName == BuiltinTypes.Boolean.Name) + { + defaultValue = declaration.defaultValueBool.ToString(); + } + else if (typeName == BuiltinTypes.Number.Name) + { + defaultValue = declaration.defaultValueNumber.ToString(CultureInfo.InvariantCulture); + } + + labelText += $"Default value: {defaultValue}\n"; + var label = _fileNameLabelScene.Instantiate