mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Mappable switches
This commit is contained in:
parent
054c0998ad
commit
1454e55629
6 changed files with 165 additions and 7 deletions
|
|
@ -4,8 +4,10 @@ using Godot.Collections;
|
|||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
[Tool]
|
||||
public partial class Switch3D : Interactable3D
|
||||
{
|
||||
[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;
|
||||
|
|
@ -19,9 +21,18 @@ public partial class Switch3D : Interactable3D
|
|||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
|
||||
_activationSound = GetNodeOrNull<AudioStreamPlayer>(_activationSoundName);
|
||||
}
|
||||
|
||||
public void _func_godot_apply_properties(Dictionary<string, string> props)
|
||||
{
|
||||
TargetGroup = props["target"];
|
||||
//TargetFunc = props["targetfunc"];
|
||||
//TargetName = props["targetname"];
|
||||
}
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
var activationTypeToUse = activationType is ActivationType.Use ? ActivationType : activationType;
|
||||
|
|
@ -34,6 +45,11 @@ public partial class Switch3D : Interactable3D
|
|||
// 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);
|
||||
}
|
||||
|
||||
|
|
@ -43,4 +59,20 @@ 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}");
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue