From 6a1a7994b98aa31ab0739a06660c119a902dd3da Mon Sep 17 00:00:00 2001 From: Matt Penny Date: Sat, 2 Mar 2024 21:58:21 -0500 Subject: [PATCH] Avoid unnecessary signal definition * Don't generate button cube signal if -1 or omitted * Require button press, door, and box dropper signals to be specified --- documentation/levels/level_objects/button.md | 10 +++++----- src/scene/button.c | 2 +- tools/level_scripts/entities.lua | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/documentation/levels/level_objects/button.md b/documentation/levels/level_objects/button.md index 5f073a7..aaeb0d2 100644 --- a/documentation/levels/level_objects/button.md +++ b/documentation/levels/level_objects/button.md @@ -5,15 +5,15 @@ A flat, circular button which emits a [signal](../signals.md) while pressed. ## Name structure ``` -@button PRESS_SIGNAL_NAME OBJECT_PRESS_SIGNAL_NAME +@button PRESS_SIGNAL_NAME [OBJECT_PRESS_SIGNAL_NAME] ``` ## Arguments -| Name | Description | -| -------------------------- | --------------------------------------------------------- | -| `PRESS_SIGNAL_NAME` | The name of the signal to emit while pressed | -| `OBJECT_PRESS_SIGNAL_NAME` | The name of the signal to emit while pressed by an object | +| Name | Description | +| ------------------------------------- | -------------------------------------------------------------------------------------------------- | +| `PRESS_SIGNAL_NAME` | The name of the signal to emit while pressed | +| `OBJECT_PRESS_SIGNAL_NAME` (optional) | The name of the signal to emit while pressed by an object. Use `-1` or omit to indicate no signal. | ## Notes diff --git a/src/scene/button.c b/src/scene/button.c index 2be742f..23ade40 100644 --- a/src/scene/button.c +++ b/src/scene/button.c @@ -134,7 +134,7 @@ void buttonUpdate(struct Button* button) { targetPos.y -= BUTTON_MOVEMENT_AMOUNT; signalsSend(button->signalIndex); - if (shouldPress == PRESSED_WITH_CUBE) { + if (button->cubeSignalIndex != -1 && shouldPress == PRESSED_WITH_CUBE) { signalsSend(button->cubeSignalIndex); } diff --git a/tools/level_scripts/entities.lua b/tools/level_scripts/entities.lua index d30176b..a7014b4 100644 --- a/tools/level_scripts/entities.lua +++ b/tools/level_scripts/entities.lua @@ -17,7 +17,7 @@ for _, dropper in pairs(sk_scene.nodes_for_type('@box_dropper')) do table.insert(box_droppers, { position, room_index, - signals.signal_index_for_name(dropper.arguments[1] or ''), + signals.signal_index_for_name(dropper.arguments[1]), }) end @@ -33,8 +33,8 @@ for _, button in pairs(sk_scene.nodes_for_type('@button')) do table.insert(buttons, { position, room_index, - signals.signal_index_for_name(button.arguments[1] or ''), - signals.signal_index_for_name(button.arguments[2] or ''), + signals.signal_index_for_name(button.arguments[1]), + signals.optional_signal_index_for_name(button.arguments[2]) }) end @@ -75,7 +75,7 @@ for _, door in pairs(sk_scene.nodes_for_type('@door')) do position, rotation, world.find_coplanar_doorway(position) - 1, - signals.signal_index_for_name(door.arguments[1] or ''), + signals.signal_index_for_name(door.arguments[1]), parse_door_type(door.arguments[2]) }) end