Switch multitarget

This commit is contained in:
Marco 2025-02-24 10:24:12 +01:00
commit a5dac0606c
3 changed files with 36 additions and 22 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=90 format=4 uid="uid://bv451a8wgty4u"]
[gd_scene load_steps=89 format=4 uid="uid://bv451a8wgty4u"]
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
@ -73,8 +73,7 @@
[ext_resource type="PackedScene" uid="uid://bc054js8ep2b" path="res://Scenes/Actors/FairyGuard_New.tscn" id="73_cfpaq"]
[ext_resource type="PackedScene" uid="uid://bdvj4cxnyr3w4" path="res://Scenes/Actors/Thermathron.tscn" id="73_ier4h"]
[ext_resource type="PackedScene" uid="uid://dfat0erkvb513" path="res://Scenes/Actors/Fairy_New.tscn" id="73_s4x1s"]
[ext_resource type="Texture2D" uid="uid://m32iqs21np0v" path="res://Sprites/BlackPixel.png" id="74_ra850"]
[ext_resource type="Script" path="res://Scripts/Activables/BlackCover.cs" id="75_jy7lo"]
[ext_resource type="PackedScene" uid="uid://c21m7w5ahpsd0" path="res://Scenes/Activable/Shroud.tscn" id="74_oaf68"]
[sub_resource type="Resource" id="Resource_6sau4"]
script = ExtResource("7_l32kg")
@ -197,10 +196,12 @@ metadata/_edit_lock_ = true
[node name="HiddenProps" type="Node2D" parent="Factory Tilemaps"]
metadata/_edit_lock_ = true
[node name="ControlPad5" parent="Factory Tilemaps/HiddenProps" node_paths=PackedStringArray("Target") instance=ExtResource("12_hfkf1")]
[node name="ControlPad5" parent="Factory Tilemaps/HiddenProps" node_paths=PackedStringArray("Target", "Targets") instance=ExtResource("12_hfkf1")]
y_sort_enabled = true
position = Vector2(-968, 162)
Target = NodePath("../../HorizontalDoor2")
Targets = [NodePath("../../../Shroud")]
ActivationType = 5
[node name="Debug Room" type="Node2D" parent="Factory Tilemaps"]
metadata/_edit_lock_ = true
@ -333,13 +334,13 @@ Target = NodePath("../Door_vertical")
position = Vector2(-1064, 165)
Target = NodePath("../Door_vertical")
[node name="ControlPad2" parent="Factory Tilemaps" node_paths=PackedStringArray("Target") instance=ExtResource("12_hfkf1")]
[node name="ControlPad2" parent="Factory Tilemaps" node_paths=PackedStringArray("Targets") instance=ExtResource("12_hfkf1")]
position = Vector2(-824, 165)
Target = NodePath("../Door_vertical2")
Targets = [NodePath("../Door_vertical2")]
[node name="ControlPad4" parent="Factory Tilemaps" node_paths=PackedStringArray("Target") instance=ExtResource("12_hfkf1")]
[node name="ControlPad4" parent="Factory Tilemaps" node_paths=PackedStringArray("Targets") instance=ExtResource("12_hfkf1")]
position = Vector2(-856, 167)
Target = NodePath("../Door_vertical2")
Targets = [NodePath("../Door_vertical2")]
[node name="Door_vertical" parent="Factory Tilemaps" instance=ExtResource("15_mgtvp")]
position = Vector2(-1048, 184)
@ -535,6 +536,15 @@ Target = NodePath("../Debug Room/HorizontalForceField")
[node name="VerticalDoor" parent="Factory Tilemaps" instance=ExtResource("15_mgtvp")]
position = Vector2(-1452, -247)
[node name="Teleporter10" parent="Factory Tilemaps" node_paths=PackedStringArray("Target") instance=ExtResource("30_8fdby")]
position = Vector2(-815, -343)
IsEnabled = true
Target = NodePath("../DebugTeleporter")
[node name="DebugTeleporter" parent="Factory Tilemaps" instance=ExtResource("30_8fdby")]
position = Vector2(-801, 171)
Invisible = true
[node name="CameraController" type="Camera2D" parent="."]
script = ExtResource("6_t8ide")
pixel_snap = false
@ -752,10 +762,4 @@ position = Vector2(-1010, 203)
position = Vector2(-581, -346)
StartingAiState = 1
[node name="Shroud" type="Sprite2D" parent="."]
visible = false
z_index = 1
position = Vector2(-920.5, 78.75)
scale = Vector2(127, 126.5)
texture = ExtResource("74_ra850")
script = ExtResource("75_jy7lo")
[node name="Shroud" parent="." instance=ExtResource("74_oaf68")]

View file

@ -13,6 +13,7 @@ public partial class BlackCover : Sprite2D, IActivable
public override void _Ready()
{
_activated = StartActive;
UpdateSprite();
}
public void Activate(ActivationType activationType = ActivationType.Toggle)

View file

@ -1,20 +1,29 @@
using Godot;
using System.Linq;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Interactables;
public partial class Switch : Interactable
{
[Export] public Node2D Target { get; set; }
[Export] public Array<Node2D> Targets { get; private set; } = new Array<Node2D>();
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
public override bool Activate()
{
if (MeetsRequirements() && Target is IActivable activable)
{
activable?.Activate(ActivationType);
return true;
}
if (!MeetsRequirements()) return false;
// Compatibility for old single system
bool success = ActivateTarget(Target);
return Targets.Aggregate(success, (current, target) => ActivateTarget(target) | success);
}
private bool ActivateTarget(Node2D target)
{
if (target is not IActivable activable) return false;
activable?.Activate(ActivationType);
return true;
return false;
}
}