Fix issues with smgr.gd

This commit is contained in:
JeremyStar™ 2023-05-30 02:08:28 +02:00
parent 2e23c39bcd
commit 0e843d3d8f

37
smgr.gd
View file

@ -6,7 +6,8 @@
# Licensed under GNU GPLv3 # Licensed under GNU GPLv3
extends Node extends Node
var available = false @onready
var core = get_node(NodePath("/root/core"))
var ccr = null var ccr = null
var ccr_game = null var ccr_game = null
var ccr_game_inuse = false var ccr_game_inuse = false
@ -17,12 +18,16 @@ var ccr_cutscene_inuse = false
var ccr_debug = null var ccr_debug = null
var ccr_debug_names = [] var ccr_debug_names = []
func add_game(scene:PackedScene) -> bool: func add_game(resname:String) -> bool:
Logger.info("smgr","Adding game scene") Logger.info("smgr","Adding game scene")
if ccr_game_inuse: if ccr_game_inuse:
Logger.error("smgr","Failed adding game scene: Only one game scene is allowed") Logger.error("smgr","Failed adding game scene: Only one game scene is allowed")
return false return false
ccr_game.add_child(scene.instantiate()) var res = core.resmgr.getres(resname)
if res == null or res.get_class() != "PackedScene":
Logger.error("smgr","Resource is not type of PackedScene")
return false
ccr_game.add_child(res.instantiate())
ccr_game_inuse = true ccr_game_inuse = true
Logger.info("smgr","Added game scene") Logger.info("smgr","Added game scene")
return true return true
@ -37,12 +42,16 @@ func remove_game() -> bool:
Logger.info("smgr","Removed game scene") Logger.info("smgr","Removed game scene")
return true return true
func add_menu(scene_name:String,scene:PackedScene) -> bool: func add_menu(scene_name:String,resname:String) -> bool:
Logger.info("smgr","Adding menu scene \"" + scene_name + "\"") Logger.info("smgr","Adding menu scene \"" + scene_name + "\"")
if ccr_menu_names.has(scene_name): if ccr_menu_names.has(scene_name):
Logger.error("smgr","Failed adding menu scene: Menu scene with name \"" + scene_name + "\" already exists") Logger.error("smgr","Failed adding menu scene: Menu scene with name \"" + scene_name + "\" already exists")
return false return false
ccr_menu.add_child(scene.instantiate()) var res = core.resmgr.getres(resname)
if res == null or res.get_class() != "PackedScene":
Logger.error("smgr","Resource is not type of PackedScene")
return false
ccr_menu.add_child(res.instantiate())
ccr_menu_names.append(scene_name) ccr_menu_names.append(scene_name)
Logger.info("smgr","Added menu scene \"" + scene_name + "\"") Logger.info("smgr","Added menu scene \"" + scene_name + "\"")
return true return true
@ -59,12 +68,16 @@ func remove_menu(scene_name:String) -> bool:
ccr_menu_names.erase(scene_name) ccr_menu_names.erase(scene_name)
return true return true
func add_cutscene(scene:PackedScene) -> bool: func add_cutscene(resname:String) -> bool:
Logger.info("smgr","Adding cutscene scene") Logger.info("smgr","Adding cutscene scene")
if ccr_cutscene_inuse: if ccr_cutscene_inuse:
Logger.error("smgr","Failed adding cutscene scene: Only one cutscene scene is allowed") Logger.error("smgr","Failed adding cutscene scene: Only one cutscene scene is allowed")
return false return false
ccr_cutscene.add_child(scene.instantiate()) var res = core.resmgr.getres(resname)
if res == null or res.get_class() != "PackedScene":
Logger.error("smgr","Resource is not type of PackedScene")
return false
ccr_cutscene.add_child(res.instantiate())
ccr_cutscene_inuse = true ccr_cutscene_inuse = true
Logger.info("smgr","Added cutscene scene") Logger.info("smgr","Added cutscene scene")
return true return true
@ -79,12 +92,16 @@ func remove_cutscene() -> bool:
Logger.info("smgr","Removed cutscene scene") Logger.info("smgr","Removed cutscene scene")
return true return true
func add_debug(scene_name:String,scene:PackedScene) -> bool: func add_debug(scene_name:String,resname:String) -> bool:
Logger.info("smgr","Adding debug scene \"" + scene_name + "\"") Logger.info("smgr","Adding debug scene \"" + scene_name + "\"")
if ccr_debug_names.has(scene_name): if ccr_debug_names.has(scene_name):
Logger.error("smgr","Failed adding debug scene: Debug scene with name \"" + scene_name + "\" already exists") Logger.error("smgr","Failed adding debug scene: Debug scene with name \"" + scene_name + "\" already exists")
return false return false
ccr_debug.add_child(scene.instantiate()) var res = core.resmgr.getres(resname)
if res == null or res.get_class() != "PackedScene":
Logger.error("smgr","Resource is not type of PackedScene")
return false
ccr_debug.add_child(res.instantiate())
ccr_debug_names.append(scene_name) ccr_debug_names.append(scene_name)
Logger.info("smgr","Added debug scene \"" + scene_name + "\"") Logger.info("smgr","Added debug scene \"" + scene_name + "\"")
return true return true
@ -120,7 +137,7 @@ func _ready() -> void:
Logger.info("smgr","COREBackground migration complete.") Logger.info("smgr","COREBackground migration complete.")
Logger.info("smgr","Adding overlays") Logger.info("smgr","Adding overlays")
add_overlays() add_overlays()
available = true core.setready()
func add_overlays() -> void: func add_overlays() -> void:
Logger.info("smgr","Adding game overlay") Logger.info("smgr","Adding game overlay")