2024-10-07 05:05:27 +00:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
@onready var zones = Data.data.zones
|
|
|
|
|
|
|
|
const CURSOR = preload("res://components/Cursor/Cursor.tscn")
|
|
|
|
const ZONE = preload("res://src/Zone.tscn")
|
2024-10-07 08:25:58 +00:00
|
|
|
const UI_BUTTONS = preload("res://src/UIButtons.tscn")
|
|
|
|
const PAUSE_WINDOW = preload("res://src/PauseWindow.tscn")
|
|
|
|
const BUILD_WINDOW = preload("res://src/BuildWindow.tscn")
|
|
|
|
|
|
|
|
var build_object
|
2024-10-07 05:05:27 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
Triggerer.listen("spawn_window", _on_spawn_window)
|
2024-10-07 08:25:58 +00:00
|
|
|
Triggerer.listen("upgrade_menu", _on_build_menu)
|
2024-10-07 05:05:27 +00:00
|
|
|
Triggerer.listen("quit", _on_quit)
|
|
|
|
DisplayServer.window_set_title("Home")
|
|
|
|
get_viewport().transparent_bg = true
|
2024-10-07 08:25:58 +00:00
|
|
|
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)
|
2024-10-07 05:05:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
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_timer_timeout() -> void:
|
|
|
|
Triggerer.trigger("spawn_window", {"key": ["farm", "desert", "lake", "forest"].pick_random()})
|
|
|
|
|
|
|
|
|
|
|
|
func _on_quit(_data) -> void:
|
|
|
|
get_tree().quit()
|
2024-10-07 08:25:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|