From 436cf02c54142f9feb9e3000e9e74f0f7859a997 Mon Sep 17 00:00:00 2001 From: dogboydog Date: Wed, 24 Apr 2024 21:58:47 -0400 Subject: [PATCH 1/3] begin porting sqlite-net-pcl sample --- Samples/SQLiteVariableStorage/SQLSample.tscn | 30 +++ .../SQLSample.yarnproject | 10 + .../SQLSample.yarnproject.import | 14 ++ .../SQLVariableStorage.cs | 229 ++++++++++++++++++ Samples/SQLiteVariableStorage/SqlSample.yarn | 39 +++ .../SqlSample.yarn.import | 14 ++ Samples/SampleEntryPoint.cs | 118 ++++----- YarnSpinner-Godot.csproj | 6 +- 8 files changed, 400 insertions(+), 60 deletions(-) create mode 100644 Samples/SQLiteVariableStorage/SQLSample.tscn create mode 100644 Samples/SQLiteVariableStorage/SQLSample.yarnproject create mode 100644 Samples/SQLiteVariableStorage/SQLSample.yarnproject.import create mode 100644 Samples/SQLiteVariableStorage/SQLVariableStorage.cs create mode 100644 Samples/SQLiteVariableStorage/SqlSample.yarn create mode 100644 Samples/SQLiteVariableStorage/SqlSample.yarn.import diff --git a/Samples/SQLiteVariableStorage/SQLSample.tscn b/Samples/SQLiteVariableStorage/SQLSample.tscn new file mode 100644 index 0000000..8d90f5e --- /dev/null +++ b/Samples/SQLiteVariableStorage/SQLSample.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=4 format=3 uid="uid://dt33g06nhtxn2"] + +[ext_resource type="PackedScene" uid="uid://dqe5yshlcmnpg" path="res://addons/YarnSpinner-Godot/Scenes/RoundedDialogueSystem.tscn" id="1_8wwci"] +[ext_resource type="Resource" uid="uid://tsj53mnkwps3" path="res://Samples/SQLiteVariableStorage/SQLSample.yarnproject" id="2_73843"] +[ext_resource type="Script" path="res://Samples/SQLiteVariableStorage/SQLVariableStorage.cs" id="3_71oeg"] + +[node name="SqlSample" type="Node2D"] + +[node name="RoundedYarnSpinnerCanvasLayer" parent="." instance=ExtResource("1_8wwci")] + +[node name="DialogueRunner" parent="RoundedYarnSpinnerCanvasLayer" index="0" node_paths=PackedStringArray("variableStorage")] +yarnProject = ExtResource("2_73843") +variableStorage = NodePath("../SQLVariableStorage") +startNode = "SqlSample" +startAutomatically = true + +[node name="ColorRect" type="ColorRect" parent="RoundedYarnSpinnerCanvasLayer"] +z_index = -6 +z_as_relative = false +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.187867, 0.096, 0.2, 1) + +[node name="SQLVariableStorage" type="Node2D" parent="RoundedYarnSpinnerCanvasLayer"] +script = ExtResource("3_71oeg") + +[editable path="RoundedYarnSpinnerCanvasLayer"] diff --git a/Samples/SQLiteVariableStorage/SQLSample.yarnproject b/Samples/SQLiteVariableStorage/SQLSample.yarnproject new file mode 100644 index 0000000..5cbeb26 --- /dev/null +++ b/Samples/SQLiteVariableStorage/SQLSample.yarnproject @@ -0,0 +1,10 @@ +{ + "projectFileVersion": 2, + "sourceFiles": [ + "**/*.yarn" + ], + "excludeFiles": [], + "localisation": {}, + "baseLanguage": "en", + "compilerOptions": {} +} \ No newline at end of file diff --git a/Samples/SQLiteVariableStorage/SQLSample.yarnproject.import b/Samples/SQLiteVariableStorage/SQLSample.yarnproject.import new file mode 100644 index 0000000..16debed --- /dev/null +++ b/Samples/SQLiteVariableStorage/SQLSample.yarnproject.import @@ -0,0 +1,14 @@ +[remap] + +importer="yarnproject" +type="Resource" +uid="uid://tsj53mnkwps3" +path="res://.godot/imported/SQLSample.yarnproject-492bf8c35d4a0f0a8978692c27ea366f.tres" + +[deps] + +source_file="res://Samples/SQLiteVariableStorage/SQLSample.yarnproject" +dest_files=["res://.godot/imported/SQLSample.yarnproject-492bf8c35d4a0f0a8978692c27ea366f.tres"] + +[params] + diff --git a/Samples/SQLiteVariableStorage/SQLVariableStorage.cs b/Samples/SQLiteVariableStorage/SQLVariableStorage.cs new file mode 100644 index 0000000..66666ad --- /dev/null +++ b/Samples/SQLiteVariableStorage/SQLVariableStorage.cs @@ -0,0 +1,229 @@ +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Godot; +using SQLite; +using YarnSpinnerGodot; + +public partial class SQLVariableStorage : VariableStorageBehaviour +{ + private SQLiteConnection db; // the database connector + + public override void _EnterTree() + { + // pick a place on disk for the database to save to + string path = ProjectSettings.GlobalizePath("user://db.sqlite"); + // create a new database connection to speak to it + db = new SQLiteConnection(path); + // create the tables we need + db.CreateTable(); + db.CreateTable(); + db.CreateTable(); + GD.Print($"Initialized database at {path}"); + } + + public override bool TryGetValue(string variableName, out T result) + { + string query = ""; + List results = new(); + // try to get a value from the given table, as a generic object + if (typeof(T) == typeof(string)) + { + query = "SELECT * FROM YarnString WHERE key = ?"; + results.AddRange(db.Query(query, variableName)); + } + else if (typeof(T) == typeof(bool)) + { + query = "SELECT * FROM YarnBool WHERE key = ?"; + results.AddRange(db.Query(query, variableName)); + } + else if (typeof(T) == typeof(float)) + { + query = "SELECT * FROM YarnFloat WHERE key = ?"; + results.AddRange(db.Query(query, variableName)); + } + + // if a result was found, convert it to type T and assign it + if (results?.Count > 0) + { + if (results[0] is YarnFloat f) + { + result = (T)(object)f.value; + } + else if (results[0] is YarnBool b) + { + result = (T)(object)b.value; + } else if (results[0] is YarnString s) + { + result = (T)(object)s.value; + } + else + { + throw new ArgumentException($"Unknown variable type {typeof(T)}"); + } + return true; + } + + // otherwise TryGetValue has failed + result = default(T); + return false; + } + + public override void SetValue(string variableName, string stringValue) + { + // check it doesn't exist already in other table + if (Exists(variableName, typeof(bool))) + { + throw new ArgumentException($"{variableName} is a bool."); + } + + if (Exists(variableName, typeof(float))) + { + throw new ArgumentException($"{variableName} is a float."); + } + + // if not, insert or update row in this table to the given value + string query = "INSERT OR REPLACE INTO YarnString (key, value)"; + query += "VALUES (?, ?)"; + db.Execute(query, variableName, stringValue); + } + + public override void SetValue(string variableName, float floatValue) + { + // check it doesn't exist already in other table + if (Exists(variableName, typeof(string))) + { + throw new ArgumentException($"{variableName} is a string."); + } + + if (Exists(variableName, typeof(float))) + { + throw new ArgumentException($"{variableName} is a float."); + } + + // if not, insert or update row in this table to the given value + string query = "INSERT OR REPLACE INTO YarnFloat (key, value)"; + query += "VALUES (?, ?)"; + db.Execute(query, variableName, floatValue); + } + + public override void SetValue(string variableName, bool boolValue) + { + // check it doesn't exist already in other table + if (Exists(variableName, typeof(string))) + { + throw new ArgumentException($"{variableName} is a string."); + } + + if (Exists(variableName, typeof(float))) + { + throw new ArgumentException($"{variableName} is a float."); + } + + // if not, insert or update row in this table to the given value + string query = "INSERT OR REPLACE INTO YarnBool (key, value)"; + query += "VALUES (?, ?)"; + db.Execute(query, variableName, boolValue); + } + + public override void Clear() + { + db.Execute("DELETE * FROM YarnString;"); + db.Execute("DELETE * FROM YarnBool;"); + db.Execute("DELETE * FROM YarnFloat;"); + } + + public override bool Contains(string variableName) + { + return Exists(variableName, typeof(string)) || + Exists(variableName, typeof(bool)) || + Exists(variableName, typeof(float)); + } + + public override void SetAllVariables(Dictionary floats, Dictionary strings, + Dictionary bools, bool clear = true) + { + foreach (var entry in floats) + { + SetValue(entry.Key, entry.Value); + } + + foreach (var entry in bools) + { + SetValue(entry.Key, entry.Value); + } + + foreach (var entry in strings) + { + SetValue(entry.Key, entry.Value); + } + } + + public override (Dictionary, Dictionary, Dictionary) GetAllVariables() + { + var floatQuery = "SELECT value FROM YarnFloat"; + var floats = db.Query(floatQuery) + .AsEnumerable() + .ToDictionary(f => f.key, f => f.value); + var stringQuery = "SELECT value FROM YarnString"; + var strings = db.Query(stringQuery) + .AsEnumerable() + .ToDictionary(f => f.key, f => f.value); + var boolQuery = "SELECT value FROM YarnBool"; + var booleans = db.Query(boolQuery) + .AsEnumerable() + .ToDictionary(f => f.key, f => f.value); + + return (floats, strings, booleans); + } + + private bool Exists(string variableName, Type type) + { + if (type == typeof(string)) + { + string stringResult; + if (TryGetValue(variableName, out stringResult)) + { + return (stringResult != null); + } + } + else if (type == typeof(bool)) + { + string boolResult; + if (TryGetValue(variableName, out boolResult)) + { + return (boolResult != null); + } + } + else if (type == typeof(float)) + { + string floatResult; + if (TryGetValue(variableName, out floatResult)) + { + return (floatResult != null); + } + } + + return false; + } +} + +public class YarnString +{ + [PrimaryKey] public string key { get; set; } + public string value { get; set; } +} + +public class YarnFloat +{ + [PrimaryKey] public string key { get; set; } + public float value { get; set; } +} + +public class YarnBool +{ + [PrimaryKey] public string key { get; set; } + public bool value { get; set; } +} \ No newline at end of file diff --git a/Samples/SQLiteVariableStorage/SqlSample.yarn b/Samples/SQLiteVariableStorage/SqlSample.yarn new file mode 100644 index 0000000..7abfc50 --- /dev/null +++ b/Samples/SQLiteVariableStorage/SqlSample.yarn @@ -0,0 +1,39 @@ +title: SqlSample +tags: +--- +<> +<> +<> +Guide: Alright, I've been waiting for my last applicant of the day. +Guide: Hmm, how do you say your name!? It says "S-Q-L". +-> Eskew-well + <> +-> Seekwill + <> +{$characterName}: My name is {$characterName}. +{$characterName}: I have trained for one thousand years to store the most variables of all time. +Guide: Wow. Impressive! Just how many variables do you think you could store?? +-> There's no limit. + <> +-> One thousand. + <> +-> Three. + <> +<> +Guide: Wh- what? Unlimited?? +Guide: Gahhh!!! +The guide ran away. +<> +Guide: Hmm. That's not bad. +<> +<> +Guide: I ...see. Where you come from, is that impressive? +<> + +Guide: Alright then, {$characterName}. You can store {$numVariables} variables... +<> +Guide: Welcome to Variable Academy. +<> +Guide: I'm afraid you're not cut out for Variable Academy. +<> +=== \ No newline at end of file diff --git a/Samples/SQLiteVariableStorage/SqlSample.yarn.import b/Samples/SQLiteVariableStorage/SqlSample.yarn.import new file mode 100644 index 0000000..7fc5ec1 --- /dev/null +++ b/Samples/SQLiteVariableStorage/SqlSample.yarn.import @@ -0,0 +1,14 @@ +[remap] + +importer="yarnscript" +type="Resource" +uid="uid://mno2y7y3atrn" +path="res://.godot/imported/SqlSample.yarn-1a034971b5ef626e0730aa486cf1cdf1.tres" + +[deps] + +source_file="res://Samples/SQLiteVariableStorage/SqlSample.yarn" +dest_files=["res://.godot/imported/SqlSample.yarn-1a034971b5ef626e0730aa486cf1cdf1.tres"] + +[params] + diff --git a/Samples/SampleEntryPoint.cs b/Samples/SampleEntryPoint.cs index 8e27bfd..23cf649 100644 --- a/Samples/SampleEntryPoint.cs +++ b/Samples/SampleEntryPoint.cs @@ -8,68 +8,68 @@ /// public partial class SampleEntryPoint : CanvasLayer { - [Export] private Button _spaceButton; - [Export] private Button _visualNovelButton; - [Export] private Button _markupPaletteButton; - [Export] private Button _pausingTypewriterButton; - [Export] private Button _roundedViewsButton; - - /// - /// Resource path to the packed scene of entry point scene - /// - public const string ENTRY_POINT_PATH = "res://Samples/SampleEntryPoint.tscn"; + [Export] private Button _spaceButton; + [Export] private Button _visualNovelButton; + [Export] private Button _markupPaletteButton; + [Export] private Button _pausingTypewriterButton; + [Export] private Button _roundedViewsButton; + + /// + /// Resource path to the packed scene of entry point scene + /// + public const string ENTRY_POINT_PATH = "res://Samples/SampleEntryPoint.tscn"; - // Called when the node enters the scene tree for the first time. - public override void _Ready() - { - _spaceButton.Pressed += () => LoadSample( - "res://Samples/Space/SpaceSample.tscn" - ); - _visualNovelButton.Pressed += () => LoadSample( - "res://Samples/VisualNovel/VisualNovelSample.tscn" - ); - _markupPaletteButton.Pressed += () => LoadSample( - "res://Samples/MarkupPalette/PaletteSample.tscn" - ); - _pausingTypewriterButton.Pressed += () => LoadSample( - "res://Samples/PausingTypewriter/PauseSample.tscn" - ); - _roundedViewsButton.Pressed += () => LoadSample( - "res://Samples/RoundedViews/RoundedSample.tscn" - ); + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + _spaceButton.Pressed += () => LoadSample( + "res://Samples/Space/SpaceSample.tscn" + ); + _visualNovelButton.Pressed += () => LoadSample( + "res://Samples/VisualNovel/VisualNovelSample.tscn" + ); + _markupPaletteButton.Pressed += () => LoadSample( + "res://Samples/MarkupPalette/PaletteSample.tscn" + ); + _pausingTypewriterButton.Pressed += () => LoadSample( + "res://Samples/PausingTypewriter/PauseSample.tscn" + ); + _roundedViewsButton.Pressed += () => LoadSample( + "res://Samples/RoundedViews/RoundedSample.tscn" + ); - _spaceButton.GrabFocus(); - } + _spaceButton.GrabFocus(); + } - public void LoadSample(string samplePath) - { - var samplePacked = ResourceLoader.Load(samplePath); - var sample = samplePacked.Instantiate(); - GetTree().Root.CallDeferred("add_child", sample); - QueueFree(); - } + public void LoadSample(string samplePath) + { + var samplePacked = ResourceLoader.Load(samplePath); + var sample = samplePacked.Instantiate(); + GetTree().Root.CallDeferred("add_child", sample); + QueueFree(); + } - /// - /// Return to the entry point - /// - public static void Return() - { - var root = ((SceneTree) Engine.GetMainLoop()).Root; - var nodesToFree = new List(); - for (var i = 0; i < root.GetChildCount(); i++) - { - nodesToFree.Add(root.GetChild(i)); - } + /// + /// Return to the entry point + /// + public static void Return() + { + var root = ((SceneTree) Engine.GetMainLoop()).Root; + var nodesToFree = new List(); + for (var i = 0; i < root.GetChildCount(); i++) + { + nodesToFree.Add(root.GetChild(i)); + } - foreach (var node in nodesToFree) - { - node.QueueFree(); - } + foreach (var node in nodesToFree) + { + node.QueueFree(); + } - var loadResult = root.GetTree().ChangeSceneToFile(ENTRY_POINT_PATH); - if (loadResult != Error.Ok) - { - GD.PushError($"Failed to load the sample entry point: {loadResult}"); - } - } -} \ No newline at end of file + var loadResult = root.GetTree().ChangeSceneToFile(ENTRY_POINT_PATH); + if (loadResult != Error.Ok) + { + GD.PushError($"Failed to load the sample entry point: {loadResult}"); + } + } +} diff --git a/YarnSpinner-Godot.csproj b/YarnSpinner-Godot.csproj index fbe2ab0..71c403c 100644 --- a/YarnSpinner-Godot.csproj +++ b/YarnSpinner-Godot.csproj @@ -1,4 +1,4 @@ - + net6.0 true @@ -12,5 +12,9 @@ + + + + \ No newline at end of file From c778f23d177e47581e361d6822ef87bdcb6846d9 Mon Sep 17 00:00:00 2001 From: dogboydog Date: Sat, 27 Apr 2024 00:31:07 -0400 Subject: [PATCH 2/3] Fix SQLite sample --- Samples/PausingTypewriter/PauseSample.tscn | 2 +- Samples/SQLiteVariableStorage/SQLSample.tscn | 8 +- .../SQLVariableStorage.cs | 57 ++++++--- Samples/SQLiteVariableStorage/SqlSample.yarn | 26 ++-- Samples/SampleEntryPoint.cs | 119 +++++++++--------- Samples/SampleEntryPoint.tscn | 25 +++- YarnSpinner-Godot.csproj | 3 +- .../Editor/YarnCompileErrorsPropertyEditor.cs | 2 +- .../YarnSpinner-Godot/Scenes/OptionView.tscn | 2 +- .../Scenes/RoundedDialogueSystem.tscn | 4 +- 10 files changed, 154 insertions(+), 94 deletions(-) diff --git a/Samples/PausingTypewriter/PauseSample.tscn b/Samples/PausingTypewriter/PauseSample.tscn index feff20e..f5be7d1 100644 --- a/Samples/PausingTypewriter/PauseSample.tscn +++ b/Samples/PausingTypewriter/PauseSample.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=7 format=3 uid="uid://ckp616grs7xrs"] [ext_resource type="PackedScene" uid="uid://bv42g323prh5f" path="res://addons/YarnSpinner-Godot/Scenes/DefaultDialogueSystem.tscn" id="1_m0dlq"] -[ext_resource type="Resource" uid="uid://btil08na83k0p" path="res://Samples/PausingTypewriter/PauseProj.yarnproject" id="2_j3415"] +[ext_resource type="Resource" uid="uid://21gon4fidoq8" path="res://Samples/PausingTypewriter/PauseProj.yarnproject" id="2_j3415"] [ext_resource type="Texture2D" uid="uid://crtrls05kcbu5" path="res://Samples/PausingTypewriter/sprites/talking.png" id="2_njmvd"] [ext_resource type="Script" path="res://Samples/PausingTypewriter/PauseResponder.cs" id="3_uqanb"] [ext_resource type="Texture2D" uid="uid://dk84dy4vqquds" path="res://Samples/PausingTypewriter/sprites/thinking.png" id="4_1i87u"] diff --git a/Samples/SQLiteVariableStorage/SQLSample.tscn b/Samples/SQLiteVariableStorage/SQLSample.tscn index 8d90f5e..13e8367 100644 --- a/Samples/SQLiteVariableStorage/SQLSample.tscn +++ b/Samples/SQLiteVariableStorage/SQLSample.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://dt33g06nhtxn2"] +[gd_scene load_steps=5 format=3 uid="uid://dt33g06nhtxn2"] [ext_resource type="PackedScene" uid="uid://dqe5yshlcmnpg" path="res://addons/YarnSpinner-Godot/Scenes/RoundedDialogueSystem.tscn" id="1_8wwci"] [ext_resource type="Resource" uid="uid://tsj53mnkwps3" path="res://Samples/SQLiteVariableStorage/SQLSample.yarnproject" id="2_73843"] [ext_resource type="Script" path="res://Samples/SQLiteVariableStorage/SQLVariableStorage.cs" id="3_71oeg"] +[ext_resource type="Script" path="res://Samples/ReturnOnComplete.cs" id="4_lgfx4"] [node name="SqlSample" type="Node2D"] @@ -22,9 +23,14 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 color = Color(0.187867, 0.096, 0.2, 1) [node name="SQLVariableStorage" type="Node2D" parent="RoundedYarnSpinnerCanvasLayer"] script = ExtResource("3_71oeg") +[node name="ReturnOnComplete" type="Node2D" parent="." node_paths=PackedStringArray("dialogueRunner")] +script = ExtResource("4_lgfx4") +dialogueRunner = NodePath("../RoundedYarnSpinnerCanvasLayer/DialogueRunner") + [editable path="RoundedYarnSpinnerCanvasLayer"] diff --git a/Samples/SQLiteVariableStorage/SQLVariableStorage.cs b/Samples/SQLiteVariableStorage/SQLVariableStorage.cs index 66666ad..7525692 100644 --- a/Samples/SQLiteVariableStorage/SQLVariableStorage.cs +++ b/Samples/SQLiteVariableStorage/SQLVariableStorage.cs @@ -7,6 +7,9 @@ using SQLite; using YarnSpinnerGodot; +/// +/// SQLite based custom variable storage example. +/// public partial class SQLVariableStorage : VariableStorageBehaviour { private SQLiteConnection db; // the database connector @@ -28,7 +31,31 @@ public override bool TryGetValue(string variableName, out T result) { string query = ""; List results = new(); - // try to get a value from the given table, as a generic object + if (typeof(T) == typeof(IConvertible)) + { + // we don't know the expected type + if (TryGetValue(variableName, out string stringResult)) + { + result = (T) (object) stringResult; + return true; + } + + if (TryGetValue(variableName, out float floatResult)) + { + result = (T) (object) floatResult; + return true; + } + + if (TryGetValue(variableName, out bool boolResult)) + { + result = (T) (object) boolResult; + return true; + } + + result = default(T); + return false; + } + if (typeof(T) == typeof(string)) { query = "SELECT * FROM YarnString WHERE key = ?"; @@ -50,19 +77,21 @@ public override bool TryGetValue(string variableName, out T result) { if (results[0] is YarnFloat f) { - result = (T)(object)f.value; + result = (T) (object) f.value; } else if (results[0] is YarnBool b) { - result = (T)(object)b.value; - } else if (results[0] is YarnString s) - { - result = (T)(object)s.value; + result = (T) (object) b.value; + } + else if (results[0] is YarnString s) + { + result = (T) (object) s.value; } else { throw new ArgumentException($"Unknown variable type {typeof(T)}"); - } + } + return true; } @@ -98,9 +127,9 @@ public override void SetValue(string variableName, float floatValue) throw new ArgumentException($"{variableName} is a string."); } - if (Exists(variableName, typeof(float))) + if (Exists(variableName, typeof(bool))) { - throw new ArgumentException($"{variableName} is a float."); + throw new ArgumentException($"{variableName} is a bool."); } // if not, insert or update row in this table to the given value @@ -191,18 +220,16 @@ private bool Exists(string variableName, Type type) } else if (type == typeof(bool)) { - string boolResult; - if (TryGetValue(variableName, out boolResult)) + if (TryGetValue(variableName, out bool _)) { - return (boolResult != null); + return true; } } else if (type == typeof(float)) { - string floatResult; - if (TryGetValue(variableName, out floatResult)) + if (TryGetValue(variableName, out float _)) { - return (floatResult != null); + return true; } } diff --git a/Samples/SQLiteVariableStorage/SqlSample.yarn b/Samples/SQLiteVariableStorage/SqlSample.yarn index 7abfc50..29ba08d 100644 --- a/Samples/SQLiteVariableStorage/SqlSample.yarn +++ b/Samples/SQLiteVariableStorage/SqlSample.yarn @@ -3,11 +3,11 @@ tags: --- <> <> -<> +<> Guide: Alright, I've been waiting for my last applicant of the day. Guide: Hmm, how do you say your name!? It says "S-Q-L". -> Eskew-well - <> + <> -> Seekwill <> {$characterName}: My name is {$characterName}. @@ -15,20 +15,22 @@ Guide: Hmm, how do you say your name!? It says "S-Q-L". Guide: Wow. Impressive! Just how many variables do you think you could store?? -> There's no limit. <> + Guide: Wh- what? Unlimited?? + Guide: Gahhh!!! + The guide ran away. + <> +-> Sixty two thousand. + <> + Guide: Formidable... imagine the heights you could reach under our guidance. + <> -> One thousand. <> + Guide: Hmm. That's not bad. + <> -> Three. <> -<> -Guide: Wh- what? Unlimited?? -Guide: Gahhh!!! -The guide ran away. -<> -Guide: Hmm. That's not bad. -<> -<> -Guide: I ...see. Where you come from, is that impressive? -<> + Guide: I ...see. + <> Guide: Alright then, {$characterName}. You can store {$numVariables} variables... <> diff --git a/Samples/SampleEntryPoint.cs b/Samples/SampleEntryPoint.cs index 23cf649..b46f13f 100644 --- a/Samples/SampleEntryPoint.cs +++ b/Samples/SampleEntryPoint.cs @@ -8,68 +8,69 @@ /// public partial class SampleEntryPoint : CanvasLayer { - [Export] private Button _spaceButton; - [Export] private Button _visualNovelButton; - [Export] private Button _markupPaletteButton; - [Export] private Button _pausingTypewriterButton; - [Export] private Button _roundedViewsButton; - - /// - /// Resource path to the packed scene of entry point scene - /// - public const string ENTRY_POINT_PATH = "res://Samples/SampleEntryPoint.tscn"; + [Export] private Button _spaceButton; + [Export] private Button _visualNovelButton; + [Export] private Button _markupPaletteButton; + [Export] private Button _pausingTypewriterButton; + [Export] private Button _roundedViewsButton; + [Export] private Button _sqliteButton; - // Called when the node enters the scene tree for the first time. - public override void _Ready() - { - _spaceButton.Pressed += () => LoadSample( - "res://Samples/Space/SpaceSample.tscn" - ); - _visualNovelButton.Pressed += () => LoadSample( - "res://Samples/VisualNovel/VisualNovelSample.tscn" - ); - _markupPaletteButton.Pressed += () => LoadSample( - "res://Samples/MarkupPalette/PaletteSample.tscn" - ); - _pausingTypewriterButton.Pressed += () => LoadSample( - "res://Samples/PausingTypewriter/PauseSample.tscn" - ); - _roundedViewsButton.Pressed += () => LoadSample( - "res://Samples/RoundedViews/RoundedSample.tscn" - ); + /// + /// Resource path to the packed scene of entry point scene + /// + public const string ENTRY_POINT_PATH = "res://Samples/SampleEntryPoint.tscn"; - _spaceButton.GrabFocus(); - } + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + _spaceButton.Pressed += () => LoadSample( + "res://Samples/Space/SpaceSample.tscn" + ); + _visualNovelButton.Pressed += () => LoadSample( + "res://Samples/VisualNovel/VisualNovelSample.tscn" + ); + _markupPaletteButton.Pressed += () => LoadSample( + "res://Samples/MarkupPalette/PaletteSample.tscn" + ); + _pausingTypewriterButton.Pressed += () => LoadSample( + "res://Samples/PausingTypewriter/PauseSample.tscn" + ); + _roundedViewsButton.Pressed += () => LoadSample( + "res://Samples/RoundedViews/RoundedSample.tscn" + ); + _sqliteButton.Pressed += () => LoadSample("res://Samples/SQLiteVariableStorage/SQLSample.tscn"); + _spaceButton.GrabFocus(); + } - public void LoadSample(string samplePath) - { - var samplePacked = ResourceLoader.Load(samplePath); - var sample = samplePacked.Instantiate(); - GetTree().Root.CallDeferred("add_child", sample); - QueueFree(); - } + public void LoadSample(string samplePath) + { + var samplePacked = ResourceLoader.Load(samplePath); + var sample = samplePacked.Instantiate(); + GetTree().Root.CallDeferred("add_child", sample); + QueueFree(); + } - /// - /// Return to the entry point - /// - public static void Return() - { - var root = ((SceneTree) Engine.GetMainLoop()).Root; - var nodesToFree = new List(); - for (var i = 0; i < root.GetChildCount(); i++) - { - nodesToFree.Add(root.GetChild(i)); - } + /// + /// Return to the entry point + /// + public static void Return() + { + var root = ((SceneTree) Engine.GetMainLoop()).Root; + var nodesToFree = new List(); + for (var i = 0; i < root.GetChildCount(); i++) + { + nodesToFree.Add(root.GetChild(i)); + } - foreach (var node in nodesToFree) - { - node.QueueFree(); - } + foreach (var node in nodesToFree) + { + node.QueueFree(); + } - var loadResult = root.GetTree().ChangeSceneToFile(ENTRY_POINT_PATH); - if (loadResult != Error.Ok) - { - GD.PushError($"Failed to load the sample entry point: {loadResult}"); - } - } -} + var loadResult = root.GetTree().ChangeSceneToFile(ENTRY_POINT_PATH); + if (loadResult != Error.Ok) + { + GD.PushError($"Failed to load the sample entry point: {loadResult}"); + } + } +} \ No newline at end of file diff --git a/Samples/SampleEntryPoint.tscn b/Samples/SampleEntryPoint.tscn index 86211e7..af34a56 100644 --- a/Samples/SampleEntryPoint.tscn +++ b/Samples/SampleEntryPoint.tscn @@ -4,13 +4,14 @@ [ext_resource type="Theme" uid="uid://b2mp0b1wvnu8s" path="res://Samples/sample_default_theme.tres" id="2"] [ext_resource type="Texture2D" uid="uid://pbrr5yyepbx8" path="res://addons/YarnSpinner-Godot/Editor/Icons/YarnSpinnerLogo.png" id="3_bcudv"] -[node name="SampleEntryPoint" type="CanvasLayer" node_paths=PackedStringArray("_spaceButton", "_visualNovelButton", "_markupPaletteButton", "_pausingTypewriterButton", "_roundedViewsButton")] +[node name="SampleEntryPoint" type="CanvasLayer" node_paths=PackedStringArray("_spaceButton", "_visualNovelButton", "_markupPaletteButton", "_pausingTypewriterButton", "_roundedViewsButton", "_sqliteButton")] script = ExtResource("1") _spaceButton = NodePath("HBoxContainer/VBoxContainer/Space") _visualNovelButton = NodePath("HBoxContainer/VBoxContainer2/Visual Novel") _markupPaletteButton = NodePath("HBoxContainer/VBoxContainer3/MarkupPalette") _pausingTypewriterButton = NodePath("HBoxContainer/VBoxContainer4/PausingTypewriter") _roundedViewsButton = NodePath("HBoxContainer/VBoxContainer5/RoundedViews") +_sqliteButton = NodePath("HBoxContainer/VBoxContainer6/SQLite") [node name="ColorRect" type="ColorRect" parent="."] anchors_preset = 15 @@ -165,3 +166,25 @@ theme_override_font_sizes/normal_font_size = 28 bbcode_enabled = true text = "Alternate dialogue UI style" scroll_active = false + +[node name="VBoxContainer6" type="VBoxContainer" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="SQLite" type="Button" parent="HBoxContainer/VBoxContainer6"] +custom_minimum_size = Vector2(180, 100) +layout_mode = 2 +theme = ExtResource("2") +theme_override_colors/font_outline_color = Color(0, 0, 0, 1) +theme_override_constants/outline_size = 5 +theme_override_font_sizes/font_size = 27 +text = "SQLite Variable +Storage" + +[node name="features" type="RichTextLabel" parent="HBoxContainer/VBoxContainer6"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_font_sizes/normal_font_size = 28 +bbcode_enabled = true +text = "Custom variable storage script that saves variables in a SQLite database" +scroll_active = false diff --git a/YarnSpinner-Godot.csproj b/YarnSpinner-Godot.csproj index 71c403c..92a2616 100644 --- a/YarnSpinner-Godot.csproj +++ b/YarnSpinner-Godot.csproj @@ -1,4 +1,4 @@ - + net6.0 true @@ -11,6 +11,7 @@ + diff --git a/addons/YarnSpinner-Godot/Editor/YarnCompileErrorsPropertyEditor.cs b/addons/YarnSpinner-Godot/Editor/YarnCompileErrorsPropertyEditor.cs index fb196f4..df0b23d 100644 --- a/addons/YarnSpinner-Godot/Editor/YarnCompileErrorsPropertyEditor.cs +++ b/addons/YarnSpinner-Godot/Editor/YarnCompileErrorsPropertyEditor.cs @@ -56,7 +56,7 @@ private void RefreshControlText() else { _propertyControl.Text = - $"{_currentValue.Count} error{(_currentValue.Count > 1 ? "s" : "")}"; + $"❌{_currentValue.Count} error{(_currentValue.Count > 1 ? "s" : "")}"; } } diff --git a/addons/YarnSpinner-Godot/Scenes/OptionView.tscn b/addons/YarnSpinner-Godot/Scenes/OptionView.tscn index 803e81f..b831b56 100644 --- a/addons/YarnSpinner-Godot/Scenes/OptionView.tscn +++ b/addons/YarnSpinner-Godot/Scenes/OptionView.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://addons/YarnSpinner-Godot/Runtime/Views/OptionView.cs" id="1"] [node name="OptionView" type="Button" node_paths=PackedStringArray("label")] -custom_minimum_size = Vector2(0, 32) +custom_minimum_size = Vector2(0, 26) anchors_preset = 7 anchor_left = 0.5 anchor_top = 1.0 diff --git a/addons/YarnSpinner-Godot/Scenes/RoundedDialogueSystem.tscn b/addons/YarnSpinner-Godot/Scenes/RoundedDialogueSystem.tscn index 3e20739..21bbd5c 100644 --- a/addons/YarnSpinner-Godot/Scenes/RoundedDialogueSystem.tscn +++ b/addons/YarnSpinner-Godot/Scenes/RoundedDialogueSystem.tscn @@ -202,9 +202,9 @@ anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 offset_left = -597.0 -offset_top = -164.0 +offset_top = -108.0 offset_right = 496.0 -offset_bottom = 324.0 +offset_bottom = 380.0 grow_horizontal = 2 grow_vertical = 2 From 195ad261e35d7162359919dc4774097dc18fd313 Mon Sep 17 00:00:00 2001 From: dogboydog Date: Sat, 27 Apr 2024 11:00:56 -0400 Subject: [PATCH 3/3] update Samples.md for SQLite variable storage --- docs/Samples.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/Samples.md b/docs/Samples.md index 19a234e..846aa5c 100644 --- a/docs/Samples.md +++ b/docs/Samples.md @@ -66,6 +66,12 @@ You can create your own MarkupPalette with Project -> Tools -> YarnSpinner -> Cr https://github.com/YarnSpinnerTool/YarnSpinner-Godot/assets/9920963/cb7573ff-8cf2-4de9-b85c-99647a6c5cf0 +# SQLite Variable Storage + +This example shows how to write a custom variable storage class. In this case, variables are read and written to a SQLite +database file on the player's machine. This sample uses the `sqlite-net-pcl` package as a dependency. + + ## ASSET CREDITS The assets included in this example project are: