Convert some repetitive functions in Player.gd to dispatch tables

Convert some repetitive functions in Player.gd to dispatch tables. This makes reading the code easier and clarifies purpose.
This commit is contained in:
Jeod
2025-09-22 09:45:58 -04:00
parent f876241a99
commit 7f44b4bc2e

View File

@@ -537,35 +537,56 @@ func die(pit := false) -> void:
func death_load() -> void: func death_load() -> void:
power_state = get_node("PowerStates/Small") power_state = get_node("PowerStates/Small")
Global.player_power_states = "0000" Global.player_power_states = "0000"
if Global.death_load: if Global.death_load:
return return
Global.death_load = true Global.death_load = true
if Global.current_game_mode == Global.GameMode.CUSTOM_LEVEL:
LevelTransition.level_to_transition_to = "res://Scenes/Levels/LevelEditor.tscn" # Handle lives decrement for CAMPAIGN and MARATHON
Global.transition_to_scene("res://Scenes/Levels/LevelTransition.tscn")
return
if Global.current_game_mode == Global.GameMode.LEVEL_EDITOR:
owner.stop_testing()
return
if [Global.GameMode.CAMPAIGN, Global.GameMode.MARATHON].has(Global.current_game_mode): if [Global.GameMode.CAMPAIGN, Global.GameMode.MARATHON].has(Global.current_game_mode):
if Settings.file.difficulty.inf_lives == 0: if Settings.file.difficulty.inf_lives == 0:
Global.lives -= 1 Global.lives -= 1
Global.death_load = true
if Global.current_game_mode == Global.GameMode.CHALLENGE: # Full dispatch table for death handling
Global.transition_to_scene("res://Scenes/Levels/ChallengeMiss.tscn") var death_actions = {
elif Global.time <= 0: Global.GameMode.CUSTOM_LEVEL: func():
Global.transition_to_scene("res://Scenes/Levels/TimeUp.tscn") LevelTransition.level_to_transition_to = "res://Scenes/Levels/LevelEditor.tscn"
elif Global.lives <= 0 and Settings.file.difficulty.inf_lives == 0: Global.transition_to_scene("res://Scenes/Levels/LevelTransition.tscn"),
Global.death_load = false
Global.transition_to_scene("res://Scenes/Levels/GameOver.tscn") Global.GameMode.LEVEL_EDITOR: func():
else: owner.stop_testing(),
LevelPersistance.reset_states()
if Global.current_game_mode == Global.GameMode.BOO_RACE: Global.GameMode.CHALLENGE: func():
Global.transition_to_scene("res://Scenes/Levels/ChallengeMiss.tscn"),
Global.GameMode.BOO_RACE: func():
Global.reset_values() Global.reset_values()
Global.clear_saved_values() Global.clear_saved_values()
Global.death_load = false Global.death_load = false
Level.start_level_path = Global.current_level.scene_file_path Level.start_level_path = Global.current_level.scene_file_path
Global.current_level.reload_level() Global.current_level.reload_level(),
"time_up": func():
Global.transition_to_scene("res://Scenes/Levels/TimeUp.tscn"),
"game_over": func():
Global.death_load = false
Global.transition_to_scene("res://Scenes/Levels/GameOver.tscn"),
"default_reload": func():
LevelPersistance.reset_states()
Global.current_level.reload_level()
}
# Determine which action to take
if death_actions.has(Global.current_game_mode):
death_actions[Global.current_game_mode].call()
elif Global.time <= 0:
death_actions["time_up"].call()
elif Global.lives <= 0 and Settings.file.difficulty.inf_lives == 0:
death_actions["game_over"].call()
else:
death_actions["default_reload"].call()
func time_up() -> void: func time_up() -> void:
die() die()