-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup basic visualization of continually generated names floating thr…
…ough 2D space
- Loading branch information
Showing
4 changed files
with
236 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,136 @@ | ||
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<PackedScene>("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<TextEdit>("Editor/Vowels").Text = vowels; | ||
this.GetNode<TextEdit>("Editor/LeadingConsonants").Text = leadingConsonants; | ||
this.GetNode<TextEdit>("Editor/TrailingConsonants").Text = trailingConsonants; | ||
|
||
this.RefreshShiftingLabels(); | ||
|
||
} | ||
|
||
public void RefreshSyllableGenerator() | ||
{ | ||
var vowels = this.GetNode<TextEdit>("Editor/Vowels").Text; | ||
var leadingConsonants = this.GetNode<TextEdit>("Editor/LeadingConsonants").Text; | ||
var trailingConsonants = this.GetNode<TextEdit>("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<ShiftingLabel>("Editor/VowelLabel").Values = _syllableGenerator.Vowels.Select(x => x.Value).ToList(); | ||
this.GetNode<ShiftingLabel>("Editor/LeadingConsonantLabel").Values = _syllableGenerator.LeadingConsonants.Select(x => x.Value).ToList(); | ||
this.GetNode<ShiftingLabel>("Editor/TrailingConsonantLabel").Values = _syllableGenerator.TrailingConsonants.Select(x => x.Value).ToList(); | ||
} | ||
|
||
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<Label>("NameLabel"); | ||
nameLabel.MouseEntered += this.SlowDownFloaters; | ||
nameLabel.MouseExited += this.ResumeFloaters; | ||
|
||
this.GetTree().CurrentScene.AddChild(instance); | ||
this.GetTree().CurrentScene.AddChild(instance); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,97 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://dvet30uohxhwh"] | ||
[gd_scene load_steps=4 format=3 uid="uid://dvet30uohxhwh"] | ||
|
||
[ext_resource type="Script" path="res://MainVisualizer.cs" id="1_42c8l"] | ||
[ext_resource type="PackedScene" uid="uid://cr4njnftd3faq" path="res://ShiftingLabel.tscn" id="2_dyjlh"] | ||
|
||
[sub_resource type="LabelSettings" id="LabelSettings_sy3ib"] | ||
font_size = 35 | ||
|
||
[node name="MainVisualizer" type="Node2D"] | ||
script = ExtResource("1_42c8l") | ||
|
||
[node name="ColorRect" type="ColorRect" parent="."] | ||
offset_right = 1159.0 | ||
offset_bottom = 651.0 | ||
[node name="BlackBackground" type="ColorRect" parent="."] | ||
show_behind_parent = true | ||
offset_right = 1200.0 | ||
offset_bottom = 800.0 | ||
color = Color(0, 0, 0, 1) | ||
|
||
[node name="GenerateNamesTimer" type="Timer" parent="."] | ||
wait_time = 0.5 | ||
autostart = true | ||
|
||
[node name="Editor" type="Panel" parent="."] | ||
anchors_preset = 4 | ||
anchor_top = 0.5 | ||
anchor_bottom = 0.5 | ||
offset_left = 13.0 | ||
offset_top = 17.0 | ||
offset_right = 282.0 | ||
offset_bottom = 770.0 | ||
grow_vertical = 2 | ||
|
||
[node name="SyllaboreLabel" type="Label" parent="Editor"] | ||
layout_mode = 0 | ||
offset_left = 5.0 | ||
offset_top = 5.0 | ||
offset_right = 261.0 | ||
offset_bottom = 66.0 | ||
text = "Syllabore" | ||
label_settings = SubResource("LabelSettings_sy3ib") | ||
horizontal_alignment = 1 | ||
vertical_alignment = 1 | ||
|
||
[node name="VowelLabel" parent="Editor" instance=ExtResource("2_dyjlh")] | ||
layout_mode = 0 | ||
offset_left = 104.0 | ||
offset_top = 76.0 | ||
offset_right = 169.0 | ||
offset_bottom = 136.0 | ||
text = "A" | ||
|
||
[node name="LeadingConsonantLabel" parent="Editor" instance=ExtResource("2_dyjlh")] | ||
layout_mode = 0 | ||
offset_left = 29.0 | ||
offset_top = 72.0 | ||
offset_right = 88.0 | ||
offset_bottom = 135.0 | ||
text = "C" | ||
|
||
[node name="TrailingConsonantLabel" parent="Editor" instance=ExtResource("2_dyjlh")] | ||
layout_mode = 0 | ||
offset_left = 189.0 | ||
offset_top = 78.0 | ||
offset_right = 247.0 | ||
offset_bottom = 134.0 | ||
text = "T" | ||
|
||
[node name="Vowels" type="TextEdit" parent="Editor"] | ||
custom_minimum_size = Vector2(75, 0) | ||
layout_mode = 0 | ||
offset_left = 99.0 | ||
offset_top = 139.0 | ||
offset_right = 174.0 | ||
offset_bottom = 175.0 | ||
placeholder_text = "Vowels" | ||
|
||
[node name="LeadingConsonants" type="TextEdit" parent="Editor"] | ||
custom_minimum_size = Vector2(75, 0) | ||
layout_mode = 0 | ||
offset_left = 19.0 | ||
offset_top = 139.0 | ||
offset_right = 94.0 | ||
offset_bottom = 176.0 | ||
placeholder_text = "Leading" | ||
|
||
[node name="TrailingConsonants" type="TextEdit" parent="Editor"] | ||
custom_minimum_size = Vector2(75, 0) | ||
layout_mode = 0 | ||
offset_left = 179.0 | ||
offset_top = 139.0 | ||
offset_right = 254.0 | ||
offset_bottom = 174.0 | ||
placeholder_text = "Trailing" | ||
|
||
[connection signal="timeout" from="GenerateNamesTimer" to="." method="GenerateName"] | ||
[connection signal="text_changed" from="Editor/Vowels" to="." method="RefreshSyllableGenerator"] | ||
[connection signal="text_changed" from="Editor/LeadingConsonants" to="." method="RefreshSyllableGenerator"] | ||
[connection signal="text_changed" from="Editor/TrailingConsonants" to="." method="RefreshSyllableGenerator"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters