Skip to content

Commit

Permalink
Added a simple visual of generated names flying in an empty 2D space
Browse files Browse the repository at this point in the history
  • Loading branch information
kesac committed Jun 11, 2024
1 parent da82b76 commit 8330ae2
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 42 additions & 0 deletions Syllabore/Syllabore.Visualizer/MainVisualizer.cs
Original file line number Diff line number Diff line change
@@ -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<PackedScene>("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);
}

}
16 changes: 15 additions & 1 deletion Syllabore/Syllabore.Visualizer/MainVisualizer.tscn
Original file line number Diff line number Diff line change
@@ -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"]
32 changes: 32 additions & 0 deletions Syllabore/Syllabore.Visualizer/NameFloater.cs
Original file line number Diff line number Diff line change
@@ -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<Label>("NameLabel").Text;
}
set
{
this.GetNode<Label>("NameLabel").Text = value;
}
}

public override void _Process(double delta)
{
if (this.Position.Y < -20)
{
this.QueueFree();
}
else
{
this.Position += Vector2.Up * Speed * (float)delta;
}
}

}
15 changes: 15 additions & 0 deletions Syllabore/Syllabore.Visualizer/NameFloater.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[gd_scene load_steps=3 format=3 uid="uid://b8sdde54fk5v8"]

[ext_resource type="Script" path="res://NameFloater.cs" id="1_qwpa5"]

[sub_resource type="LabelSettings" id="LabelSettings_6ep6f"]
font_size = 26

[node name="NameFloater" type="Node2D"]
script = ExtResource("1_qwpa5")

[node name="NameLabel" type="Label" parent="."]
offset_right = 40.0
offset_bottom = 23.0
text = "Name"
label_settings = SubResource("LabelSettings_6ep6f")
3 changes: 3 additions & 0 deletions Syllabore/Syllabore.Visualizer/Syllabore.Visualizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Syllabore" Version="2.3.3" />
</ItemGroup>
</Project>
6 changes: 5 additions & 1 deletion Syllabore/Syllabore.Visualizer/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ config_version=5

config/name="Syllabore.Visualizer"
run/main_scene="res://MainVisualizer.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/features=PackedStringArray("4.2", "C#", "GL Compatibility")
config/icon="res://icon.svg"

[display]

window/stretch/mode="canvas_items"

[dotnet]

project/assembly_name="Syllabore.Visualizer"
Expand Down

0 comments on commit 8330ae2

Please sign in to comment.