ChocolateBird/main.gd

70 lines
2.1 KiB
GDScript

extends Control
enum Menu {
LOADER,
MAIN,
LOAD_SAVE,
WORLD_MAP,
FIELD_MAP,
PARTY,
SHOP,
BATTLE,
DEBUG,
DEBUG_AUDIO_SYSTEM,
DEBUG_BATTLE_SPRITES,
}
var menus = {}
var active_menu_stack = []
var is_rom_loaded := false
func _rom_loaded() -> void:
menus[Menu.PARTY] = preload('res://widgets/PartyMenu.tscn').instance()
menus[Menu.WORLD_MAP] = preload('res://test/worldmap_system.tscn').instance()
menus[Menu.DEBUG] = preload('res://test/debug_menu.tscn').instance()
menus[Menu.DEBUG].connect('pressed_worldmap', self, 'push_menu', [Menu.WORLD_MAP])
menus[Menu.DEBUG].connect('pressed_party', self, 'push_menu', [Menu.PARTY])
menus[Menu.DEBUG].connect('pressed_battle_sprites', self, 'push_menu', [Menu.DEBUG_BATTLE_SPRITES])
menus[Menu.DEBUG].connect('pressed_audio', self, 'push_menu', [Menu.DEBUG_AUDIO_SYSTEM])
menus[Menu.DEBUG_AUDIO_SYSTEM] = preload('res://test/audio_system.tscn').instance()
menus[Menu.DEBUG_BATTLE_SPRITES] = preload('res://test/battle_sprites.tscn').instance()
is_rom_loaded = true
func _ready() -> void:
if OS.get_name() != 'HTML5' or !OS.has_feature('JavaScript'):
menus[Menu.LOADER] = preload('res://widgets/RomSelect.tscn').instance()
else:
menus[Menu.LOADER] = preload('res://widgets/WebFileSelect.tscn').instance()
push_menu(Menu.LOADER)
RomLoader.connect('rom_loaded', self, '_rom_loaded')
menus[Menu.LOADER].connect('continue_pressed', self, 'push_debug_menu')
Common.update_window_scale()
func push_debug_menu():
push_menu(Menu.DEBUG)
func push_menu(menu_type):
if len(active_menu_stack) > 0:
if active_menu_stack[-1] == menu_type:
return
remove_child(menus[active_menu_stack[-1]])
active_menu_stack.append(menu_type)
add_child(menus[menu_type])
func pop_menu():
if len(active_menu_stack) > 0:
remove_child(menus[active_menu_stack.pop_back()])
if len(active_menu_stack) > 0:
add_child(menus[active_menu_stack[-1]])
else:
push_menu(Menu.LOADER)
func _input(event: InputEvent) -> void:
if event is InputEventKey and event.pressed:
match event.scancode:
KEY_BACKSPACE:
pop_menu()
KEY_D:
if is_rom_loaded:
push_menu(Menu.DEBUG)