match-3 grid generation
make game scene modular global debug mode
This commit is contained in:
@@ -1,17 +1,63 @@
|
||||
extends Node
|
||||
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
|
||||
# Fixed: Use static Match3 instance from scene instead of dynamic loading
|
||||
@onready var match3_instance: Node = $Match3
|
||||
@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)
|
||||
# Fixed: No need to load match3 scene - it's already in the scene tree
|
||||
|
||||
# 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()
|
||||
# Fixed: Don't free the static instance, just exit
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user