ChocolateBird/main.gd

73 lines
2.1 KiB
GDScript

extends Control
#warning-ignore-all:return_value_discarded
const globals = preload('res://globals.gd') # Make LSP shut up about non-const
const Menu = globals.Menu
var packed_menus = {}
var menus = {}
var active_menu_stack = []
func instantiate_menu_list(menu_list) -> void:
for key in menu_list:
packed_menus[key] = load(globals.MENUS[key][0])
menus[key] = packed_menus[key].instance()
var is_rom_loaded := false
func _on_rom_loaded() -> void:
instantiate_menu_list(globals.POST_ROM_MENUS)
menus[Menu.DEBUG].connect('button_pressed', self, 'push_menu')
is_rom_loaded = true
var is_savefile_loaded := false
func _on_savefile_loaded(dicts) -> void:
push_menu(Menu.LOAD_SAVE)
menus[Menu.LOAD_SAVE].set_data(dicts)
menus[Menu.LOAD_SAVE].connect('slot_activated', self, '_on_saveslot_loaded')
func _on_saveslot_loaded(dict) -> void:
push_menu(Menu.PARTY)
menus[Menu.PARTY].update_labels(dict)
func _ready() -> void:
if OS.get_name() != 'HTML5' or !OS.has_feature('JavaScript'):
packed_menus[Menu.LOADER] = preload('res://widgets/FileSelect.tscn')
else:
packed_menus[Menu.LOADER] = preload('res://widgets/FileSelectWeb.tscn')
menus[Menu.LOADER] = packed_menus[Menu.LOADER].instance()
push_menu(Menu.LOADER)
instantiate_menu_list(globals.INITIAL_MENUS)
RomLoader.connect('rom_loaded', self, '_on_rom_loaded')
menus[Menu.LOADER].connect('continue_pressed', self, 'push_debug_menu')
menus[Menu.LOADER].connect('savefile_loaded', self, '_on_savefile_loaded')
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)