managems/Main.gd

36 lines
938 B
GDScript3
Raw Normal View History

2022-05-24 18:12:10 +02:00
extends Node
2022-05-25 17:26:43 +02:00
# 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
2022-05-24 18:12:10 +02:00
# Called when the node enters the scene tree for the first time.
func _ready():
2022-05-25 17:26:43 +02:00
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():
2022-05-24 18:12:10 +02:00
pass
2022-05-25 17:26:43 +02:00
# 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')