mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-04 02:36:01 +00:00
Changed events to generic node
This commit is contained in:
parent
b89043cd8c
commit
7b2d32e727
17 changed files with 166 additions and 135 deletions
74
Scripts/Activables/ScriptableBase3D.cs
Normal file
74
Scripts/Activables/ScriptableBase3D.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using Cirno.Scripts.Resources.Events;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class ScriptableArea3D : Area3D, IActivable
|
||||
{
|
||||
[Export] public Array<EventResource> Events { get; set; } = [];
|
||||
|
||||
private EventResource CurrentEvent => Events[_currentEventIndex];
|
||||
|
||||
private int _currentEventIndex = 0;
|
||||
|
||||
private bool _started = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
foreach (var item in Events)
|
||||
{
|
||||
item.Init(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_started = true;
|
||||
StartEvent(CurrentEvent);
|
||||
}
|
||||
|
||||
private void StartEvent(EventResource eventResource)
|
||||
{
|
||||
eventResource.Start(this);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_started) return;
|
||||
|
||||
CurrentEvent.UpdateEvent(delta);
|
||||
|
||||
if (!CurrentEvent.WaitForCompletion || CurrentEvent.IsComplete())
|
||||
{
|
||||
// This loops
|
||||
_currentEventIndex++;
|
||||
if (_currentEventIndex >= Events.Count)
|
||||
{
|
||||
// It's over
|
||||
_started = false;
|
||||
_currentEventIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentEvent.Start(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
Start();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
this.Activate();
|
||||
}
|
||||
|
||||
public bool CanActivate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue