1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 16:14:22 +00:00
hella-farm/main.gd

82 lines
1.9 KiB
GDScript3
Raw Normal View History

2024-04-13 01:14:11 +00:00
extends Node
2024-04-13 01:08:16 +00:00
class_name Main
2024-04-13 02:04:43 +00:00
2024-04-13 03:29:43 +00:00
@onready var tree: SceneTree = get_tree()
2024-04-13 02:04:43 +00:00
@onready var container: Control = $"PrimaryCanvas/SafeMarginContainer"
## The possible states the game can be in.
enum Stage {
NONE = 0,
MENU = 1,
2024-04-13 03:29:43 +00:00
OPTIONS = 2,
GAME = 3,
2024-04-13 02:04:43 +00:00
}
## The [Stage] the game is currently in.
##
## Changing this will automatically destroy and build the relevant scenes.
var current_stage: Stage:
get:
return current_stage
set(value):
# Do not rebuild scenes if the stage is set to the value it's already set to
if value == current_stage:
return
# Destroy the current scenes
match current_stage:
Stage.MENU:
destroy_menu()
# Update the current stage
current_stage = value
# Build the next scenes
match current_stage:
Stage.MENU:
build_menu()
2024-04-13 14:38:05 +00:00
Stage.GAME:
build_game()
2024-04-13 02:04:43 +00:00
## The [Stage] that [field current_stage] should be set to upon starting the game.
@export var starting_stage: Stage
## The main menu scene.
const SCENE_MENU: PackedScene = preload("res://scenes/interface/main_menu.tscn")
2024-04-13 14:38:05 +00:00
const SCENE_GAME: PackedScene = preload("res://scenes/game/game.tscn")
2024-04-13 02:04:43 +00:00
## The main menu node.
var scene_menu: MainMenu = null
2024-04-13 14:38:05 +00:00
var scene_game: MainGame = null
2024-04-13 02:04:43 +00:00
## Destroy the main menu.
func destroy_menu() -> void:
scene_menu.queue_free()
scene_menu = null
## Build the main menu.
func build_menu() -> void:
scene_menu = SCENE_MENU.instantiate()
2024-04-13 03:29:43 +00:00
scene_menu.selected_play.connect(_on_menu_selected_play)
scene_menu.selected_options.connect(_on_menu_selected_options)
2024-04-13 02:04:43 +00:00
container.add_child(scene_menu)
2024-04-13 14:38:05 +00:00
## Build the main menu.
func build_game() -> void:
scene_game = SCENE_GAME.instantiate()
scene_game.selected_exit.connect(_on_game_selected_exit)
container.add_child(scene_game)
2024-04-13 02:04:43 +00:00
func _ready() -> void:
current_stage = starting_stage
2024-04-13 03:29:43 +00:00
func _on_menu_selected_play() -> void:
current_stage = Stage.GAME
func _on_menu_selected_options() -> void:
current_stage = Stage.OPTIONS
2024-04-13 14:38:05 +00:00
func _on_game_selected_exit() -> void:
current_stage = Stage.MENU