SwitchInteraction ​
Inherits: InteractableObjectInteraction < Interaction < Resource
Inherited by: LightInteraction
Switch interaction - handles ON/OFF toggle with lock mechanics and audio feedback Base class for LightInteraction and other toggle-based interactions
Properties ​
SwitchState | current_state | SwitchState.OFF |
bool | starts_on | false |
bool | cooldown_enabled | false |
float | cooldown_duration | 2.0 |
String | switch_on_animation | "switch_on" |
String | switch_off_animation | "switch_off" |
String | broken_animation | "broken" |
String | locked_animation | "locked" |
SFXSelection | switch_on_sound | |
SFXSelection | switch_off_sound | |
SFXSelection | locked_sound |
Variables ​
Timer | cooldown_timer |
Methods ​
void | setup_for_interactable_objects( interactable: InteractableObject ) |
bool | can_interact( player: Player ) |
void | start_interaction( player: Player ) |
void | end_interaction() |
String | get_interaction_prompt() |
void | on_locked_reaction() |
float | get_cooldown_remaining() |
void | set_switch_state( new_state: SwitchState, triggering_entity: Entity = null ) |
SwitchState | get_switch_state() |
bool | is_switch_on() |
bool | is_switch_off() |
bool | is_switch_broken() |
bool | is_switch_on_cooldown() |
void | break_switch() |
void | turn_on() |
void | turn_off() |
void | toggle() |
Dictionary | save_state() |
void | load_state( state: Dictionary ) |
void | cleanup() |
Signals ​
switch_turned_on( entity: Entity ) ​
Emitted when the switch is turned on.
switch_turned_off( entity: Entity ) ​
Emitted when the switch is turned off.
switch_state_changed( new_state: SwitchState, entity: Entity ) ​
Emitted when the state of the switch changes: the new state and who changed it.
Enumerations ​
enum SwitchState ​
The states of a switch: on, off, broken or in cooldown.
- ON =
0 - OFF =
1 - BROKEN =
2 - COOLDOWN =
3
Property descriptions ​
SwitchState current_state = SwitchState.OFF ​
The state of the switch now.
bool starts_on = false ​
True when the switch is on when the game starts.
Cooldown
bool cooldown_enabled = false ​
True when the switch cannot be used again for a while after a use.
float cooldown_duration = 2.0 ​
How many seconds the switch waits after a use (when the cooldown is on).
Animations
String switch_on_animation = "switch_on" ​
The animation of turning the switch on.
String switch_off_animation = "switch_off" ​
The animation of turning the switch off.
String broken_animation = "broken" ​
The animation of a broken switch.
String locked_animation = "locked" ​
The animation of trying a locked switch.
Audio
SFXSelection switch_on_sound ​
The sound of turning the switch on.
SFXSelection switch_off_sound ​
The sound of turning the switch off.
SFXSelection locked_sound ​
The sound of trying a locked switch.
Variable descriptions ​
Timer cooldown_timer ​
The timer of the cooldown.
Method descriptions ​
void setup_for_interactable_objects( interactable: InteractableObject ) ​
Sets the switch up on its object: finds the nodes it needs and applies its starting state.
bool can_interact( player: Player ) ​
Can the player use the switch now (in range, the object is not broken, the requirements are met)?
void start_interaction( player: Player ) ​
The player uses the switch.
void end_interaction() ​
Does nothing: a switch has no end of interaction.
String get_interaction_prompt() ​
The text of the prompt above the object for its state now ("Open", "Climb" ...).
void on_locked_reaction() ​
Called when someone tries the object while it is locked: plays the locked sound and animation.
float get_cooldown_remaining() ​
How many seconds of the cooldown are left.
void set_switch_state( new_state: SwitchState, triggering_entity: Entity = null ) ​
Force the switch to a specific state
SwitchState get_switch_state() ​
Get the current switch state
bool is_switch_on() ​
Check if switch is currently on
bool is_switch_off() ​
Check if switch is currently off
bool is_switch_broken() ​
Check if switch is broken
bool is_switch_on_cooldown() ​
Check if switch is on cooldown
void break_switch() ​
Break the switch (set to BROKEN state)
void turn_on() ​
Turn switch on (force without entity interaction)
void turn_off() ​
Turn switch off (force without entity interaction)
void toggle() ​
Toggle switch state
Dictionary save_state() ​
The state of the switch for a save.
void load_state( state: Dictionary ) ​
Restores the state of the switch from a save.
void cleanup() ​
Gives its timers back and clears what it holds (the object is going away).