mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 04:55:54 +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;
|
||||
}
|
||||
}
|
||||
1
Scripts/Activables/ScriptableBase3D.cs.uid
Normal file
1
Scripts/Activables/ScriptableBase3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cpwn25m6b4lqf
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Cirno.Scripts;
|
||||
|
||||
public partial class AlarmManager : Node2D
|
||||
public partial class AlarmManager : Node
|
||||
{
|
||||
[Export]
|
||||
public AudioStream AlarmSound { get; private set; }
|
||||
|
|
@ -12,10 +12,14 @@ public partial class AlarmManager : Node2D
|
|||
public bool IsAlarmOn { get; private set; } = false;
|
||||
|
||||
public Vector2 LastAlarmPosition { get; private set; } = new Vector2();
|
||||
public Vector3 LastAlarmPosition3D { get; private set; } = new Vector3();
|
||||
|
||||
[Signal]
|
||||
public delegate void AlarmEnabledEventHandler(Vector2 location);
|
||||
|
||||
[Signal]
|
||||
public delegate void AlarmEnabled3DEventHandler(Vector3 location);
|
||||
|
||||
[Signal]
|
||||
public delegate void AlarmDisabledEventHandler();
|
||||
|
||||
|
|
@ -40,7 +44,18 @@ public partial class AlarmManager : Node2D
|
|||
if (IsAlarmOn) return;
|
||||
IsAlarmOn = true;
|
||||
LastAlarmPosition = location;
|
||||
EmitSignal(nameof(AlarmEnabled), location);
|
||||
EmitSignalAlarmEnabled(location);
|
||||
|
||||
GD.Print($"Alarm sounded at {location}");
|
||||
_player?.Play();
|
||||
}
|
||||
|
||||
public void SoundAlarm(Vector3 location)
|
||||
{
|
||||
if (IsAlarmOn) return;
|
||||
IsAlarmOn = true;
|
||||
LastAlarmPosition3D = location;
|
||||
EmitSignalAlarmEnabled3D(location);
|
||||
|
||||
GD.Print($"Alarm sounded at {location}");
|
||||
_player?.Play();
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
using Cirno.Scripts.Misc;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Events._3D;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class GenericDialogueStartEvent : EventResource
|
||||
{
|
||||
[Export] public StringName TimelineName = "timeline";
|
||||
private Node _dialogic;
|
||||
private GameManager _gameManager;
|
||||
private bool _isComplete = false;
|
||||
|
||||
private DialogueSkipListener _listener;
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
{
|
||||
_gameManager = parent.GetGameManager();
|
||||
_dialogic = parent.GetNode("/root/Dialogic");
|
||||
_dialogic.ProcessMode = Node.ProcessModeEnum.Always;
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
{
|
||||
if (GlobalState.Instance.SessionSettings.SkipDialogues)
|
||||
{
|
||||
DialogueEndAction();
|
||||
return;
|
||||
}
|
||||
|
||||
CreateSkipListener(parent);
|
||||
|
||||
Hud.Instance?.HideHud();
|
||||
|
||||
_dialogic.Connect("timeline_ended", Callable.From(OnTimelineEnded));
|
||||
|
||||
var dialogicNode =_dialogic.Call("start", TimelineName.ToString());
|
||||
((Node)dialogicNode).ProcessMode = Node.ProcessModeEnum.Always;
|
||||
_gameManager.ChangeState(GameState.Dialogue);
|
||||
}
|
||||
|
||||
private void CreateSkipListener(Node2D parent)
|
||||
{
|
||||
_listener = new DialogueSkipListener();
|
||||
parent.AddChild(_listener);
|
||||
_listener.ProcessMode = Node.ProcessModeEnum.Always;
|
||||
_listener.Skipped += ListenerOnSkipped;
|
||||
}
|
||||
|
||||
private void ListenerOnSkipped()
|
||||
{
|
||||
_listener.Skipped -= ListenerOnSkipped;
|
||||
_listener.QueueFree();
|
||||
_dialogic.Call("end_timeline");
|
||||
}
|
||||
|
||||
private void OnTimelineEnded()
|
||||
{
|
||||
Hud.Instance?.ShowHud();
|
||||
_gameManager.ChangeState(GameState.Playing);
|
||||
if (_dialogic.IsConnected("timeline_ended", Callable.From(OnTimelineEnded)))
|
||||
{
|
||||
_dialogic.Disconnect("timeline_ended", Callable.From(OnTimelineEnded));
|
||||
}
|
||||
|
||||
DialogueEndAction();
|
||||
}
|
||||
|
||||
private void DialogueEndAction()
|
||||
{
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
public override void UpdateEvent(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://no0it4lihfx
|
||||
|
|
@ -10,7 +10,7 @@ public partial class ActivateEvent : EventResource
|
|||
|
||||
[Export] public Array<NodePath> Targets;
|
||||
|
||||
private Node2D _parent;
|
||||
private Node _parent;
|
||||
|
||||
private bool _isComplete = false;
|
||||
|
||||
|
|
@ -37,12 +37,12 @@ public partial class ActivateEvent : EventResource
|
|||
return true;
|
||||
}
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
|
||||
ActivateTargets();
|
||||
|
|
|
|||
|
|
@ -7,21 +7,25 @@ namespace Cirno.Scripts.Resources.Events;
|
|||
public partial class AlarmDisableEvent : EventResource
|
||||
{
|
||||
private bool _isComplete = false;
|
||||
private AlarmManager _alarmManager;
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_alarmManager = parent.GetAlarmManager();
|
||||
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
_alarmManager.DisableAlarm();
|
||||
if (AlarmManager.Instance is null)
|
||||
{
|
||||
_isComplete = true;
|
||||
return;
|
||||
};
|
||||
AlarmManager.Instance.DisableAlarm();
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,21 +7,36 @@ namespace Cirno.Scripts.Resources.Events;
|
|||
public partial class AlarmEnableEvent : EventResource
|
||||
{
|
||||
private bool _isComplete = false;
|
||||
private AlarmManager _alarmManager;
|
||||
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_alarmManager = parent.GetAlarmManager();
|
||||
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
_alarmManager.SoundAlarm(parent.GlobalPosition);
|
||||
if (AlarmManager.Instance is null)
|
||||
{
|
||||
_isComplete = true;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (parent)
|
||||
{
|
||||
case Node2D node2D:
|
||||
AlarmManager.Instance.SoundAlarm(node2D.GlobalPosition);
|
||||
break;
|
||||
case Node3D node3D:
|
||||
AlarmManager.Instance.SoundAlarm(node3D.GlobalPosition);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public partial class CameraTargetEvent : CameraTargetPlayerEvent
|
|||
[Export]
|
||||
public Vector2 Offset { get; private set; }
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
GameManager.Instance.CameraTargetObject(parent.GetNode<Node2D>(Target), Offset);
|
||||
_isComplete = true;
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ public partial class CameraTargetPlayerEvent : EventResource
|
|||
{
|
||||
protected bool _isComplete = false;
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
GameManager.Instance.CameraTargetPlayer();
|
||||
_isComplete = true;
|
||||
|
|
|
|||
|
|
@ -8,22 +8,20 @@ public partial class ControlActorEvent : EventResource
|
|||
[Export]
|
||||
public NodePath Target { get; set; }
|
||||
|
||||
private Node2D _parent;
|
||||
private Node _parent;
|
||||
|
||||
private GameManager _gameManager;
|
||||
private bool _isComplete = false;
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_gameManager = parent.GetGameManager();
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public override void Start(Node2D parentNode)
|
||||
public override void Start(Node parentNode)
|
||||
{
|
||||
_isComplete = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,28 +8,27 @@ public partial class ControlEnemyEvent : EventResource
|
|||
[Export]
|
||||
public NodePath Target { get; set; }
|
||||
|
||||
private Node2D _parent;
|
||||
private Node _parent;
|
||||
|
||||
private GameManager _gameManager;
|
||||
private bool _isComplete = false;
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_gameManager = parent.GetGameManager();
|
||||
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public override void Start(Node2D parentNode)
|
||||
public override void Start(Node parentNode)
|
||||
{
|
||||
_isComplete = false;
|
||||
|
||||
if (_parent.GetNode<Node2D>(Target) is Enemy enemy)
|
||||
{
|
||||
_gameManager.CameraTargetObject(enemy);
|
||||
GameManager.Instance.CameraTargetObject(enemy);
|
||||
GameManager.Instance.Player.SetState(PlayerState.Controlling);
|
||||
// _gameManager.Player.RequestMovementDisable(true);
|
||||
enemy.AssumeControl();
|
||||
|
|
|
|||
|
|
@ -8,19 +8,17 @@ public partial class DialogueStartEvent : EventResource
|
|||
{
|
||||
[Export] public StringName TimelineName = "timeline";
|
||||
private Node _dialogic;
|
||||
private GameManager _gameManager;
|
||||
private bool _isComplete = false;
|
||||
|
||||
private DialogueSkipListener _listener;
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_gameManager = parent.GetGameManager();
|
||||
_dialogic = parent.GetNode("/root/Dialogic");
|
||||
_dialogic.ProcessMode = Node.ProcessModeEnum.Always;
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
if (GlobalState.Instance.SessionSettings.SkipDialogues)
|
||||
{
|
||||
|
|
@ -36,10 +34,22 @@ public partial class DialogueStartEvent : EventResource
|
|||
|
||||
var dialogicNode =_dialogic.Call("start", TimelineName.ToString());
|
||||
((Node)dialogicNode).ProcessMode = Node.ProcessModeEnum.Always;
|
||||
_gameManager.ChangeState(GameState.Dialogue);
|
||||
ChangeState(GameState.Dialogue);
|
||||
}
|
||||
|
||||
private void CreateSkipListener(Node2D parent)
|
||||
private void ChangeState(GameState state)
|
||||
{
|
||||
if (GameManager.Instance is not null)
|
||||
{
|
||||
GameManager.Instance.ChangeState(state);
|
||||
}
|
||||
else if (GameController.Instance is not null)
|
||||
{
|
||||
GameController.Instance.ChangeState(state);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSkipListener(Node parent)
|
||||
{
|
||||
_listener = new DialogueSkipListener();
|
||||
parent.AddChild(_listener);
|
||||
|
|
@ -57,7 +67,7 @@ public partial class DialogueStartEvent : EventResource
|
|||
private void OnTimelineEnded()
|
||||
{
|
||||
Hud.Instance?.ShowHud();
|
||||
_gameManager.ChangeState(GameState.Playing);
|
||||
ChangeState(GameState.Playing);
|
||||
if (_dialogic.IsConnected("timeline_ended", Callable.From(OnTimelineEnded)))
|
||||
{
|
||||
_dialogic.Disconnect("timeline_ended", Callable.From(OnTimelineEnded));
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ namespace Cirno.Scripts.Resources.Events;
|
|||
public abstract partial class EventResource : Resource
|
||||
{
|
||||
[Export] public bool WaitForCompletion = true;
|
||||
public abstract void Init(Node2D parent);
|
||||
public abstract void Start(Node2D parent);
|
||||
public abstract void Init(Node parent);
|
||||
public abstract void Start(Node parent);
|
||||
public abstract void UpdateEvent(double delta);
|
||||
public abstract bool IsComplete();
|
||||
}
|
||||
|
|
@ -26,14 +26,13 @@ public partial class MovePlayerEvent : EventResource
|
|||
|
||||
private bool _isComplete = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_gameManager = parent.GetGameManager();
|
||||
|
||||
}
|
||||
|
||||
public override void Start(Node2D parentNode)
|
||||
public override void Start(Node parentNode)
|
||||
{
|
||||
_isComplete = false;
|
||||
_ = MovePlayer();
|
||||
|
|
@ -45,8 +44,8 @@ public partial class MovePlayerEvent : EventResource
|
|||
//_gameManager.Player.RequestMovementDisable(true);
|
||||
|
||||
var gtween = GTweenSequenceBuilder.New()
|
||||
.Append(_gameManager.Player.MainObject.TweenGlobalPosition(
|
||||
_gameManager.Player.MainObject.GlobalPosition + RelativeTargetPosition, MovementTime)
|
||||
.Append(GameManager.Instance.Player.MainObject.TweenGlobalPosition(
|
||||
GameManager.Instance.Player.MainObject.GlobalPosition + RelativeTargetPosition, MovementTime)
|
||||
.SetEasing(GTweenEasing)
|
||||
//.
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,19 +5,18 @@ namespace Cirno.Scripts.Resources.Events;
|
|||
[GlobalClass]
|
||||
public partial class UpdateCheckPointEvent : EventResource
|
||||
{
|
||||
private GameManager _gameManager;
|
||||
|
||||
[Export]
|
||||
public NodePath Target { get; set; }
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
_gameManager = parent.GetGameManager();
|
||||
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
_gameManager.LastCheckpointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||
GameManager.Instance.LastCheckpointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||
// _gameManager.Player.LastCheckPointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ public partial class WaitEvent : EventResource
|
|||
public float WaitTime { get; set; }
|
||||
protected bool _isComplete = false;
|
||||
|
||||
public override void Init(Node2D parent)
|
||||
public override void Init(Node parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override void Start(Node parent)
|
||||
{
|
||||
_ = Wait();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue