From c4a579f94bc00ff1900d18cd27cf7207dbdd6b99 Mon Sep 17 00:00:00 2001 From: kesac Date: Tue, 11 Jun 2024 21:46:41 -0600 Subject: [PATCH] Setup basic visualization of continually generated names floating through 2D space --- .../Syllabore.Visualizer/MainVisualizer.cs | 120 +++++++++++++++--- .../Syllabore.Visualizer/MainVisualizer.tscn | 88 ++++++++++++- Syllabore/Syllabore.Visualizer/NameFloater.cs | 49 ++++++- .../Syllabore.Visualizer/NameFloater.tscn | 7 +- 4 files changed, 236 insertions(+), 28 deletions(-) diff --git a/Syllabore/Syllabore.Visualizer/MainVisualizer.cs b/Syllabore/Syllabore.Visualizer/MainVisualizer.cs index 12d4668..acaccbc 100644 --- a/Syllabore/Syllabore.Visualizer/MainVisualizer.cs +++ b/Syllabore/Syllabore.Visualizer/MainVisualizer.cs @@ -1,20 +1,79 @@ using Godot; using Syllabore; using System; +using System.Data; +using System.Linq; +using System.Collections; +using System.Collections.Generic; +using Syllabore.Visualizer; +using static Godot.Control; -public partial class MainVisualizer : Node2D +public partial class MainVisualizer : Node2D, ITemporalController { + private static readonly string DefaultVowels = "ae"; + private static readonly string DefaultLeadingConsonants = "str"; + private static readonly string DefaultTrailingConsonants = "lmn"; + + private SyllableGenerator _syllableGenerator; private NameGenerator _nameGenerator; private PackedScene _nameFloaterScene; - private int _speed = 100; private Random _random = new Random(); - private int _xPadding = 100; + private int _xLeftPadding = 300; // Make room for the menu stuff + private int _xRightPadding = 100; // Ensure names fit + + public bool IsSlowed { get; set; } + public bool IsPaused { get; set; } public override void _Ready() { - _nameGenerator = new NameGenerator("ae","strl"); + _syllableGenerator = new SyllableGenerator() + .WithVowels(DefaultVowels) + .WithLeadingConsonants(DefaultLeadingConsonants) + .WithTrailingConsonants(DefaultTrailingConsonants); + + _nameGenerator = new NameGenerator(_syllableGenerator).UsingSyllableCount(2, 3); _nameFloaterScene = GD.Load("res://NameFloater.tscn"); + + this.RefreshEditorTextValues(); + } + + public void RefreshEditorTextValues() + { + + var vowels = string.Join(string.Empty, _syllableGenerator.Vowels.Select(x => x.Value)); + var leadingConsonants = string.Join(string.Empty, _syllableGenerator.LeadingConsonants.Select(x => x.Value)); + var trailingConsonants = string.Join(string.Empty, _syllableGenerator.TrailingConsonants.Select(x => x.Value)); + + this.GetNode("Editor/Vowels").Text = vowels; + this.GetNode("Editor/LeadingConsonants").Text = leadingConsonants; + this.GetNode("Editor/TrailingConsonants").Text = trailingConsonants; + + this.RefreshShiftingLabels(); + + } + + public void RefreshSyllableGenerator() + { + var vowels = this.GetNode("Editor/Vowels").Text; + var leadingConsonants = this.GetNode("Editor/LeadingConsonants").Text; + var trailingConsonants = this.GetNode("Editor/TrailingConsonants").Text; + + _syllableGenerator = new SyllableGenerator() + .WithVowels(vowels) + .WithLeadingConsonants(leadingConsonants) + .WithTrailingConsonants(trailingConsonants); + + _nameGenerator = new NameGenerator(_syllableGenerator).UsingSyllableCount(2, 3); + + this.RefreshShiftingLabels(); + } + + public void RefreshShiftingLabels() + { + this.GetNode("Editor/VowelLabel").Values = _syllableGenerator.Vowels.Select(x => x.Value).ToList(); + this.GetNode("Editor/LeadingConsonantLabel").Values = _syllableGenerator.LeadingConsonants.Select(x => x.Value).ToList(); + this.GetNode("Editor/TrailingConsonantLabel").Values = _syllableGenerator.TrailingConsonants.Select(x => x.Value).ToList(); } public override void _Process(double delta) @@ -22,27 +81,56 @@ public override void _Process(double delta) } + public void PauseFloaters() + { + this.IsPaused = true; + this.IsSlowed = false; + } + + public void SlowDownFloaters() + { + this.IsPaused = false; + this.IsSlowed = true; + } + + public void ResumeFloaters() + { + this.IsSlowed = false; + this.IsPaused = false; + } + public void GenerateName() { + if (!this.IsPaused && !this.IsSlowed && _syllableGenerator.Vowels.Count > 0) + { + var windowSize = GetViewportRect().Size; + + var xRoundTo = 20; + var yRoundTo = 20; + + var xPosition = _xLeftPadding + _random.Next((int)windowSize.X - (_xLeftPadding + _xRightPadding)); + xPosition = (xPosition / xRoundTo) * xRoundTo; // Round to nearest 50 - var windowSize = GetViewportRect().Size; + //var yPosition = (int)windowSize.Y; + var yPosition = -20; // Start off screen + yPosition = (yPosition / yRoundTo) * yRoundTo; - var xRoundTo = 50; - var yRoundTo = 20; + var instance = (NameFloater)_nameFloaterScene.Instantiate(); - var xPosition = _xPadding + _random.Next((int)windowSize.X - (2 * _xPadding)); - xPosition = (xPosition / xRoundTo) * xRoundTo; // Round to nearest 50 + instance.SetTemporalController(this); - var yPosition = (int)windowSize.Y; - yPosition = (yPosition / yRoundTo) * yRoundTo; + instance.Text = _nameGenerator.Next(); - var instance = (NameFloater)_nameFloaterScene.Instantiate(); + instance.Speed = 100; // Base speed only; the instance will adjust itself based on the TemporalController's state + instance.Position = new Vector2(xPosition, yPosition); - instance.Text = _nameGenerator.Next(); - instance.Speed = 100; - instance.Position = new Vector2(xPosition, yPosition); + //connect instance label to the the MainVisualizer's PauseFloater method + var nameLabel = instance.GetNode