mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:45:33 +00:00
Triggerable movable walls
This commit is contained in:
parent
f3edc2b433
commit
9d0036c436
20 changed files with 1292 additions and 693 deletions
115
Scripts/Actors/3D/AlarmTrigger3D.cs
Normal file
115
Scripts/Actors/3D/AlarmTrigger3D.cs
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Actors._3D;
|
||||
|
||||
[Tool]
|
||||
public partial class AlarmTrigger3D : Node3D
|
||||
{
|
||||
[Export] public string TargetGroup { get; private set; }
|
||||
[Export] public Node Target { get; set; }
|
||||
[Export] public Array<Node> Targets { get; private set; } = [];
|
||||
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
|
||||
|
||||
[Export] public bool ActivateOnEnable { get; set; }
|
||||
[Export] public bool ActivateOnDisable { get; set; }
|
||||
|
||||
public void _func_godot_apply_properties(Dictionary<string, string> props)
|
||||
{
|
||||
TargetGroup = props["target"];
|
||||
if (props.TryGetValue("activationtype", out var type))
|
||||
{
|
||||
var t = Enum.TryParse(type, true, out ActivationType activationType);
|
||||
if (t)
|
||||
{
|
||||
ActivationType = activationType;
|
||||
}
|
||||
}
|
||||
|
||||
if (bool.TryParse(props["activateonenable"], out bool activateOnEnable))
|
||||
{
|
||||
ActivateOnEnable = activateOnEnable;
|
||||
}
|
||||
|
||||
if (bool.TryParse(props["activateondisable"], out bool activateOnDisable))
|
||||
{
|
||||
ActivateOnDisable = activateOnDisable;
|
||||
}
|
||||
|
||||
// TODO: Oneshot
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
|
||||
if (AlarmManager.Instance is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ActivateOnEnable)
|
||||
{
|
||||
AlarmManager.Instance.AlarmEnabled3D += AlarmEnabled;
|
||||
}
|
||||
|
||||
if (ActivateOnDisable)
|
||||
{
|
||||
AlarmManager.Instance.AlarmDisabled += AlarmDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
private void AlarmDisabled()
|
||||
{
|
||||
if (!ActivateOnDisable) return;
|
||||
Activate(ActivationType);
|
||||
}
|
||||
|
||||
private void AlarmEnabled(Vector3 location)
|
||||
{
|
||||
if (!ActivateOnEnable) return;
|
||||
Activate(ActivationType);
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
var activationTypeToUse = activationType is ActivationType.Use ? ActivationType : activationType;
|
||||
|
||||
// Compatibility for old single system
|
||||
bool success = ActivateTarget(Target, activationTypeToUse);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(TargetGroup))
|
||||
{
|
||||
UseTargets(this, TargetGroup);
|
||||
}
|
||||
|
||||
return Targets.Aggregate(success, (current, target) => ActivateTarget(target, activationTypeToUse) | success);
|
||||
}
|
||||
|
||||
private bool ActivateTarget(Node target, ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (target is not IActivable activable) return false;
|
||||
activable?.Activate(activationType);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UseTargets(Node activator, string target)
|
||||
{
|
||||
GD.Print($"Trying to use targets called: {target}");
|
||||
var targetList = GetTree().GetNodesInGroup(target);
|
||||
foreach (var t in targetList)
|
||||
{
|
||||
//string f;
|
||||
GD.Print($"Trying to use {t.Name}");
|
||||
if (t is IActivable activable)
|
||||
{
|
||||
GD.Print($"Activating {t.Name}");
|
||||
activable.Activate(ActivationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
Scripts/Actors/3D/AlarmTrigger3D.cs.uid
Normal file
1
Scripts/Actors/3D/AlarmTrigger3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bwh3ft5pcmajd
|
||||
Loading…
Add table
Add a link
Reference in a new issue