I hope this doesn't break everything
This commit is contained in:
parent
645a4ba981
commit
2346b09da2
4 changed files with 152 additions and 2 deletions
|
@ -26,3 +26,4 @@ class_name CoreTypes
|
|||
|
||||
enum VersionType { RELEASE, RELEASECANDIDATE, BETA, ALPHA }
|
||||
enum LoggerLevel { NONE, ERROR, WARN, INFO, VERB, DIAG }
|
||||
enum SceneType { NONE, DEBUG, CUTSCENE, MENU, MAIN, BACKGROUND }
|
||||
|
|
|
@ -32,6 +32,7 @@ const version_typerelease: int = 0
|
|||
# Modules
|
||||
var logger: CoreBaseModule
|
||||
var misc: CoreBaseModule
|
||||
var sms: CoreBaseModule
|
||||
var logui: CoreBaseModule
|
||||
|
||||
# Variables
|
||||
|
@ -62,28 +63,34 @@ func initialize_modules() -> void:
|
|||
# Create Nodes
|
||||
logger = CoreBaseModule.new()
|
||||
misc = CoreBaseModule.new()
|
||||
sms = CoreBaseModule.new()
|
||||
logui = CoreBaseModule.new()
|
||||
# Set names
|
||||
logger.name = "Logger"
|
||||
misc.name = "Misc"
|
||||
sms.name = "SceneManagementSystem"
|
||||
logui.name = "LogUI"
|
||||
# Set scripts
|
||||
logger.set_script(ResourceLoader.load(basepath + "src/logger.gd"))
|
||||
misc.set_script(ResourceLoader.load(basepath + "src/misc.gd"))
|
||||
sms.set_script(ResourceLoader.load(basepath + "src/sms.gd"))
|
||||
logui.set_script(ResourceLoader.load(basepath + "src/logui.gd"))
|
||||
# Set reference to self
|
||||
logger.core = self
|
||||
misc.core = self
|
||||
sms.core = self
|
||||
logui.core = self
|
||||
# Call _initialize() (workaround as modules cannot access "core" during _init())
|
||||
logger._initialize()
|
||||
misc._initialize()
|
||||
sms._initialize()
|
||||
logui._initialize()
|
||||
|
||||
# Inject modules into the SceneTree
|
||||
func inject_modules() -> void:
|
||||
add_child(logger)
|
||||
add_child(misc)
|
||||
add_child(sms)
|
||||
add_child(logui)
|
||||
|
||||
# Registers a custom module
|
||||
|
@ -134,6 +141,7 @@ func apply_configuration() -> void:
|
|||
logger.verb("Applying configuration")
|
||||
logger._pull_config()
|
||||
misc._pull_config()
|
||||
sms._pull_config()
|
||||
logui._pull_config()
|
||||
for module in custom_modules:
|
||||
logger.diag("Updating configuration for custom module \"" + module.name + "\"")
|
||||
|
|
|
@ -36,7 +36,7 @@ func _initialize() -> void:
|
|||
font_bold = ResourceLoader.load(core.basepath + "dist/FiraCode/Bold.ttf")
|
||||
# Create LogUI
|
||||
background = ColorRect.new()
|
||||
background.name = "LogUI"
|
||||
background.name = "LOGUI"
|
||||
# Create LogRTL
|
||||
logrtl = RichTextLabel.new()
|
||||
logrtl.name = "LogRTL"
|
||||
|
@ -66,7 +66,7 @@ func _pull_config() -> void:
|
|||
|
||||
func _ready() -> void:
|
||||
# Add to SceneTree
|
||||
add_child(background)
|
||||
core.sms.add_child(background)
|
||||
background.add_child(logrtl)
|
||||
# Hide VScrollBar
|
||||
var vsbar: VScrollBar = logrtl.get_child(0, true)
|
||||
|
|
141
src/sms.gd
Normal file
141
src/sms.gd
Normal file
|
@ -0,0 +1,141 @@
|
|||
##############################################################################
|
||||
### CORE FRAMEWORK SOURCE FILE ###
|
||||
### Copyright (c) 2024 The StarOpenSource Project & Contributors ###
|
||||
### Licensed under the GNU General Public License v3 ###
|
||||
### ###
|
||||
### This program is free software: you can redistribute it and/or modify ###
|
||||
### it under the terms of the GNU General Public License as published by ###
|
||||
### the Free Software Foundation, either version 3 of the License, or ###
|
||||
### (at your option) any later version. ###
|
||||
### ###
|
||||
### This program is distributed in the hope that it will be useful, ###
|
||||
### but WITHOUT ANY WARRANTY; without even the implied warranty of ###
|
||||
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ###
|
||||
### GNU General Public License for more details. ###
|
||||
### ###
|
||||
### You should have received a copy of the GNU General Public License ###
|
||||
### along with this program. If not, see <https://www.gnu.org/licenses/>. ###
|
||||
##############################################################################
|
||||
### src/sms.gd (Scene Management System) ###
|
||||
### ###
|
||||
### Makes scene management way smarter and easier. ###
|
||||
##############################################################################
|
||||
extends CoreBaseModule
|
||||
|
||||
# Objects
|
||||
var scenes_debug: Node = Node.new()
|
||||
var scenes_cutscene: Node = Node.new()
|
||||
var scenes_menu: Node = Node.new()
|
||||
var scenes_main: Node = Node.new()
|
||||
var scenes_background: Node = Node.new()
|
||||
|
||||
# Variables
|
||||
var scenes: Dictionary = {}
|
||||
|
||||
func _initialize() -> void:
|
||||
scenes_debug.name = "DEBUG"
|
||||
scenes_cutscene.name = "CUTSCENE"
|
||||
scenes_menu.name = "MENU"
|
||||
scenes_main.name = "MAIN"
|
||||
scenes_background.name = "BACKGROUND"
|
||||
add_child(scenes_debug)
|
||||
add_child(scenes_cutscene)
|
||||
add_child(scenes_menu)
|
||||
add_child(scenes_main)
|
||||
add_child(scenes_background)
|
||||
|
||||
func _pull_config() -> void:
|
||||
if core.config.headless:
|
||||
# Remove all scenes
|
||||
logger.verb("Removing all scenes (triggered by headless mode)")
|
||||
for scene in scenes: remove_scene(scene, true)
|
||||
|
||||
# Add a scene to some scene collection
|
||||
func add_scene(sname: String, type: CoreTypes.SceneType, sclass: Node) -> bool:
|
||||
if core.config.headless: return false
|
||||
logger.verb("Adding scene \"" + sname + "\" of type " + str(type))
|
||||
if exists(sname) != CoreTypes.SceneType.NONE:
|
||||
logger.error("Scene with name \"" + sname + "\" already exists")
|
||||
return true
|
||||
sclass.name = sname
|
||||
match(type):
|
||||
CoreTypes.SceneType.DEBUG: scenes_debug.add_child(sclass)
|
||||
CoreTypes.SceneType.CUTSCENE: scenes_cutscene.add_child(sclass)
|
||||
CoreTypes.SceneType.MENU: scenes_menu.add_child(sclass)
|
||||
CoreTypes.SceneType.MAIN: scenes_main.add_child(sclass)
|
||||
CoreTypes.SceneType.BACKGROUND: scenes_background.add_child(sclass)
|
||||
CoreTypes.SceneType.NONE:
|
||||
logger.error("CoreTypes.SceneType.NONE is not a valid scene type")
|
||||
return false
|
||||
_: await logger.crash("Invalid SceneType " + str(type), true)
|
||||
scenes.merge({ sname: { "type": type, "class": sclass } })
|
||||
return true
|
||||
|
||||
# Remove a scene from some scene collection
|
||||
func remove_scene(sname: String, force_remove: bool = false) -> bool:
|
||||
if core.config.headless and !force_remove: return false
|
||||
if force_remove: await logger.crash("force_remove = true is not allowed", true)
|
||||
logger.verb("Removing scene \"" + sname + "\"")
|
||||
match(exists(sname)):
|
||||
CoreTypes.SceneType.DEBUG: scenes_debug.remove_child(scenes[sname]["class"])
|
||||
CoreTypes.SceneType.CUTSCENE: scenes_cutscene.remove_child(scenes[sname]["class"])
|
||||
CoreTypes.SceneType.MENU: scenes_menu.remove_child(scenes[sname]["class"])
|
||||
CoreTypes.SceneType.MAIN: scenes_main.remove_child(scenes[sname]["class"])
|
||||
CoreTypes.SceneType.BACKGROUND: scenes_background.remove_child(scenes[sname]["class"])
|
||||
CoreTypes.SceneType.NONE:
|
||||
logger.error("Scene \"" + sname + "\" does not exist")
|
||||
return false
|
||||
_: await logger.crash("Invalid SceneType " + str(exists(sname)), true)
|
||||
scenes.erase(sname)
|
||||
return true
|
||||
|
||||
# Return a loaded scene
|
||||
func get_scene(sname: String) -> Node:
|
||||
if core.config.headless: return null
|
||||
match(exists(sname)):
|
||||
CoreTypes.SceneType.DEBUG: return scenes[sname]["class"]
|
||||
CoreTypes.SceneType.CUTSCENE: return scenes[sname]["class"]
|
||||
CoreTypes.SceneType.MENU: return scenes[sname]["class"]
|
||||
CoreTypes.SceneType.MAIN: return scenes[sname]["class"]
|
||||
CoreTypes.SceneType.BACKGROUND: return scenes[sname]["class"]
|
||||
CoreTypes.SceneType.NONE: logger.error("Scene \"" + sname + "\" does not exist")
|
||||
_: await logger.crash("Invalid SceneType " + str(exists(sname)), true)
|
||||
return null
|
||||
|
||||
# Return a scene collection for scene manipulation
|
||||
func get_scene_collection(type: CoreTypes.SceneType) -> Node:
|
||||
if core.config.headless: return null
|
||||
match(type):
|
||||
CoreTypes.SceneType.DEBUG: return scenes_debug
|
||||
CoreTypes.SceneType.CUTSCENE: return scenes_cutscene
|
||||
CoreTypes.SceneType.MENU: return scenes_menu
|
||||
CoreTypes.SceneType.MAIN: return scenes_main
|
||||
CoreTypes.SceneType.BACKGROUND: return scenes_background
|
||||
CoreTypes.SceneType.NONE: logger.error("No scene collection was found for CoreTypes.SceneType.NONE")
|
||||
_: await logger.crash("Invalid SceneType " + str(type), true)
|
||||
return null
|
||||
|
||||
# Return scenes in some scene collection
|
||||
func get_scene_collection_list(type: CoreTypes.SceneType) -> Array[Node]:
|
||||
var list: Array[Node] = []
|
||||
for scene in scenes:
|
||||
if scenes[scene]["type"] == type:
|
||||
list.append(scene)
|
||||
return list
|
||||
|
||||
# Return scene count in some scene collection
|
||||
func get_scene_collection_count(type: CoreTypes.SceneType) -> int:
|
||||
var amount: int = 0
|
||||
for scene in scenes:
|
||||
if scene[scene]["type"] == type:
|
||||
amount = amount+1
|
||||
return amount
|
||||
|
||||
# Return scene existance & scene collection
|
||||
func exists(sname: String) -> CoreTypes.SceneType:
|
||||
if scenes_debug.has(sname): return CoreTypes.SceneType.DEBUG
|
||||
elif scenes_cutscene.has(sname): return CoreTypes.SceneType.CUTSCENE
|
||||
elif scenes_menu.has(sname): return CoreTypes.SceneType.MENU
|
||||
elif scenes_main.has(sname): return CoreTypes.SceneType.MAIN
|
||||
elif scenes_background.has(sname): return CoreTypes.SceneType.BACKGROUND
|
||||
else: return CoreTypes.SceneType.NONE
|
Loading…
Reference in a new issue