Files
skelly/scenes/game/game.gd

73 lines
2.7 KiB
GDScript

extends Control
const GAMEPLAY_SCENES = {
"match3": "res://scenes/game/gameplays/match3_gameplay.tscn",
"clickomania": "res://scenes/game/gameplays/clickomania_gameplay.tscn"
}
@onready var back_button: Button = $BackButtonContainer/BackButton
@onready var gameplay_container: Control = $GameplayContainer
@onready var score_display: Label = $UI/ScoreDisplay
var current_gameplay_mode: String
var global_score: int = 0 : set = set_global_score
func _ready() -> void:
if not back_button.pressed.is_connected(_on_back_button_pressed):
back_button.pressed.connect(_on_back_button_pressed)
# Default to match3 for now
set_gameplay_mode("match3")
func set_gameplay_mode(mode: String) -> void:
current_gameplay_mode = mode
load_gameplay(mode)
func load_gameplay(mode: String) -> void:
DebugManager.log_debug("Loading gameplay mode: %s" % mode, "Game")
# Clear existing gameplay
for child in gameplay_container.get_children():
DebugManager.log_debug("Removing existing child: %s" % child.name, "Game")
child.queue_free()
# Load new gameplay
if GAMEPLAY_SCENES.has(mode):
DebugManager.log_debug("Found scene path: %s" % GAMEPLAY_SCENES[mode], "Game")
var gameplay_scene = load(GAMEPLAY_SCENES[mode])
var gameplay_instance = gameplay_scene.instantiate()
DebugManager.log_debug("Instantiated gameplay: %s" % gameplay_instance.name, "Game")
gameplay_container.add_child(gameplay_instance)
DebugManager.log_debug("Added gameplay to container, child count now: %d" % gameplay_container.get_child_count(), "Game")
# Connect gameplay signals to shared systems
if gameplay_instance.has_signal("score_changed"):
gameplay_instance.score_changed.connect(_on_score_changed)
DebugManager.log_debug("Connected score_changed signal", "Game")
else:
DebugManager.log_error("Gameplay mode '%s' not found in GAMEPLAY_SCENES" % mode, "Game")
func set_global_score(value: int) -> void:
global_score = value
if score_display:
score_display.text = "Score: " + str(global_score)
func _on_score_changed(points: int) -> void:
self.global_score += points
func _on_back_button_pressed() -> void:
DebugManager.log_debug("Back button pressed in game scene", "Game")
AudioManager.play_ui_click()
GameManager.save_game()
GameManager.exit_to_main_menu()
func _input(event: InputEvent) -> void:
if event.is_action_pressed("action_south") and Input.is_action_pressed("action_north"):
# Debug: Switch to clickomania when primary+secondary actions pressed together
if current_gameplay_mode == "match3":
set_gameplay_mode("clickomania")
DebugManager.log_debug("Switched to clickomania gameplay", "Game")
else:
set_gameplay_mode("match3")
DebugManager.log_debug("Switched to match3 gameplay", "Game")