extends Node2D @onready var zones = Data.data.zones const CURSOR = preload("res://components/Cursor/Cursor.tscn") const ZONE = preload("res://src/Zone.tscn") const UI_BUTTONS = preload("res://src/UIButtons.tscn") const PAUSE_WINDOW = preload("res://src/PauseWindow.tscn") const BUILD_WINDOW = preload("res://src/BuildWindow.tscn") const CREATURE_WINDOW = preload("res://src/CreatureWindow.tscn") var build_object @onready var upgrade_pool = Data.data.upgrades.keys() @onready var zone_pool = Data.data.zones.keys() @onready var audio_stream_player_2: AudioStreamPlayer = $AudioStreamPlayer2 @onready var audio_stream_player_3: AudioStreamPlayer = $AudioStreamPlayer3 @onready var audio_stream_player_4: AudioStreamPlayer = $AudioStreamPlayer4 func _ready() -> void: Persister.persist_data("creature_resource_spawn_rate", 20) Triggerer.listen("spawn_window", _on_spawn_window) Triggerer.listen("upgrade_menu", _on_build_menu) Triggerer.listen("quit", _on_quit) Triggerer.listen("creature_sound", _on_creature_sound) Triggerer.listen("coin_sound", _on_coin_sound) Triggerer.listen("coin_collect_sound", _on_coin_collect_sound) DisplayServer.window_set_title("Home") get_viewport().transparent_bg = true DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_MOUSE_PASSTHROUGH, true) var new_buttons = UI_BUTTONS.instantiate() var new_cursor = CURSOR.instantiate() new_buttons.add_child(new_cursor) add_child(new_buttons) func _on_creature_sound(_data): audio_stream_player_2.play() func _on_coin_collect_sound(_data): audio_stream_player_3.play() func _on_coin_sound(_data): audio_stream_player_4.play() func _process(delta: float) -> void: if Input.is_action_just_pressed("test"): Triggerer.trigger("spawn_window", {"key": ["farm", "desert", "lake", "forest"].pick_random()}) func _on_spawn_window(data) -> void: var zone = zones[data.key] var new_window = ZONE.instantiate() new_window.key = data.key new_window.size = Vector2(int(zone.size[0]) * 12 * 4, int(zone.size[1]) * 12 * 4) var new_cursor = CURSOR.instantiate() new_window.add_child(new_cursor) get_tree().root.add_child(new_window) func _on_quit(_data) -> void: get_tree().quit() func _on_build_menu(data): if data.value: var new_window = BUILD_WINDOW.instantiate() var new_cursor = CURSOR.instantiate() new_window.add_child(new_cursor) add_child(new_window) build_object = new_window else: build_object.queue_free() func _on_timer_timeout() -> void: var new_window = CREATURE_WINDOW.instantiate() var new_cursor = CURSOR.instantiate() new_window.add_child(new_cursor) add_child(new_window) Triggerer.trigger("spawn_window", {"key": ["forest"].pick_random()})