Door player detection

This commit is contained in:
Marco 2025-07-08 14:31:12 +02:00
commit f7334c056b
14 changed files with 1631 additions and 1361 deletions

View file

@ -13,21 +13,24 @@ public partial class Switch3D : Interactable3D
[Export] public Node Target { get; set; }
[Export] public Array<Node> Targets { get; private set; } = [];
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
[Signal]
public delegate void OnActivatedEventHandler(ActivationType activationType);
private AudioStreamPlayer _activationSound;
private AudioStreamPlayer _denySound;
private readonly string _activationSoundName = "ActivationSound";
private readonly string _denySoundName = "ActivationSound";
public override void _Ready()
{
if (Engine.IsEditorHint()) return;
_activationSound = GetNodeOrNull<AudioStreamPlayer>(_activationSoundName);
_denySound = GetNodeOrNull<AudioStreamPlayer>(_denySoundName);
}
public void _func_godot_apply_properties(Dictionary<string, string> props)
{
TargetGroup = props["target"];
@ -35,6 +38,7 @@ public partial class Switch3D : Interactable3D
{
RequirementKeys = [prop];
}
if (props.TryGetValue("activationtype", out var type))
{
var t = Enum.TryParse(type, true, out ActivationType activationType);
@ -46,16 +50,19 @@ public partial class Switch3D : Interactable3D
//TargetFunc = props["targetfunc"];
//TargetName = props["targetname"];
}
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
var activationTypeToUse = activationType is ActivationType.Use ? ActivationType : activationType;
if (!MeetsRequirements()) return false;
_activationSound?.Play();
if (!MeetsRequirements())
{
_denySound?.Play();
return false;
}
EmitSignal(SignalName.OnActivated, (int)activationTypeToUse);
// Compatibility for old single system
bool success = ActivateTarget(Target, activationTypeToUse);
@ -63,8 +70,20 @@ public partial class Switch3D : Interactable3D
{
ActivationHelper.UseTargets(this, TargetGroup, activationType);
}
return Targets.Aggregate(success, (current, target) => ActivateTarget(target, activationTypeToUse) | success);
var result = Targets.Aggregate(success,
(current, target) => ActivateTarget(target, activationTypeToUse) | success);
if (result)
{
_activationSound?.Play();
}
else
{
_denySound?.Play();
}
return result;
}
private bool ActivateTarget(Node target, ActivationType activationType = ActivationType.Toggle)
@ -73,7 +92,7 @@ public partial class Switch3D : Interactable3D
activable?.Activate(activationType);
return true;
}
// private void UseTargets(Node activator, string target)
// {
// GD.Print($"Trying to use targets called: {target}");