mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 02:15:53 +00:00
Terminal dialogue and entities fix
This commit is contained in:
parent
fe33f8d225
commit
dd979fe50a
16 changed files with 1078 additions and 912 deletions
91
Scripts/Activables/ScriptableArea3D.cs
Normal file
91
Scripts/Activables/ScriptableArea3D.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
using Cirno.Scripts.Interactables;
|
||||
using Cirno.Scripts.Misc;
|
||||
using Cirno.Scripts.Resources.Events;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class ScriptableArea3D : Area3D, IActivable, IInteractable
|
||||
{
|
||||
[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;
|
||||
}
|
||||
|
||||
public Vector2 GetGlobalPosition2D()
|
||||
{
|
||||
return new Vector2(this.GlobalPosition.X, this.GlobalPosition.Z);
|
||||
}
|
||||
|
||||
public Vector2 GetScreenPosition()
|
||||
{
|
||||
if (CameraController3D.Instance is null)
|
||||
{
|
||||
return this.GetGlobalPosition2D();
|
||||
}
|
||||
|
||||
return CameraController3D.Instance.UnprojectPosition(this.GlobalPosition);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue