decisions decisions decisions
This commit is contained in:
57
src/Gameplay/Nodules/Components/GrowArea.cs
Normal file
57
src/Gameplay/Nodules/Components/GrowArea.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Godot;
|
||||
using Slimepire.Core;
|
||||
|
||||
namespace Slimepire.Gameplay.Nodules.Components;
|
||||
|
||||
[SceneTree]
|
||||
public partial class GrowArea : Area2D
|
||||
{
|
||||
private bool _mouseInsideClickArea;
|
||||
private bool _clickedInside;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
MouseEntered += ClickAreaOnMouseEntered;
|
||||
MouseExited += ClickAreaOnMouseExited;
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseEntered()
|
||||
{
|
||||
_mouseInsideClickArea = true;
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseExited()
|
||||
{
|
||||
_mouseInsideClickArea = false;
|
||||
|
||||
// ghost == null check probably unnecessary
|
||||
if (_clickedInside && !NoduleManager.Instance.Building)
|
||||
{
|
||||
NoduleManager.Instance.Building = true;
|
||||
_clickedInside = false;
|
||||
|
||||
var ghost = Instantiator.Instantiate<BuildGhost>();
|
||||
ghost.Position = Position;
|
||||
|
||||
// TODO: Make it better... EntityRoot oder vllt. NoduleRoot
|
||||
// Oder einfach den Baum auch als Baum in der Scene darstellen?
|
||||
GetTree().Root.AddChild(ghost);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
using (@event)
|
||||
{
|
||||
if (
|
||||
@event is InputEventMouseButton { ButtonIndex: MouseButton.Left }
|
||||
&& @event.IsPressed()
|
||||
&& _mouseInsideClickArea
|
||||
)
|
||||
{
|
||||
_clickedInside = true;
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
src/Gameplay/Nodules/Components/GrowArea.cs.uid
Normal file
1
src/Gameplay/Nodules/Components/GrowArea.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cfxb8wmnt7ej7
|
||||
13
src/Gameplay/Nodules/Components/GrowArea.tscn
Normal file
13
src/Gameplay/Nodules/Components/GrowArea.tscn
Normal file
@@ -0,0 +1,13 @@
|
||||
[gd_scene format=3 uid="uid://3x5pqm4t5cbl"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cfxb8wmnt7ej7" path="res://src/Gameplay/Nodules/Components/GrowArea.cs" id="1_a3tcn"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_7qt20"]
|
||||
radius = 15.0
|
||||
|
||||
[node name="GrowArea" type="Area2D" unique_id=979341496]
|
||||
monitorable = false
|
||||
script = ExtResource("1_a3tcn")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1616623898]
|
||||
shape = SubResource("CircleShape2D_7qt20")
|
||||
31
src/Gameplay/Nodules/Components/TubeConnectionArea.cs
Normal file
31
src/Gameplay/Nodules/Components/TubeConnectionArea.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Godot;
|
||||
|
||||
namespace Slimepire.Gameplay.Nodules.Components;
|
||||
|
||||
public partial class TubeConnectionArea : Area2D
|
||||
{
|
||||
public Action<Nodule> ConnectionAdded { get; set; }
|
||||
public Action<Nodule> ConnectionRemoved { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AreaEntered += TubeConnectionAreaOnAreaEntered;
|
||||
AreaExited += TubeConnectionAreaOnAreaExited;
|
||||
}
|
||||
|
||||
private void TubeConnectionAreaOnAreaEntered(Area2D area)
|
||||
{
|
||||
if (area.GetParent() is Nodule nodule)
|
||||
{
|
||||
ConnectionAdded?.Invoke(nodule);
|
||||
}
|
||||
}
|
||||
|
||||
private void TubeConnectionAreaOnAreaExited(Area2D area)
|
||||
{
|
||||
if (area.GetParent() is Nodule nodule)
|
||||
{
|
||||
ConnectionRemoved?.Invoke(nodule);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bcw8vylpb533h
|
||||
15
src/Gameplay/Nodules/Components/TubeConnectionArea.tscn
Normal file
15
src/Gameplay/Nodules/Components/TubeConnectionArea.tscn
Normal file
@@ -0,0 +1,15 @@
|
||||
[gd_scene format=3 uid="uid://bjesfu1mfx8l5"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bcw8vylpb533h" path="res://src/Gameplay/Nodules/Components/TubeConnectionArea.cs" id="1_uhdst"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_x44k2"]
|
||||
radius = 96.38
|
||||
|
||||
[node name="TubeConnectionArea" type="Area2D" unique_id=1821668398]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_uhdst")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=301201606]
|
||||
shape = SubResource("CircleShape2D_x44k2")
|
||||
debug_color = Color(0.38922516, 0.6054754, 0.25354394, 0.41960785)
|
||||
@@ -1,5 +1,5 @@
|
||||
using Godot;
|
||||
using Slimepire.Data;
|
||||
using Slimepire.Gameplay.Nodules.Components;
|
||||
|
||||
namespace Slimepire.Gameplay.Nodules;
|
||||
|
||||
@@ -8,105 +8,31 @@ public partial class Nodule : Node2D
|
||||
{
|
||||
public long Id { get; set; } = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||
|
||||
private bool _mouseInsideClickArea;
|
||||
private bool _clickedInside;
|
||||
|
||||
public readonly List<Nodule> Connections = [];
|
||||
public List<Nodule> Connections { get; } = [];
|
||||
|
||||
[Export]
|
||||
public required NoduleResource NoduleResource;
|
||||
|
||||
private float energy = 0;
|
||||
|
||||
// todo remove?
|
||||
private bool _isExpanding;
|
||||
private TubeConnectionArea _tubeConnectionArea;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Gfx.SpriteFrames = NoduleResource.SpriteFrames;
|
||||
Gfx.SelfModulate = NoduleResource.Color;
|
||||
Gfx.SelfModulate = Colors.DarkOliveGreen;
|
||||
Gfx.Play();
|
||||
|
||||
ClickArea.MouseEntered += ClickAreaOnMouseEntered;
|
||||
ClickArea.MouseExited += ClickAreaOnMouseExited;
|
||||
|
||||
TubeConnectionArea.AreaEntered += TubeConnectionAreaOnAreaEntered;
|
||||
TubeConnectionArea.AreaExited += TubeConnectionAreaOnAreaExited;
|
||||
_tubeConnectionArea.ConnectionAdded += ConnectionAdded;
|
||||
_tubeConnectionArea.ConnectionRemoved += ConnectionRemoved;
|
||||
|
||||
NoduleManager.Instance.RegisterNodule(this);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
private void ConnectionAdded(Nodule nodule)
|
||||
{
|
||||
EnergyLabel.Text = energy.ToString("F2");
|
||||
}
|
||||
|
||||
private void TubeConnectionAreaOnAreaEntered(Area2D area)
|
||||
{
|
||||
if (area.GetParent() is Nodule nodule)
|
||||
{
|
||||
Connections.Add(nodule);
|
||||
NoduleManager.Instance.Update();
|
||||
}
|
||||
}
|
||||
|
||||
private void TubeConnectionAreaOnAreaExited(Area2D area)
|
||||
{
|
||||
if (area.GetParent() is Nodule nodule)
|
||||
{
|
||||
Connections.Remove(nodule);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
using (@event)
|
||||
{
|
||||
if (
|
||||
@event is InputEventMouseButton { ButtonIndex: MouseButton.Left }
|
||||
&& @event.IsPressed()
|
||||
&& _mouseInsideClickArea
|
||||
)
|
||||
{
|
||||
_clickedInside = true;
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseEntered()
|
||||
{
|
||||
_mouseInsideClickArea = true;
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseExited()
|
||||
{
|
||||
_mouseInsideClickArea = false;
|
||||
|
||||
// ghost == null check probably unnecessary
|
||||
if (_clickedInside && !NoduleManager.Instance.Building)
|
||||
{
|
||||
NoduleManager.Instance.Building = true;
|
||||
_clickedInside = false;
|
||||
_isExpanding = true;
|
||||
|
||||
var ghost = Instantiator.Instantiate<BuildGhost>();
|
||||
ghost.Position = Position;
|
||||
|
||||
GetParent()?.AddChild(ghost);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBuildComplete(Vector2 pos)
|
||||
{
|
||||
NoduleManager.Instance.Building = false;
|
||||
_isExpanding = false;
|
||||
|
||||
var nodule = Instantiator.Instantiate<Nodule>();
|
||||
|
||||
nodule.Position = pos;
|
||||
Connections.Add(nodule);
|
||||
nodule.Connections.Add(this);
|
||||
GetParent()?.AddChild(nodule);
|
||||
NoduleManager.Instance.Update();
|
||||
}
|
||||
|
||||
private void ConnectionRemoved(Nodule nodule)
|
||||
{
|
||||
Connections.Remove(nodule);
|
||||
NoduleManager.Instance.Update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://cmpl0if164dba" path="res://src/Gameplay/Nodules/Nodule.cs" id="1_yembh"]
|
||||
[ext_resource type="Texture2D" uid="uid://cecg47efx7gw8" path="res://assets/simple_nodule.png" id="2_7qt20"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_7qt20"]
|
||||
radius = 15.0
|
||||
[ext_resource type="PackedScene" uid="uid://bjesfu1mfx8l5" path="res://src/Gameplay/Nodules/Components/TubeConnectionArea.tscn" id="2_inlcu"]
|
||||
[ext_resource type="PackedScene" uid="uid://3x5pqm4t5cbl" path="res://src/Gameplay/Nodules/Components/GrowArea.tscn" id="2_x44k2"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_7qt20"]
|
||||
atlas = ExtResource("2_7qt20")
|
||||
@@ -35,9 +34,6 @@ animations = [{
|
||||
"speed": 2.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_x44k2"]
|
||||
radius = 96.38
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_x44k2"]
|
||||
font_size = 12
|
||||
outline_size = 3
|
||||
@@ -45,15 +41,14 @@ outline_color = Color(0, 0, 0, 1)
|
||||
shadow_size = 3
|
||||
shadow_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="Nodule" type="Node2D" unique_id=1637542829]
|
||||
[node name="Nodule" type="Node2D" unique_id=1637542829 node_paths=PackedStringArray("_tubeConnectionArea")]
|
||||
z_index = 1
|
||||
script = ExtResource("1_yembh")
|
||||
_tubeConnectionArea = NodePath("TubeConnectionArea")
|
||||
|
||||
[node name="ClickArea" type="Area2D" parent="." unique_id=120357381]
|
||||
unique_name_in_owner = true
|
||||
[node name="TubeConnectionArea" parent="." unique_id=1821668398 instance=ExtResource("2_inlcu")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ClickArea" unique_id=2005066434]
|
||||
shape = SubResource("CircleShape2D_7qt20")
|
||||
[node name="GrowArea" parent="." unique_id=979341496 instance=ExtResource("2_x44k2")]
|
||||
|
||||
[node name="Gfx" type="AnimatedSprite2D" parent="." unique_id=190397869]
|
||||
unique_name_in_owner = true
|
||||
@@ -62,15 +57,6 @@ sprite_frames = SubResource("SpriteFrames_xyjsl")
|
||||
autoplay = "default"
|
||||
frame_progress = 0.120879106
|
||||
|
||||
[node name="TubeConnectionArea" type="Area2D" parent="." unique_id=339547035]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="TubeConnectionArea" unique_id=234655540]
|
||||
shape = SubResource("CircleShape2D_x44k2")
|
||||
debug_color = Color(0.38922516, 0.6054754, 0.25354394, 0.41960785)
|
||||
|
||||
[node name="EnergyLabel" type="Label" parent="." unique_id=466024399]
|
||||
unique_name_in_owner = true
|
||||
anchors_preset = 5
|
||||
|
||||
Reference in New Issue
Block a user