init
This commit is contained in:
96
src/Gameplay/Nodules/Nodule.cs
Normal file
96
src/Gameplay/Nodules/Nodule.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using Godot;
|
||||
|
||||
namespace Slimepire.Gameplay.Nodules;
|
||||
|
||||
[SceneTree]
|
||||
public partial class Nodule : Node2D
|
||||
{
|
||||
[Export]
|
||||
public bool IsRoot;
|
||||
|
||||
private BuildGhost? _ghost;
|
||||
|
||||
private bool _mouseInsideClickArea;
|
||||
private bool _clickedInside;
|
||||
|
||||
public readonly List<Nodule> Connections = [];
|
||||
|
||||
// todo remove?
|
||||
private bool _isExpanding;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
ClickArea.MouseEntered += ClickAreaOnMouseEntered;
|
||||
ClickArea.MouseExited += ClickAreaOnMouseExited;
|
||||
|
||||
TubeConnectionArea.AreaEntered += TubeConnectionAreaOnAreaEntered;
|
||||
TubeConnectionArea.AreaExited += TubeConnectionAreaOnAreaExited;
|
||||
|
||||
TubeManager.Instance.RegisterNodule(this);
|
||||
}
|
||||
|
||||
private void TubeConnectionAreaOnAreaEntered(Area2D area)
|
||||
{
|
||||
if (area.GetParent() is Nodule nodule)
|
||||
{
|
||||
Connections.Add(nodule);
|
||||
TubeManager.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 && @event.IsPressed() && _mouseInsideClickArea)
|
||||
{
|
||||
_clickedInside = true;
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseEntered()
|
||||
{
|
||||
_mouseInsideClickArea = true;
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseExited()
|
||||
{
|
||||
_mouseInsideClickArea = false;
|
||||
|
||||
// ghost == null check probably unnecessary
|
||||
if (_clickedInside && _ghost == null)
|
||||
{
|
||||
_clickedInside = false;
|
||||
_isExpanding = true;
|
||||
|
||||
_ghost = Instantiator.Instantiate<BuildGhost>();
|
||||
_ghost.Position = Position;
|
||||
_ghost.OnBuild += OnBuildComplete;
|
||||
|
||||
GetParent()?.AddChild(_ghost);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBuildComplete(Vector2 pos)
|
||||
{
|
||||
_isExpanding = false;
|
||||
_ghost = null;
|
||||
|
||||
var nodule = Instantiator.Instantiate<Nodule>();
|
||||
|
||||
nodule.Position = pos;
|
||||
Connections.Add(nodule);
|
||||
nodule.Connections.Add(this);
|
||||
GetParent()?.AddChild(nodule);
|
||||
}
|
||||
}
|
||||
1
src/Gameplay/Nodules/Nodule.cs.uid
Normal file
1
src/Gameplay/Nodules/Nodule.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cmpl0if164dba
|
||||
64
src/Gameplay/Nodules/Nodule.tscn
Normal file
64
src/Gameplay/Nodules/Nodule.tscn
Normal file
@@ -0,0 +1,64 @@
|
||||
[gd_scene format=3 uid="uid://cnl6t8o4mh0j3"]
|
||||
|
||||
[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/Sprite-0001.png" id="2_7qt20"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_7qt20"]
|
||||
radius = 15.0
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_7qt20"]
|
||||
atlas = ExtResource("2_7qt20")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_x44k2"]
|
||||
atlas = ExtResource("2_7qt20")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_inlcu"]
|
||||
atlas = ExtResource("2_7qt20")
|
||||
region = Rect2(64, 0, 32, 32)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_xyjsl"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_7qt20")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_x44k2")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_inlcu")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 2.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_x44k2"]
|
||||
radius = 96.38
|
||||
|
||||
[node name="Nodule" type="Node2D" unique_id=1637542829]
|
||||
z_index = 1
|
||||
script = ExtResource("1_yembh")
|
||||
|
||||
[node name="ClickArea" type="Area2D" parent="." unique_id=120357381]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ClickArea" unique_id=2005066434]
|
||||
shape = SubResource("CircleShape2D_7qt20")
|
||||
|
||||
[node name="Blob" type="AnimatedSprite2D" parent="." unique_id=190397869]
|
||||
modulate = Color(0.34855, 0.6165254, 0.5102762, 1)
|
||||
texture_filter = 1
|
||||
sprite_frames = SubResource("SpriteFrames_xyjsl")
|
||||
autoplay = "default"
|
||||
frame = 1
|
||||
frame_progress = 0.9100785
|
||||
|
||||
[node name="TubeConnectionArea" type="Area2D" parent="." unique_id=339547035]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[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)
|
||||
9
src/Gameplay/Nodules/nodule.gd
Normal file
9
src/Gameplay/Nodules/nodule.gd
Normal file
@@ -0,0 +1,9 @@
|
||||
extends Node2D
|
||||
|
||||
var clicked_inside := false
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed == true:
|
||||
clicked_inside = true
|
||||
get_viewport().set_input_as_handled()
|
||||
1
src/Gameplay/Nodules/nodule.gd.uid
Normal file
1
src/Gameplay/Nodules/nodule.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bvl0487nflq0q
|
||||
Reference in New Issue
Block a user