Skip to content

Commit 8330ae2

Browse files
committed
Added a simple visual of generated names flying in an empty 2D space
1 parent da82b76 commit 8330ae2

File tree

7 files changed

+113
-2
lines changed

7 files changed

+113
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@
3535
/Syllabore/Syllabore.Tests/bin/Release/net8.0
3636
/Syllabore/Syllabore.Visualizer/.godot
3737
/Syllabore/Syllabore.Visualizer/.vs/SYLLABORE.VISUALIZER
38+
/Syllabore/Syllabore.Visualizer/.vs/ProjectEvaluation
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,48 @@
11
using Godot;
2+
using Syllabore;
23
using System;
34

45
public partial class MainVisualizer : Node2D
56
{
7+
private NameGenerator _nameGenerator;
8+
private PackedScene _nameFloaterScene;
9+
10+
private int _speed = 100;
11+
private Random _random = new Random();
12+
private int _xPadding = 100;
13+
14+
public override void _Ready()
15+
{
16+
_nameGenerator = new NameGenerator("ae","strl");
17+
_nameFloaterScene = GD.Load<PackedScene>("res://NameFloater.tscn");
18+
}
19+
20+
public override void _Process(double delta)
21+
{
22+
23+
}
24+
25+
public void GenerateName()
26+
{
27+
28+
var windowSize = GetViewportRect().Size;
29+
30+
var xRoundTo = 50;
31+
var yRoundTo = 20;
32+
33+
var xPosition = _xPadding + _random.Next((int)windowSize.X - (2 * _xPadding));
34+
xPosition = (xPosition / xRoundTo) * xRoundTo; // Round to nearest 50
35+
36+
var yPosition = (int)windowSize.Y;
37+
yPosition = (yPosition / yRoundTo) * yRoundTo;
38+
39+
var instance = (NameFloater)_nameFloaterScene.Instantiate();
40+
41+
instance.Text = _nameGenerator.Next();
42+
instance.Speed = 100;
43+
instance.Position = new Vector2(xPosition, yPosition);
44+
45+
this.GetTree().CurrentScene.AddChild(instance);
46+
}
47+
648
}
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
[gd_scene format=3 uid="uid://dvet30uohxhwh"]
1+
[gd_scene load_steps=2 format=3 uid="uid://dvet30uohxhwh"]
2+
3+
[ext_resource type="Script" path="res://MainVisualizer.cs" id="1_42c8l"]
24

35
[node name="MainVisualizer" type="Node2D"]
6+
script = ExtResource("1_42c8l")
7+
8+
[node name="ColorRect" type="ColorRect" parent="."]
9+
offset_right = 1159.0
10+
offset_bottom = 651.0
11+
color = Color(0, 0, 0, 1)
12+
13+
[node name="GenerateNamesTimer" type="Timer" parent="."]
14+
wait_time = 0.5
15+
autostart = true
16+
17+
[connection signal="timeout" from="GenerateNamesTimer" to="." method="GenerateName"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Godot;
2+
using System;
3+
4+
public partial class NameFloater : Node2D
5+
{
6+
[Export]
7+
public int Speed = 10;
8+
9+
public string Text {
10+
get
11+
{
12+
return this.GetNode<Label>("NameLabel").Text;
13+
}
14+
set
15+
{
16+
this.GetNode<Label>("NameLabel").Text = value;
17+
}
18+
}
19+
20+
public override void _Process(double delta)
21+
{
22+
if (this.Position.Y < -20)
23+
{
24+
this.QueueFree();
25+
}
26+
else
27+
{
28+
this.Position += Vector2.Up * Speed * (float)delta;
29+
}
30+
}
31+
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://b8sdde54fk5v8"]
2+
3+
[ext_resource type="Script" path="res://NameFloater.cs" id="1_qwpa5"]
4+
5+
[sub_resource type="LabelSettings" id="LabelSettings_6ep6f"]
6+
font_size = 26
7+
8+
[node name="NameFloater" type="Node2D"]
9+
script = ExtResource("1_qwpa5")
10+
11+
[node name="NameLabel" type="Label" parent="."]
12+
offset_right = 40.0
13+
offset_bottom = 23.0
14+
text = "Name"
15+
label_settings = SubResource("LabelSettings_6ep6f")

Syllabore/Syllabore.Visualizer/Syllabore.Visualizer.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
66
<EnableDynamicLoading>true</EnableDynamicLoading>
77
</PropertyGroup>
8+
<ItemGroup>
9+
<PackageReference Include="Syllabore" Version="2.3.3" />
10+
</ItemGroup>
811
</Project>

Syllabore/Syllabore.Visualizer/project.godot

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ config_version=5
1212

1313
config/name="Syllabore.Visualizer"
1414
run/main_scene="res://MainVisualizer.tscn"
15-
config/features=PackedStringArray("4.2", "GL Compatibility")
15+
config/features=PackedStringArray("4.2", "C#", "GL Compatibility")
1616
config/icon="res://icon.svg"
1717

18+
[display]
19+
20+
window/stretch/mode="canvas_items"
21+
1822
[dotnet]
1923

2024
project/assembly_name="Syllabore.Visualizer"

0 commit comments

Comments
 (0)