Files
hotdesking/Gameplay/Tchotchke.cs

85 lines
1.8 KiB
C#

using Godot;
using System;
using System.Collections.Generic;
public partial class Tchotchke : StaticBody2D
{
public bool _hovered = false, _held = false;
public List<Effect> _effects = new();
public override void _Process(double DELTA_)
{
if (_held)
{
GlobalPosition = GetGlobalMousePosition();
if (Input.IsActionJustReleased("left_click"))
{
Transform2D newTransform = GlobalTransform;
newTransform.Origin = Position;
GlobalTransform = newTransform;
Drop();
}
}
else
{
if (_hovered)
{
if (Input.IsActionJustPressed("left_click"))
{
Hold();
}
if (Input.IsActionJustPressed("scroll_up"))
{
Rotation -= 1.0f * (float)(Math.PI) / 180.0f;
}
if (Input.IsActionJustPressed("scroll_down"))
{
Rotation += 1.0f * (float)(Math.PI) / 180.0f;
}
}
}
}
public void Drop()
{
if (_held)
{
_held = false;
}
}
public void Hold()
{
if (_held)
{
return;
}
_held = true;
}
// Processes
// PRIVATE METHODS
private void OnMouseEntered()
{
_hovered = true;
}
private void OnMouseExited()
{
_hovered = false;
}
private void OnBodyEntered(Node NODE)
{
if (NODE is Worker)
{
for (int i = 0; i < _effects.Count; i++)
{
GD.Print(1001);
_effects[i].TriggerEffect((Worker)NODE);
}
}
}
}