Camera triggers

This commit is contained in:
Marco 2025-06-30 10:02:37 +02:00
commit b0d0161ab0
8 changed files with 1136 additions and 1074 deletions

View file

@ -1,14 +1,37 @@
using Godot;
using System;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Actors._3D;
[Tool]
public partial class SecurityCamera3D : Destructible3D
{
[Export] public StringName SweepAnimation { get; private set; } = "SweepLoop";
[Export] public string TargetGroup { get; private set; }
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
[Signal]
public delegate void AnimationStartEventHandler(string animationName);
[Signal]
public delegate void OnActivatedEventHandler(ActivationType activationType);
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;
}
}
}
public override void _Ready()
{
if (Engine.IsEditorHint()) return;
@ -20,5 +43,9 @@ public partial class SecurityCamera3D : Destructible3D
if (Engine.IsEditorHint()) return;
GD.Print($"{body.Name} Sighted!");
AlarmManager.Instance?.SoundAlarm(this.GlobalPosition);
if (!string.IsNullOrWhiteSpace(TargetGroup))
{
ActivationHelper.UseTargets(this, TargetGroup);
}
}
}

View file

@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Linq;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;
@ -33,6 +35,14 @@ public partial class Switch3D : Interactable3D
{
RequirementKeys = [prop];
}
if (props.TryGetValue("activationtype", out var type))
{
var t = Enum.TryParse(type, true, out ActivationType activationType);
if (t)
{
ActivationType = activationType;
}
}
//TargetFunc = props["targetfunc"];
//TargetName = props["targetname"];
}
@ -51,7 +61,7 @@ public partial class Switch3D : Interactable3D
if (!string.IsNullOrWhiteSpace(TargetGroup))
{
UseTargets(this, TargetGroup);
ActivationHelper.UseTargets(this, TargetGroup);
}
return Targets.Aggregate(success, (current, target) => ActivateTarget(target, activationTypeToUse) | success);
@ -64,19 +74,19 @@ public partial class Switch3D : Interactable3D
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.Toggle();
}
}
}
// private void UseTargets(Node activator, string target)
// {
// GD.Print($"Trying to use targets called: {target}");
// var targetList = activator.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.Toggle();
// }
// }
// }
}

View file

@ -0,0 +1,22 @@
using Godot;
namespace Cirno.Scripts.Utils;
public static class ActivationHelper
{
public static void UseTargets(Node activator, string target)
{
GD.Print($"Trying to use targets called: {target}");
var targetList = activator.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.Toggle();
}
}
}
}

View file

@ -0,0 +1 @@
uid://yaelg8hdimia