From 8330ae2ea5a06f26e9aedb9d579717ac3885d20f Mon Sep 17 00:00:00 2001 From: kesac Date: Mon, 10 Jun 2024 20:05:38 -0600 Subject: [PATCH] Added a simple visual of generated names flying in an empty 2D space --- .gitignore | 1 + .../Syllabore.Visualizer/MainVisualizer.cs | 42 +++++++++++++++++++ .../Syllabore.Visualizer/MainVisualizer.tscn | 16 ++++++- Syllabore/Syllabore.Visualizer/NameFloater.cs | 32 ++++++++++++++ .../Syllabore.Visualizer/NameFloater.tscn | 15 +++++++ .../Syllabore.Visualizer.csproj | 3 ++ Syllabore/Syllabore.Visualizer/project.godot | 6 ++- 7 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 Syllabore/Syllabore.Visualizer/NameFloater.cs create mode 100644 Syllabore/Syllabore.Visualizer/NameFloater.tscn diff --git a/.gitignore b/.gitignore index 94de160..5c21262 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ /Syllabore/Syllabore.Tests/bin/Release/net8.0 /Syllabore/Syllabore.Visualizer/.godot /Syllabore/Syllabore.Visualizer/.vs/SYLLABORE.VISUALIZER +/Syllabore/Syllabore.Visualizer/.vs/ProjectEvaluation diff --git a/Syllabore/Syllabore.Visualizer/MainVisualizer.cs b/Syllabore/Syllabore.Visualizer/MainVisualizer.cs index 64d5c3e..12d4668 100644 --- a/Syllabore/Syllabore.Visualizer/MainVisualizer.cs +++ b/Syllabore/Syllabore.Visualizer/MainVisualizer.cs @@ -1,6 +1,48 @@ using Godot; +using Syllabore; using System; public partial class MainVisualizer : Node2D { + private NameGenerator _nameGenerator; + private PackedScene _nameFloaterScene; + + private int _speed = 100; + private Random _random = new Random(); + private int _xPadding = 100; + + public override void _Ready() + { + _nameGenerator = new NameGenerator("ae","strl"); + _nameFloaterScene = GD.Load("res://NameFloater.tscn"); + } + + public override void _Process(double delta) + { + + } + + public void GenerateName() + { + + var windowSize = GetViewportRect().Size; + + var xRoundTo = 50; + var yRoundTo = 20; + + var xPosition = _xPadding + _random.Next((int)windowSize.X - (2 * _xPadding)); + xPosition = (xPosition / xRoundTo) * xRoundTo; // Round to nearest 50 + + var yPosition = (int)windowSize.Y; + yPosition = (yPosition / yRoundTo) * yRoundTo; + + var instance = (NameFloater)_nameFloaterScene.Instantiate(); + + instance.Text = _nameGenerator.Next(); + instance.Speed = 100; + instance.Position = new Vector2(xPosition, yPosition); + + this.GetTree().CurrentScene.AddChild(instance); + } + } diff --git a/Syllabore/Syllabore.Visualizer/MainVisualizer.tscn b/Syllabore/Syllabore.Visualizer/MainVisualizer.tscn index 6fbdcb4..5779236 100644 --- a/Syllabore/Syllabore.Visualizer/MainVisualizer.tscn +++ b/Syllabore/Syllabore.Visualizer/MainVisualizer.tscn @@ -1,3 +1,17 @@ -[gd_scene format=3 uid="uid://dvet30uohxhwh"] +[gd_scene load_steps=2 format=3 uid="uid://dvet30uohxhwh"] + +[ext_resource type="Script" path="res://MainVisualizer.cs" id="1_42c8l"] [node name="MainVisualizer" type="Node2D"] +script = ExtResource("1_42c8l") + +[node name="ColorRect" type="ColorRect" parent="."] +offset_right = 1159.0 +offset_bottom = 651.0 +color = Color(0, 0, 0, 1) + +[node name="GenerateNamesTimer" type="Timer" parent="."] +wait_time = 0.5 +autostart = true + +[connection signal="timeout" from="GenerateNamesTimer" to="." method="GenerateName"] diff --git a/Syllabore/Syllabore.Visualizer/NameFloater.cs b/Syllabore/Syllabore.Visualizer/NameFloater.cs new file mode 100644 index 0000000..872fd6b --- /dev/null +++ b/Syllabore/Syllabore.Visualizer/NameFloater.cs @@ -0,0 +1,32 @@ +using Godot; +using System; + +public partial class NameFloater : Node2D +{ + [Export] + public int Speed = 10; + + public string Text { + get + { + return this.GetNode