managems/Main.gd

36 lines
938 B
GDScript

extends Node
# The main scene manages the displayed screens
const BattleScreen = preload("res://screens/battle_screen.tscn")
# Variables
# The stack of screens. All are displayed one above the others.
var screens: Array = []
var current_screen: String
# Called when the node enters the scene tree for the first time.
func _ready():
go_to_battle_screen()
# Function to change screen
func on_next_screen(screen: String):
match screen:
'battle':
go_to_battle_screen()
# Function to leave current screen
func on_leave_screen():
pass
# Common screen management
func go_to_screen(type, name):
current_screen = name
var scr = type.instance()
scr.connect("next_screen", self, "on_next_screen")
scr.connect("leave_screen", self, "on_leave_screen")
screens.push_back(scr)
$Screens.add_child(scr)
# Screen transitions
func go_to_battle_screen():
go_to_screen(BattleScreen, 'battle')