CORE/smgr.gd
2023-03-18 16:34:12 +01:00

123 lines
4 KiB
GDScript

# smgr.gd
# Scene Manager
#
# This file is part of StarOpenSource CORE (SOSCORE)
# Made by the StarOpenSource Project and Contributers
# Licensed under GNU GPLv3
extends Node
var available = false
var ccr = null
var ccr_game = null
var ccr_game_inuse = false
var ccr_menu = null
var ccr_menu_names = []
var ccr_cutscene = null
var ccr_cutscene_inuse = false
var ccr_debug = null
func add_game(scene:PackedScene) -> bool:
Logger.info("smgr","Adding game scene")
if ccr_game_inuse:
Logger.error("smgr","Failed adding game scene: Only one game scene is allowed")
return false
ccr_game.add_child(scene.instantiate())
ccr_game_inuse = true
Logger.info("smgr","Added game scene")
return true
func remove_game() -> bool:
Logger.info("smgr","Removing game scene")
if !ccr_game_inuse:
Logger.error("smgr","Failed removing game scene: No game scene is active")
return false
ccr_game.remove_child(ccr_game.get_child(0))
ccr_game_inuse = false
Logger.info("smgr","Removed game scene")
return true
func add_menu(scene_name:String,scene:PackedScene) -> bool:
Logger.info("smgr","Adding menu scene \"" + scene_name + "\"")
if ccr_menu_names.has(scene_name):
Logger.error("smgr","Failed adding menu scene: Menu scene with name \"" + scene_name + "\" already exists")
return false
ccr_menu.add_child(scene.instantiate())
ccr_menu_names.append(scene_name)
Logger.info("smgr","Added menu scene \"" + scene_name + "\"")
return true
func remove_menu(scene_name:String) -> bool:
Logger.info("smgr","Removing menu scene \"" + scene_name + "\"")
if !ccr_menu_names.has(scene_name):
Logger.error("smgr","Failed removing menu scene: Menu scene with name \"" + scene_name + "\" does not exist")
return false
for i in ccr_menu.get_children():
if i.name == scene_name:
ccr_menu.remove_child(i)
break
ccr_menu_names.erase(scene_name)
return true
func add_cutscene(scene:PackedScene) -> bool:
Logger.info("smgr","Adding cutscene scene")
if ccr_cutscene_inuse:
Logger.error("smgr","Failed adding cutscene scene: Only one cutscene scene is allowed")
return false
ccr_cutscene.add_child(scene.instantiate())
ccr_cutscene_inuse = true
Logger.info("smgr","Added cutscene scene")
return true
func remove_cutscene() -> bool:
Logger.info("smgr","Removing cutscene scene")
if !ccr_cutscene_inuse:
Logger.error("smgr","Failed removing cutscene scene: No cutscene scene is active")
return false
ccr_cutscene.remove_child(ccr_cutscene.get_child(0))
ccr_cutscene_inuse = false
Logger.info("smgr","Removed cutscene scene")
return true
func _ready() -> void:
Logger.info("smgr","Constructing CORE Scene Root (CCR)")
ccr = Control.new()
ccr.name = "ccr"
Logger.info("smgr","Adding CCR to /root/")
get_tree().root.add_child(ccr)
Logger.info("smgr","Migrating COREBackground to CCR")
var corebg = get_tree().current_scene
Logger.info("smgr","Reconstructing COREBackground to CCR")
var corebg_log = corebg.get_node(NodePath("Background/Log")).text
corebg.get_node(NodePath("Background/Log")).rmconnect()
get_tree().current_scene.queue_free()
var corebg_new = ResourceLoader.load("res://CORE/background.tscn").instantiate()
ccr.add_child(corebg_new)
corebg_new.get_node(NodePath("Background/Log")).text = corebg_log
corebg_new.get_node(NodePath("Background/Log")).log_first = false
Logger.info("smgr","COREBackground migration complete.")
Logger.info("smgr","Adding overlays")
add_overlays()
add_debug()
available = true
func add_overlays() -> void:
Logger.info("smgr","Adding game overlay")
ccr_game = Control.new()
ccr_game.name = "GameOverlay"
ccr.add_child(ccr_game)
Logger.info("smgr","Adding menu overlay")
ccr_menu = Control.new()
ccr_menu.name = "MenuOverlay"
ccr.add_child(ccr_menu)
Logger.info("smgr","Adding cutscene overlay")
ccr_cutscene = Control.new()
ccr_cutscene.name = "CutsceneOverlay"
ccr.add_child(ccr_cutscene)
Logger.info("smgr","Adding debug overlay")
ccr_debug = Control.new()
ccr_debug.name = "DebugOverlay"
ccr.add_child(ccr_debug)
func add_debug() -> void:
Logger.info("smgr","No debug scenes are available.")
return