Tuesday, 16 September 2025 12:26:13

This commit is contained in:
2025-09-16 12:26:16 -04:00
parent 36ce21cb44
commit 948e1d3874
8 changed files with 154 additions and 100 deletions

View File

@@ -3,21 +3,20 @@ using System;
using System.Collections.Generic;
using System.Linq;
public partial class Worker : CharacterBody2D
public partial class Worker : Area2D
{
[Signal]
public delegate void SetHoveredEventHandler(Worker THIS);
// [Signal]
// public delegate void SwapPositionsEventHandler(Worker THIS);
public bool _dead = false, _hovered = false, _held = false, _selected = false;
public int _size, _health, _healthMax;
public float _distanceTraveled, _stamina, _staminaMax;
public Stat _aptitude = new(), _agility = new(), _ardor = new(), _accumen = new(), _awareness = new(), _appeal = new();
public float _rotationalForce = 0;
public Vector2 _chainPosition = new Vector2(-1, -1), _deskPosition;
public List<Vector2> _moves = new();
public Sprite2D _image;
public ProgressBar _healthBar;
public Manager _manager;
public Cell _cell;
public List<Trait> _traits = new();
public override void _Ready()
{
@@ -48,9 +47,22 @@ public partial class Worker : CharacterBody2D
public override void _Process(double DELTA_)
{
// _chainPosition = GlobalPosition;
if (_hovered)
{
if (Input.IsActionJustPressed("left_click"))
{
Hold();
}
}
if (_held)
{
GlobalPosition = GetGlobalMousePosition();
if (Input.IsActionJustReleased("left_click"))
{
Drop();
}
}
}
// public void ChangeHealth(int CHANGE, Node CHANGEMAKER)
@@ -76,6 +88,7 @@ public partial class Worker : CharacterBody2D
if (_held)
{
_held = false;
GlobalPosition = _cell.GlobalPosition;
}
}
@@ -116,17 +129,40 @@ public partial class Worker : CharacterBody2D
_appeal._effective = _appeal._default;
}
public void SwapWith(Worker OTHERWORKER)
{
Cell thisCell = _cell, otherCell = OTHERWORKER._cell;
OTHERWORKER.GlobalPosition = thisCell.GlobalPosition;
_cell = otherCell;
OTHERWORKER._cell = thisCell;
int indexA = _manager._workers.IndexOf(this), indexB = _manager._workers.IndexOf(OTHERWORKER);
Worker placeholder = this;
_manager._workers[indexA] = OTHERWORKER;
_manager._workers[indexB] = placeholder;
}
// PRIVATE METHODS
private void OnAreaEntered(Area2D AREA)
{
if (AREA is Worker)
{
if (_held)
{
SwapWith((Worker)AREA);
}
}
}
private void OnMouseEntered()
{
_hovered = true;
EmitSignal(SignalName.SetHovered, this);
}
private void OnMouseExited()
{
_hovered = false;
EmitSignal(SignalName.SetHovered, this);
}
// private void OnBodyEntered(Node NODE)