64 lines
2.0 KiB
GDScript
64 lines
2.0 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:
|
|
# Clear existing gameplay
|
|
for child in gameplay_container.get_children():
|
|
child.queue_free()
|
|
|
|
# Load new gameplay
|
|
if GAMEPLAY_SCENES.has(mode):
|
|
var gameplay_scene = load(GAMEPLAY_SCENES[mode])
|
|
var gameplay_instance = gameplay_scene.instantiate()
|
|
gameplay_container.add_child(gameplay_instance)
|
|
|
|
# Connect gameplay signals to shared systems
|
|
if gameplay_instance.has_signal("score_changed"):
|
|
gameplay_instance.score_changed.connect(_on_score_changed)
|
|
|
|
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:
|
|
print("Back button pressed in game scene")
|
|
AudioManager.play_ui_click()
|
|
GameManager.save_game()
|
|
GameManager.exit_to_main_menu()
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("ui_accept") and Input.is_action_pressed("ui_select"):
|
|
# Debug: Switch to clickomania when Space+Enter pressed together
|
|
if current_gameplay_mode == "match3":
|
|
set_gameplay_mode("clickomania")
|
|
print("Switched to clickomania gameplay")
|
|
else:
|
|
set_gameplay_mode("match3")
|
|
print("Switched to match3 gameplay")
|