###################################### # THE CORE FRAMEWORK # # MADE BY THE STAROPENSOURCE PROJECT # # AND CONTRIBUTERS (THANK YOU!) # # # # COPYRIGHT 2023 THE STAROPENSOURCE # # PROJECT AND CONTRIBUTERS # # # # LICENSED UNDER THE GNU GENERAL # # PUBLIC LICENSE VERSION 3 (ONLY) # ###################################### extends Node # CORE modules var core: Node = null var logger: Node = null var resourcemanager: Node = null # Overlays ## The debug overlay var debug_overlay: Node = Node.new() var debug_overlay_scene: Dictionary = {} ## The cutscene overlay var cutscene_overlay: Node = Node.new() var cutscene_overlay_scene: String = "" ## The menu overlay var menu_overlay: Node = Node.new() var menu_overlay_scene: Dictionary = {} ## The action overlay var action_overlay: Node = Node.new() var action_overlay_scene: String = "" # Initializes the scene manager func initialize() -> void: if core.protection_mode: return logger.diag("CORE/smgr.gd","Constructing overlays") # Set overlay names debug_overlay.name = "DebugOverlay" cutscene_overlay.name = "CutsceneOverlay" menu_overlay.name = "MenuOverlay" action_overlay.name = "ActionOverlay" logger.diag("CORE/smgr.gd","Adding overlays") # Adds overlays to /root/ get_tree().root.add_child(debug_overlay) get_tree().root.add_child(cutscene_overlay) get_tree().root.add_child(menu_overlay) get_tree().root.add_child(action_overlay) # Adds a debug scene func add_debug(resource_name:String) -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Adding debug scene \"" + resource_name + "\"") # Load resource into memory var resource: Object = resourcemanager.getres(resource_name) if resource == null or resource.get_class() != "PackedScene": # If resource is null (not loaded) or is not a PackedScene, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_NOT_PACKEDSCENE,{"scene":resource_name,"overlay":"debug"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] if debug_overlay_scene.has(resource_name) and debug_overlay.get_children().has(resource): # If scene already exists, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_ALREADY_LOADED,{"scene":resource_name,"overlay":"debug"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] resource = resource.instantiate() if !debug_overlay_scene.has(resource_name) and debug_overlay.get_children().has(resource): core.exception("SceneManager","debug_overlay_scene does not contain \"" + resource_name + "\" but debug_overlay does") return core.Errors.CORE_EXCEPTION if debug_overlay_scene.has(resource_name) and !debug_overlay.get_children().has(resource): core.exception("SceneManager","debug_overlay does not contain \"" + resource_name + "\" but debug_overlay_scene does") return core.Errors.CORE_EXCEPTION resource.name = resource_name debug_overlay.add_child(resource) debug_overlay_scene.merge({resource_name:resource},true) return core.Errors.OK # Adds a menu scene func add_menu(resource_name:String) -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Adding menu scene \"" + resource_name + "\"") # Load resource into memory var resource: Object = resourcemanager.getres(resource_name) if resource == null or resource.get_class() != "PackedScene": # If resource is null (not loaded) or is not a PackedScene, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_NOT_PACKEDSCENE,{"scene":resource_name,"overlay":"menu"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] if menu_overlay_scene.has(resource_name) and menu_overlay.get_children().has(resource): # If resource is null (not loaded) or is not a PackedScene, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_ALREADY_LOADED,{"scene":resource_name,"overlay":"menu"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] resource = resource.instantiate() if !menu_overlay_scene.has(resource_name) and menu_overlay.get_children().has(resource): core.exception("SceneManager","menu_overlay_scene does not contain \"" + resource_name + "\" but menu_overlay does") return core.Errors.CORE_EXCEPTION if menu_overlay_scene.has(resource_name) and !menu_overlay.get_children().has(resource): core.exception("SceneManager","menu_overlay does not contain \"" + resource_name + "\" but menu_overlay_scene does") return core.Errors.CORE_EXCEPTION resource.name = resource_name menu_overlay.add_child(resource) menu_overlay_scene.merge({resource_name:resource},true) return core.Errors.OK # Adds a cutscene scene func add_cutscene(resource_name:String) -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Adding cutscene scene \"" + resource_name + "\"") # Load resource into memory var resource: Object = resourcemanager.getres(resource_name) if resource == null or resource.get_class() != "PackedScene": # If resource is null (not loaded) or is not a PackedScene, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_NOT_PACKEDSCENE,{"scene":resource_name,"overlay":"cutscene"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] if cutscene_overlay_scene == resource_name and cutscene_overlay.get_children().has(resource): # If resource is null (not loaded) or is not a PackedScene, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_ALREADY_LOADED,{"scene":resource_name,"overlay":"cutscene"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] resource = resource.instantiate() if cutscene_overlay_scene != resource_name and cutscene_overlay.get_children().has(resource): core.exception("SceneManager","cutscene_overlay_scene does not contain \"" + resource_name + "\" but cutscene_overlay does") return core.Errors.CORE_EXCEPTION if cutscene_overlay_scene == resource_name and !cutscene_overlay.get_children().has(resource): core.exception("SceneManager","cutscene_overlay does not contain \"" + resource_name + "\" but cutscene_overlay_scene does") return core.Errors.CORE_EXCEPTION resource.name = resource_name cutscene_overlay.add_child(resource) cutscene_overlay_scene = resource_name return core.Errors.OK # Adds a action scene func add_action(resource_name:String) -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Adding action scene \"" + resource_name + "\"") # Load resource into memory var resource = resourcemanager.getres(resource_name) if resource == null or typeof(resource) != TYPE_OBJECT or resource.get_class() != "PackedScene": # If resource is null (not loaded) or is not a PackedScene, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_NOT_PACKEDSCENE,{"scene":resource_name,"overlay":"action"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] if action_overlay_scene == resource_name and action_overlay.get_children().has(resource): # If resource is null (not loaded) or is not a PackedScene, throw an error var err = core.error("SceneManager",core.Errors.SCENEMANAGER_ALREADY_LOADED,{"scene":resource_name,"overlay":"action"}) logger.error("CORE/smgr.gd",err["error"]) return err["code"] resource = resource.instantiate() if action_overlay_scene != resource_name and action_overlay.get_children().has(resource): core.exception("SceneManager","action_overlay_scene does not contain \"" + resource_name + "\" but action_overlay does") return core.Errors.CORE_EXCEPTION if action_overlay_scene == resource_name and !action_overlay.get_children().has(resource): core.exception("SceneManager","action_overlay does not contain \"" + resource_name + "\" but action_overlay_scene does") return core.Errors.CORE_EXCEPTION resource.name = resource_name action_overlay.add_child(resource) action_overlay_scene = resource_name return core.Errors.OK func remove_debug(resource_name:String) -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Removing debug scene \"" + resource_name + "\"") for child in debug_overlay.get_children(): if child.name == resource_name: debug_overlay.remove_child(child) break else: core.exception("SceneManager","Could not remove \"" + resource_name + "\" from the debug overlay as debug_overlay does have a child with that name") return core.Errors.CORE_EXCEPTION debug_overlay_scene.erase(resource_name) return core.Errors.OK func remove_cutscene() -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Removing cutscene scene \"" + cutscene_overlay_scene + "\"") for child in cutscene_overlay.get_children(): if child.name == cutscene_overlay_scene: cutscene_overlay.remove_child(child) break else: core.exception("SceneManager","Could not remove \"" + cutscene_overlay_scene + "\" from the cutscene overlay as cutscene_overlay does have a child with that name") return core.Errors.CORE_EXCEPTION cutscene_overlay_scene = "" return core.Errors.OK func remove_menu(resource_name:String) -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Removing menu scene \"" + resource_name + "\"") for child in menu_overlay.get_children(): if child.name == resource_name: menu_overlay.remove_child(child) break else: core.exception("SceneManager","Could not remove \"" + resource_name + "\" from the menu overlay as menu_overlay does have a child with that name") return core.Errors.CORE_EXCEPTION menu_overlay_scene.erase(resource_name) return core.Errors.OK func remove_action() -> int: if core.protection_mode: return core.Errors.CORE_PROTECTIONMODE logger.diag("CORE/smgr.gd","Removing action scene \"" + cutscene_overlay_scene + "\"") for child in action_overlay.get_children(): if child.name == cutscene_overlay_scene: action_overlay.remove_child(child) break else: core.exception("SceneManager","Could not remove \"" + cutscene_overlay_scene + "\" from the action overlay as action_overlay does have a child with that name") return core.Errors.CORE_EXCEPTION action_overlay_scene = "" return core.Errors.OK