Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show variable declarations, fix error with DialogueRunner.Stop() #51

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Samples/MarkupPalette/PaletteSample.tscn
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion Samples/Space/SpaceSample.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
82 changes: 77 additions & 5 deletions addons/YarnSpinner-Godot/Editor/YarnProjectInspectorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,7 +16,6 @@ namespace YarnSpinnerGodot.Editor
[Tool]
public partial class YarnProjectInspectorPlugin : EditorInspectorPlugin
{

private YarnCompileErrorsPropertyEditor _compileErrorsPropertyEditor;
private ScrollContainer _parseErrorControl;
private YarnProject _project;
Expand Down Expand Up @@ -51,7 +52,7 @@ public override bool _ParseProperty(GodotObject @object, Variant.Type type,
{
return false;
}

if (IsTresYarnProject(project))
{
return true;
Expand All @@ -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))
Expand Down Expand Up @@ -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<Label>();
label.Text = labelText;
vbox.AddChild(label);
}

scrollContainer.CustomMinimumSize =
new Vector2(0, 150);
AddCustomControl(scrollContainer);
}

return true;
}

return false;
}
catch (Exception e)
Expand Down Expand Up @@ -424,11 +497,10 @@ public override void _ParseBegin(GodotObject @object)
catch (Exception e)
{
GD.PushError(
$"Error in {nameof(YarnProjectInspectorPlugin)}: {e.Message}\n{e.StackTrace}");
$"Error in {nameof(YarnProjectInspectorPlugin)}.{nameof(_ParseBegin)}(): {e.Message}\n{e.StackTrace}");
}
}


private void OnBaseLocaleChanged()
{
if (!IsInstanceValid(_project))
Expand Down
10 changes: 8 additions & 2 deletions addons/YarnSpinner-Godot/Runtime/DialogueRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
DEALINGS IN THE SOFTWARE.

*/

#nullable disable

using System.Collections.Generic;
Expand Down Expand Up @@ -774,7 +775,7 @@ public override void _Ready()
// Load this new Yarn Project.
SetProject(yarnProject);
}

if (lineProvider == null)
{
// If we don't have a line provider, create a
Expand Down Expand Up @@ -1371,9 +1372,14 @@ private void DialogueViewCompletedInterrupt(DialogueViewBase dialogueView)
}
}

void ContinueDialogue()
private void ContinueDialogue()
{
CurrentLine = null;
if (!IsDialogueRunning)
{
return;
}

Dialogue.Continue();
}

Expand Down
2 changes: 1 addition & 1 deletion addons/YarnSpinner-Godot/Runtime/SerializedDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SerializedDeclaration
BuiltinTypes.Number
};

public string name = "$variable";
public string name;

public string typeName = BuiltinTypes.String.Name;

Expand Down
2 changes: 1 addition & 1 deletion addons/YarnSpinner-Godot/Runtime/YarnProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public SerializedDeclaration[] SerializedDeclarations
try
{
_serializedDeclarations =
JsonSerializer.Deserialize<SerializedDeclaration[]>(_serializedDeclarationsJSON);
JsonSerializer.Deserialize<SerializedDeclaration[]>(_serializedDeclarationsJSON, YarnProject.JSONOptions);
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion addons/YarnSpinner-Godot/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="YarnSpinner-Godot"
description="Yarn language based dialogue system plugin for Godot"
author="dogboydog"
version="0.2.4"
version="0.2.5"
script="YarnSpinnerPlugin.cs"
Loading