71 lines
1.3 KiB
C#
71 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.Collections;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Common/CanSpawn.cs")]
|
|
public partial class CanSpawn : Node2D
|
|
{
|
|
public enum Type
|
|
{
|
|
Delete,
|
|
Disable,
|
|
MoveOffscreen,
|
|
MoveToPoint
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Type type;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Array<SaveFile.Flags> needs;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Array<SaveFile.Flags> limit;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool continuous;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D point;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
if (!SaveFile.CanDo(needs, limit))
|
|
{
|
|
CallDeferred("Disable");
|
|
}
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (continuous && !SaveFile.CanDo(needs, limit))
|
|
{
|
|
Disable();
|
|
continuous = false;
|
|
}
|
|
}
|
|
|
|
public void Disable()
|
|
{
|
|
switch (type)
|
|
{
|
|
case Type.Delete:
|
|
QueueFree();
|
|
break;
|
|
case Type.Disable:
|
|
Main.SetActive(this, state: false);
|
|
break;
|
|
case Type.MoveOffscreen:
|
|
base.GlobalPosition = Vector2.One * 99999f;
|
|
break;
|
|
case Type.MoveToPoint:
|
|
base.GlobalPosition = ((point != null) ? point.GlobalPosition : GetChild<Node2D>(0).GlobalPosition);
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|