Update log calls
This commit is contained in:
parent
4e44373e9e
commit
49c52fb31a
5 changed files with 82 additions and 82 deletions
44
src/core.gd
44
src/core.gd
|
@ -76,7 +76,7 @@ func _ready() -> void:
|
||||||
# Cleanup
|
# Cleanup
|
||||||
# Particularily useful during testing to cleanup stuff, or if you want to do some stupid stuff with CORE during runtime
|
# Particularily useful during testing to cleanup stuff, or if you want to do some stupid stuff with CORE during runtime
|
||||||
func cleanup() -> void:
|
func cleanup() -> void:
|
||||||
logger.infof("Core", "Cleaning up")
|
logger.infof("core", "Cleaning up")
|
||||||
config.queue_free()
|
config.queue_free()
|
||||||
var modules_reverse: Array[String] = modules.duplicate()
|
var modules_reverse: Array[String] = modules.duplicate()
|
||||||
modules_reverse.reverse()
|
modules_reverse.reverse()
|
||||||
|
@ -138,38 +138,38 @@ func complete_init(no_success: bool = false) -> void:
|
||||||
|
|
||||||
# Initialization complete
|
# Initialization complete
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
if !no_success: logger.infof("Core", "Initialized CORE successfully")
|
if !no_success: logger.infof("core", "Initialized CORE successfully")
|
||||||
|
|
||||||
# Registers a custom module
|
# Registers a custom module
|
||||||
## Registers a new custom module.
|
## Registers a new custom module.
|
||||||
func register_custom_module(module_name: String, module_origin: String, module_class: CoreBaseModule) -> bool:
|
func register_custom_module(module_name: String, module_origin: String, module_class: CoreBaseModule) -> bool:
|
||||||
logger.verbf("Core", "Registering new custom module \"" + module_name + "\"")
|
logger.verbf("core", "Registering new custom module \"" + module_name + "\"")
|
||||||
if !config.custom_modules:
|
if !config.custom_modules:
|
||||||
logger.errorf("Core", "Registering module failed: Custom module support is disabled.")
|
logger.errorf("core", "Registering module failed: Custom module support is disabled.")
|
||||||
return false
|
return false
|
||||||
if custom_modules.has(module_name):
|
if custom_modules.has(module_name):
|
||||||
logger.errorf("Core", "Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
|
logger.errorf("core", "Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
|
||||||
return false
|
return false
|
||||||
logger.diagf("Core", "Updating variables")
|
logger.diagf("core", "Updating variables")
|
||||||
module_class.name = module_name
|
module_class.name = module_name
|
||||||
module_class.core = self
|
module_class.core = self
|
||||||
module_class.loggeri = logger.get_instance(module_origin)
|
module_class.loggeri = logger.get_instance(module_origin)
|
||||||
logger.diagf("Core", "Adding module to SceneTree")
|
logger.diagf("core", "Adding module to SceneTree")
|
||||||
custom_modules_node.add_child(module_class)
|
custom_modules_node.add_child(module_class)
|
||||||
logger.diagf("Core", "Merging module with custom_modules")
|
logger.diagf("core", "Merging module with custom_modules")
|
||||||
custom_modules.merge({ module_name: module_class })
|
custom_modules.merge({ module_name: module_class })
|
||||||
logger.diagf("Core", "Initializing custom module")
|
logger.diagf("core", "Initializing custom module")
|
||||||
module_class._initialize()
|
module_class._initialize()
|
||||||
logger.diagf("Core", "Updating custom module configuration")
|
logger.diagf("core", "Updating custom module configuration")
|
||||||
module_class._pull_config()
|
module_class._pull_config()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# Unregisters a custom module
|
# Unregisters a custom module
|
||||||
## Unregisters a custom module, making it no longer function.
|
## Unregisters a custom module, making it no longer function.
|
||||||
func unregister_custom_module(module_name: String) -> void:
|
func unregister_custom_module(module_name: String) -> void:
|
||||||
logger.verbf("Core", "Unregistering custom module \"" + module_name + "\"")
|
logger.verbf("core", "Unregistering custom module \"" + module_name + "\"")
|
||||||
if !custom_modules.has(module_name):
|
if !custom_modules.has(module_name):
|
||||||
logger.errorf("Core", "Unregistering module failed: A custom module with the name \"" + module_name + "\" does not exist.")
|
logger.errorf("core", "Unregistering module failed: A custom module with the name \"" + module_name + "\" does not exist.")
|
||||||
return
|
return
|
||||||
var module: Node = get_custom_module(module_name)
|
var module: Node = get_custom_module(module_name)
|
||||||
await module._cleanup()
|
await module._cleanup()
|
||||||
|
@ -181,9 +181,9 @@ func unregister_custom_module(module_name: String) -> void:
|
||||||
# Returns a custom module
|
# Returns a custom module
|
||||||
## Returns a loaded custom module for access.
|
## Returns a loaded custom module for access.
|
||||||
func get_custom_module(module_name: String) -> CoreBaseModule:
|
func get_custom_module(module_name: String) -> CoreBaseModule:
|
||||||
logger.diagf("Core", "Getting custom module \"" + module_name + "\"")
|
logger.diagf("core", "Getting custom module \"" + module_name + "\"")
|
||||||
if !custom_modules.has(module_name):
|
if !custom_modules.has(module_name):
|
||||||
logger.errorf("Core", "Getting module failed: A custom module with the name \"" + module_name + "\" does not exist.")
|
logger.errorf("core", "Getting module failed: A custom module with the name \"" + module_name + "\" does not exist.")
|
||||||
return null
|
return null
|
||||||
return custom_modules[module_name]
|
return custom_modules[module_name]
|
||||||
|
|
||||||
|
@ -191,12 +191,12 @@ func get_custom_module(module_name: String) -> CoreBaseModule:
|
||||||
## Loads a (new) configuration file and applies it to all modules.
|
## Loads a (new) configuration file and applies it to all modules.
|
||||||
func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
|
func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
|
||||||
var initialized = config != null
|
var initialized = config != null
|
||||||
if initialized: logger.verbf("Core", "Reloading CORE's configuration")
|
if initialized: logger.verbf("core", "Reloading CORE's configuration")
|
||||||
if config != null: config.queue_free()
|
if config != null: config.queue_free()
|
||||||
config = new_config
|
config = new_config
|
||||||
if is_devmode(): # Override configuration in development mode
|
if is_devmode(): # Override configuration in development mode
|
||||||
config.logger_level = CoreTypes.LoggerLevel.VERB
|
config.logger_level = CoreTypes.LoggerLevel.VERB
|
||||||
if initialized: logger.verbf("Core", "Overrode configuration (development mode)")
|
if initialized: logger.verbf("core", "Overrode configuration (development mode)")
|
||||||
if initialized: apply_configuration()
|
if initialized: apply_configuration()
|
||||||
|
|
||||||
# Call _pull_config() functions
|
# Call _pull_config() functions
|
||||||
|
@ -204,16 +204,16 @@ func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new(
|
||||||
## [br]
|
## [br]
|
||||||
## [b]NEVER call this yourself unless you know what you are doing![/b]
|
## [b]NEVER call this yourself unless you know what you are doing![/b]
|
||||||
func apply_configuration() -> void:
|
func apply_configuration() -> void:
|
||||||
logger.verbf("Core", "Applying configuration")
|
logger.verbf("core", "Applying configuration")
|
||||||
if is_devmode(): logger.warnf("Core", "The CORE Framework is in development mode. Here be dragons!")
|
if is_devmode(): logger.warnf("core", "The CORE Framework is in development mode. Here be dragons!")
|
||||||
if config.headless: logger.warnf("Core", "CORE is in headless mode. Certain modules will not work as expected.")
|
if config.headless: logger.warnf("core", "CORE is in headless mode. Certain modules will not work as expected.")
|
||||||
if !config.custom_modules:
|
if !config.custom_modules:
|
||||||
logger.verbf("Core", "Removing all custom modules (custom modules support is disabled)")
|
logger.verbf("core", "Removing all custom modules (custom modules support is disabled)")
|
||||||
for module in custom_modules: unregister_custom_module(module)
|
for module in custom_modules: unregister_custom_module(module)
|
||||||
for module in modules: get(module)._pull_config()
|
for module in modules: get(module)._pull_config()
|
||||||
if config.custom_modules:
|
if config.custom_modules:
|
||||||
for module in custom_modules:
|
for module in custom_modules:
|
||||||
logger.diagf("Core", "Updating configuration for custom module \"" + module.name + "\"")
|
logger.diagf("core", "Updating configuration for custom module \"" + module.name + "\"")
|
||||||
module._pull_config()
|
module._pull_config()
|
||||||
|
|
||||||
# Return development mode status
|
# Return development mode status
|
||||||
|
@ -249,7 +249,7 @@ func get_formatted_string(string: String) -> String:
|
||||||
CoreTypes.VersionType.ALPHA:
|
CoreTypes.VersionType.ALPHA:
|
||||||
string = string.replace("%type%", "Alpha")
|
string = string.replace("%type%", "Alpha")
|
||||||
string = string.replace("%type_technical%", "a")
|
string = string.replace("%type_technical%", "a")
|
||||||
_: await logger.crashf("Core", "Invalid version type " + str(version_type), true)
|
_: await logger.crashf("core", "Invalid version type " + str(version_type), true)
|
||||||
# Development mode
|
# Development mode
|
||||||
if is_devmode(): string = string.replace("%devmode%", "Enabled")
|
if is_devmode(): string = string.replace("%devmode%", "Enabled")
|
||||||
else: string = string.replace("%devmode%", "Disabled")
|
else: string = string.replace("%devmode%", "Disabled")
|
||||||
|
|
22
src/erm.gd
22
src/erm.gd
|
@ -34,14 +34,14 @@ func _cleanup() -> void:
|
||||||
func generate_id() -> int:
|
func generate_id() -> int:
|
||||||
var id = randi()
|
var id = randi()
|
||||||
if list_queue.has(id) or list_active.has(id): return generate_id()
|
if list_queue.has(id) or list_active.has(id): return generate_id()
|
||||||
logger.diagf("Edl", "Generated new download id " + str(id))
|
logger.diagf("erm", "Generated new download id " + str(id))
|
||||||
return id
|
return id
|
||||||
|
|
||||||
func awaited_request(url: String, parse_utf8: bool, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary:
|
func awaited_request(url: String, parse_utf8: bool, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary:
|
||||||
logger.verbf("Edl", "Creating awaited request")
|
logger.verbf("erm", "Creating awaited request")
|
||||||
var id: int = create_download(url, method, headers, data)
|
var id: int = create_download(url, method, headers, data)
|
||||||
start_download(id, parse_utf8)
|
start_download(id, parse_utf8)
|
||||||
logger.diagf("Edl", "Waiting for request " + str(id) + " to finish")
|
logger.diagf("erm", "Waiting for request " + str(id) + " to finish")
|
||||||
while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout
|
while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout
|
||||||
var dldata: Dictionary = list_complete[id]
|
var dldata: Dictionary = list_complete[id]
|
||||||
list_complete.erase(id)
|
list_complete.erase(id)
|
||||||
|
@ -56,34 +56,34 @@ func oneline_awaited_request(url: String, return_utf8: bool = true, ignore_http_
|
||||||
else: return dldata["body"]
|
else: return dldata["body"]
|
||||||
|
|
||||||
func batch_awaited_request(urls: PackedStringArray, parse_utf8: bool, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Array[Dictionary]:
|
func batch_awaited_request(urls: PackedStringArray, parse_utf8: bool, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Array[Dictionary]:
|
||||||
logger.verbf("Edl", "Creating " + str(urls.size()) + " awaited request(s)")
|
logger.verbf("erm", "Creating " + str(urls.size()) + " awaited request(s)")
|
||||||
var dldata: Array[Dictionary]= []
|
var dldata: Array[Dictionary]= []
|
||||||
for url in urls:
|
for url in urls:
|
||||||
var id: int = create_download(url, method, headers, data)
|
var id: int = create_download(url, method, headers, data)
|
||||||
start_download(id, parse_utf8)
|
start_download(id, parse_utf8)
|
||||||
logger.diagf("Edl", "Waiting for request " + str(id) + " to finish")
|
logger.diagf("erm", "Waiting for request " + str(id) + " to finish")
|
||||||
while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout
|
while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout
|
||||||
dldata.append(list_complete[id])
|
dldata.append(list_complete[id])
|
||||||
list_complete.erase(id)
|
list_complete.erase(id)
|
||||||
return dldata
|
return dldata
|
||||||
|
|
||||||
func create_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), body: String = "") -> int:
|
func create_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), body: String = "") -> int:
|
||||||
logger.verbf("Edl", "Creating new request\n-> URL: " + url + "\n-> Method: " + str(method) + "\nHeaders: " + str(headers.size()) + "\nBody size: " + str(body.length()) + " Characters")
|
logger.verbf("erm", "Creating new request\n-> URL: " + url + "\n-> Method: " + str(method) + "\nHeaders: " + str(headers.size()) + "\nBody size: " + str(body.length()) + " Characters")
|
||||||
var id = generate_id()
|
var id = generate_id()
|
||||||
list_queue.merge({ id: { "url": url, "method": method, "headers": headers, "body": body } })
|
list_queue.merge({ id: { "url": url, "method": method, "headers": headers, "body": body } })
|
||||||
return id
|
return id
|
||||||
|
|
||||||
func start_download(id: int, parse_utf8: bool) -> void:
|
func start_download(id: int, parse_utf8: bool) -> void:
|
||||||
logger.verbf("Edl", "Starting request " + str(id))
|
logger.verbf("erm", "Starting request " + str(id))
|
||||||
list_active.merge({ id: list_queue[id] })
|
list_active.merge({ id: list_queue[id] })
|
||||||
list_queue.erase(id)
|
list_queue.erase(id)
|
||||||
logger.diagf("Edl", "Creating new HTTPRequest \"Request #" + str(id) + "\"")
|
logger.diagf("erm", "Creating new HTTPRequest \"Request #" + str(id) + "\"")
|
||||||
var download: HTTPRequest = HTTPRequest.new()
|
var download: HTTPRequest = HTTPRequest.new()
|
||||||
download.name = "Request #" + str(id)
|
download.name = "Request #" + str(id)
|
||||||
download.accept_gzip = true
|
download.accept_gzip = true
|
||||||
download.use_threads = true
|
download.use_threads = true
|
||||||
var lambda: Callable = func(result: int, http_code: int, headers: PackedStringArray, body: PackedByteArray, httprequest: HTTPRequest) -> void:
|
var lambda: Callable = func(result: int, http_code: int, headers: PackedStringArray, body: PackedByteArray, httprequest: HTTPRequest) -> void:
|
||||||
logger.verbf("Edl", "Request " + str(id) + " completed\nResult: " + str(result) + "\nHTTP response code: " + str(http_code) + "\nHeaders: " + str(headers.size()) + "\nBody size: " + str(body.size()) + " Bytes // " + str(core.misc.byte2mib(body.size(), true)) + " MiB")
|
logger.verbf("erm", "Request " + str(id) + " completed\nResult: " + str(result) + "\nHTTP response code: " + str(http_code) + "\nHeaders: " + str(headers.size()) + "\nBody size: " + str(body.size()) + " Bytes // " + str(core.misc.byte2mib(body.size(), true)) + " MiB")
|
||||||
list_complete.merge({ id: { "result": result, "http_code": http_code, "headers": headers, "body": body, "body_utf8": body.get_string_from_utf8() if !parse_utf8 else "" } })
|
list_complete.merge({ id: { "result": result, "http_code": http_code, "headers": headers, "body": body, "body_utf8": body.get_string_from_utf8() if !parse_utf8 else "" } })
|
||||||
list_active.erase(id)
|
list_active.erase(id)
|
||||||
remove_child(httprequest)
|
remove_child(httprequest)
|
||||||
|
@ -95,9 +95,9 @@ func start_download(id: int, parse_utf8: bool) -> void:
|
||||||
func is_download_complete(id: int) -> bool: return list_complete.has(id)
|
func is_download_complete(id: int) -> bool: return list_complete.has(id)
|
||||||
|
|
||||||
func clean_queue() -> void:
|
func clean_queue() -> void:
|
||||||
logger.verbf("Edl", "Cleaning request queue")
|
logger.verbf("erm", "Cleaning request queue")
|
||||||
list_queue.clear()
|
list_queue.clear()
|
||||||
|
|
||||||
func clean_completed() -> void:
|
func clean_completed() -> void:
|
||||||
logger.verbf("Edl", "Cleaning completed requests")
|
logger.verbf("erm", "Cleaning completed requests")
|
||||||
list_complete.clear()
|
list_complete.clear()
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
extends CoreBaseModule
|
extends CoreBaseModule
|
||||||
|
|
||||||
func quit_safely(exitcode: int = 0) -> void:
|
func quit_safely(exitcode: int = 0) -> void:
|
||||||
logger.infof("Misc", "Shutting down (code " + str(exitcode) + ")")
|
logger.infof("misc", "Shutting down (code " + str(exitcode) + ")")
|
||||||
logger.diagf("Misc", "Waiting for log messages to be flushed")
|
logger.diagf("misc", "Waiting for log messages to be flushed")
|
||||||
await get_tree().create_timer(0.25).timeout
|
await get_tree().create_timer(0.25).timeout
|
||||||
await core.cleanup()
|
await core.cleanup()
|
||||||
get_tree().quit(exitcode)
|
get_tree().quit(exitcode)
|
||||||
|
@ -49,10 +49,10 @@ func format_stringarray(array: Array[String], item_before: String = "", item_aft
|
||||||
var output: String = ""
|
var output: String = ""
|
||||||
|
|
||||||
if array.size() == 0:
|
if array.size() == 0:
|
||||||
logger.warnf("Misc", "Unable to format a string with a size of 0")
|
logger.warnf("misc", "Unable to format a string with a size of 0")
|
||||||
return ""
|
return ""
|
||||||
elif array.size() == 1:
|
elif array.size() == 1:
|
||||||
logger.warnf("Misc", "Unable to format a string with a size of 1")
|
logger.warnf("misc", "Unable to format a string with a size of 1")
|
||||||
return array[0]
|
return array[0]
|
||||||
|
|
||||||
for item in array:
|
for item in array:
|
||||||
|
|
26
src/sms.gd
26
src/sms.gd
|
@ -47,15 +47,15 @@ func _cleanup() -> void:
|
||||||
func _pull_config() -> void:
|
func _pull_config() -> void:
|
||||||
if core.config.headless:
|
if core.config.headless:
|
||||||
# Remove all scenes
|
# Remove all scenes
|
||||||
logger.verbf("Sms", "Removing all scenes (triggered by headless mode)")
|
logger.verbf("sms", "Removing all scenes (triggered by headless mode)")
|
||||||
for scene in scenes: remove_scene(scene, true)
|
for scene in scenes: remove_scene(scene, true)
|
||||||
|
|
||||||
# Add a scene to some scene collection
|
# Add a scene to some scene collection
|
||||||
func add_scene(sname: String, sclass: Node, type: CoreTypes.SceneType) -> bool:
|
func add_scene(sname: String, sclass: Node, type: CoreTypes.SceneType) -> bool:
|
||||||
if core.config.headless: return false
|
if core.config.headless: return false
|
||||||
logger.verbf("Sms", "Adding scene \"" + sname + "\" of type " + str(type))
|
logger.verbf("sms", "Adding scene \"" + sname + "\" of type " + str(type))
|
||||||
if exists(sname) != CoreTypes.SceneType.NONE:
|
if exists(sname) != CoreTypes.SceneType.NONE:
|
||||||
logger.errorf("Sms", "Scene with name \"" + sname + "\" already exists")
|
logger.errorf("sms", "Scene with name \"" + sname + "\" already exists")
|
||||||
return true
|
return true
|
||||||
sclass.name = sname
|
sclass.name = sname
|
||||||
match(type):
|
match(type):
|
||||||
|
@ -65,17 +65,17 @@ func add_scene(sname: String, sclass: Node, type: CoreTypes.SceneType) -> bool:
|
||||||
CoreTypes.SceneType.MAIN: scenes_main.add_child(sclass)
|
CoreTypes.SceneType.MAIN: scenes_main.add_child(sclass)
|
||||||
CoreTypes.SceneType.BACKGROUND: scenes_background.add_child(sclass)
|
CoreTypes.SceneType.BACKGROUND: scenes_background.add_child(sclass)
|
||||||
CoreTypes.SceneType.NONE:
|
CoreTypes.SceneType.NONE:
|
||||||
logger.errorf("Sms", "CoreTypes.SceneType.NONE is not a valid scene type")
|
logger.errorf("sms", "CoreTypes.SceneType.NONE is not a valid scene type")
|
||||||
return false
|
return false
|
||||||
_: await logger.crashf("Sms", "Invalid SceneType " + str(type), true)
|
_: await logger.crashf("sms", "Invalid SceneType " + str(type), true)
|
||||||
scenes.merge({ sname: { "type": type, "class": sclass } })
|
scenes.merge({ sname: { "type": type, "class": sclass } })
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# Remove a scene from some scene collection
|
# Remove a scene from some scene collection
|
||||||
func remove_scene(sname: String, force_remove: bool = false) -> bool:
|
func remove_scene(sname: String, force_remove: bool = false) -> bool:
|
||||||
if core.config.headless and !force_remove: return false
|
if core.config.headless and !force_remove: return false
|
||||||
if force_remove: await logger.crashf("Sms", "force_remove = true is not allowed", true)
|
if force_remove: await logger.crashf("sms", "force_remove = true is not allowed", true)
|
||||||
logger.verbf("Sms", "Removing scene \"" + sname + "\"")
|
logger.verbf("sms", "Removing scene \"" + sname + "\"")
|
||||||
match(exists(sname)):
|
match(exists(sname)):
|
||||||
CoreTypes.SceneType.DEBUG:
|
CoreTypes.SceneType.DEBUG:
|
||||||
scenes_debug.remove_child(scenes[sname]["class"])
|
scenes_debug.remove_child(scenes[sname]["class"])
|
||||||
|
@ -93,9 +93,9 @@ func remove_scene(sname: String, force_remove: bool = false) -> bool:
|
||||||
scenes_background.remove_child(scenes[sname]["class"])
|
scenes_background.remove_child(scenes[sname]["class"])
|
||||||
scenes[sname]["class"].queue_free()
|
scenes[sname]["class"].queue_free()
|
||||||
CoreTypes.SceneType.NONE:
|
CoreTypes.SceneType.NONE:
|
||||||
logger.errorf("Sms", "Scene \"" + sname + "\" does not exist")
|
logger.errorf("sms", "Scene \"" + sname + "\" does not exist")
|
||||||
return false
|
return false
|
||||||
_: await logger.crashf("Sms", "Invalid SceneType " + str(exists(sname)), true)
|
_: await logger.crashf("sms", "Invalid SceneType " + str(exists(sname)), true)
|
||||||
scenes.erase(sname)
|
scenes.erase(sname)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ func get_scene(sname: String) -> Node:
|
||||||
CoreTypes.SceneType.MENU: return scenes[sname]["class"]
|
CoreTypes.SceneType.MENU: return scenes[sname]["class"]
|
||||||
CoreTypes.SceneType.MAIN: return scenes[sname]["class"]
|
CoreTypes.SceneType.MAIN: return scenes[sname]["class"]
|
||||||
CoreTypes.SceneType.BACKGROUND: return scenes[sname]["class"]
|
CoreTypes.SceneType.BACKGROUND: return scenes[sname]["class"]
|
||||||
CoreTypes.SceneType.NONE: logger.errorf("Sms", "Scene \"" + sname + "\" does not exist")
|
CoreTypes.SceneType.NONE: logger.errorf("sms", "Scene \"" + sname + "\" does not exist")
|
||||||
_: await logger.crashf("Sms", "Invalid SceneType " + str(exists(sname)), true)
|
_: await logger.crashf("sms", "Invalid SceneType " + str(exists(sname)), true)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
# Return a scene collection for scene manipulation
|
# Return a scene collection for scene manipulation
|
||||||
|
@ -121,8 +121,8 @@ func get_scene_collection(type: CoreTypes.SceneType) -> Node:
|
||||||
CoreTypes.SceneType.MENU: return scenes_menu
|
CoreTypes.SceneType.MENU: return scenes_menu
|
||||||
CoreTypes.SceneType.MAIN: return scenes_main
|
CoreTypes.SceneType.MAIN: return scenes_main
|
||||||
CoreTypes.SceneType.BACKGROUND: return scenes_background
|
CoreTypes.SceneType.BACKGROUND: return scenes_background
|
||||||
CoreTypes.SceneType.NONE: logger.errorf("Sms", "No scene collection was found for CoreTypes.SceneType.NONE")
|
CoreTypes.SceneType.NONE: logger.errorf("sms", "No scene collection was found for CoreTypes.SceneType.NONE")
|
||||||
_: await logger.crashf("Sms", "Invalid SceneType " + str(type), true)
|
_: await logger.crashf("sms", "Invalid SceneType " + str(type), true)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
# Return scenes in some scene collection
|
# Return scenes in some scene collection
|
||||||
|
|
|
@ -22,40 +22,40 @@ var storage_location: String = ""
|
||||||
|
|
||||||
func open_storage(location: String, create_new: bool = true, sanity_check: bool = true, fail_on_sanity_check: bool = false) -> bool:
|
func open_storage(location: String, create_new: bool = true, sanity_check: bool = true, fail_on_sanity_check: bool = false) -> bool:
|
||||||
if is_open:
|
if is_open:
|
||||||
logger.errorf("Storage", "Failed to open storage: A storage file is already open")
|
logger.errorf("storage", "Failed to open storage: A storage file is already open")
|
||||||
return false
|
return false
|
||||||
logger.verbf("Storage", "Opening storage file at \"" + location + "\"")
|
logger.verbf("storage", "Opening storage file at \"" + location + "\"")
|
||||||
var file: FileAccess
|
var file: FileAccess
|
||||||
if !FileAccess.file_exists(location):
|
if !FileAccess.file_exists(location):
|
||||||
if create_new:
|
if create_new:
|
||||||
file = FileAccess.open(location, FileAccess.WRITE)
|
file = FileAccess.open(location, FileAccess.WRITE)
|
||||||
if file == null:
|
if file == null:
|
||||||
await logger.crashf("Storage", "Could not open storage file at \"" + location + "\": Failed with code " + str(FileAccess.get_open_error()))
|
await logger.crashf("storage", "Could not open storage file at \"" + location + "\": Failed with code " + str(FileAccess.get_open_error()))
|
||||||
return false
|
return false
|
||||||
file.store_string("{}")
|
file.store_string("{}")
|
||||||
file.close()
|
file.close()
|
||||||
else:
|
else:
|
||||||
logger.errorf("Storage", "Failed to open storage: create_new is set to false")
|
logger.errorf("storage", "Failed to open storage: create_new is set to false")
|
||||||
return false
|
return false
|
||||||
file = FileAccess.open(location, FileAccess.READ)
|
file = FileAccess.open(location, FileAccess.READ)
|
||||||
var storage_temp: Variant = file.get_as_text()
|
var storage_temp: Variant = file.get_as_text()
|
||||||
file.close()
|
file.close()
|
||||||
storage_temp = JSON.parse_string(storage_temp)
|
storage_temp = JSON.parse_string(storage_temp)
|
||||||
if typeof(storage_temp) != TYPE_DICTIONARY:
|
if typeof(storage_temp) != TYPE_DICTIONARY:
|
||||||
logger.errorf("Storage", "Failed to open storage: Parsed storage file is of type " + str(typeof(storage_temp)))
|
logger.errorf("storage", "Failed to open storage: Parsed storage file is of type " + str(typeof(storage_temp)))
|
||||||
return false
|
return false
|
||||||
if sanity_check:
|
if sanity_check:
|
||||||
var check_result: Array[String] = perform_sanity_check(storage_temp)
|
var check_result: Array[String] = perform_sanity_check(storage_temp)
|
||||||
if check_result.size() != 0:
|
if check_result.size() != 0:
|
||||||
if fail_on_sanity_check:
|
if fail_on_sanity_check:
|
||||||
logger.errorf("Storage", "Sanity check failed (stopping):")
|
logger.errorf("storage", "Sanity check failed (stopping):")
|
||||||
for error in check_result:
|
for error in check_result:
|
||||||
logger.errorf("Storage", "-> " + error)
|
logger.errorf("storage", "-> " + error)
|
||||||
return false
|
return false
|
||||||
else:
|
else:
|
||||||
logger.warnf("Storage", "Sanity check failed (continuing anyway):")
|
logger.warnf("storage", "Sanity check failed (continuing anyway):")
|
||||||
for error in check_result:
|
for error in check_result:
|
||||||
logger.warnf("Storage", "-> " + error)
|
logger.warnf("storage", "-> " + error)
|
||||||
storage = storage_temp
|
storage = storage_temp
|
||||||
storage_location = location
|
storage_location = location
|
||||||
is_open = true
|
is_open = true
|
||||||
|
@ -63,90 +63,90 @@ func open_storage(location: String, create_new: bool = true, sanity_check: bool
|
||||||
|
|
||||||
func close_storage() -> bool:
|
func close_storage() -> bool:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errorf("Storage", "Failed to close storage: No storage file is open")
|
logger.errorf("storage", "Failed to close storage: No storage file is open")
|
||||||
return false
|
return false
|
||||||
logger.verbf("Storage", "Closing storage file")
|
logger.verbf("storage", "Closing storage file")
|
||||||
storage = {}
|
storage = {}
|
||||||
is_open = false
|
is_open = false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func save_storage() -> bool:
|
func save_storage() -> bool:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errorf("Storage", "Failed to save storage: No storage file is open")
|
logger.errorf("storage", "Failed to save storage: No storage file is open")
|
||||||
return false
|
return false
|
||||||
var file: FileAccess = FileAccess.open(storage_location, FileAccess.WRITE)
|
var file: FileAccess = FileAccess.open(storage_location, FileAccess.WRITE)
|
||||||
if file == null:
|
if file == null:
|
||||||
await logger.crashf("Storage", "Could not open storage file at \"" + storage_location + "\": Failed with code " + str(FileAccess.get_open_error()))
|
await logger.crashf("storage", "Could not open storage file at \"" + storage_location + "\": Failed with code " + str(FileAccess.get_open_error()))
|
||||||
return false
|
return false
|
||||||
logger.diagf("Storage", "Writing storage file to disk")
|
logger.diagf("storage", "Writing storage file to disk")
|
||||||
file.store_string(JSON.stringify(storage))
|
file.store_string(JSON.stringify(storage))
|
||||||
file.close()
|
file.close()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func nuke_storage(autosave: bool = true) -> bool:
|
func nuke_storage(autosave: bool = true) -> bool:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errorf("Storage", "Failed to nuke storage: No storage file is open")
|
logger.errorf("storage", "Failed to nuke storage: No storage file is open")
|
||||||
return false
|
return false
|
||||||
logger.warnf("Storage", "Nuking storage")
|
logger.warnf("storage", "Nuking storage")
|
||||||
storage = {}
|
storage = {}
|
||||||
if autosave: save_storage()
|
if autosave: save_storage()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func get_key(key: String, default: Variant) -> Variant:
|
func get_key(key: String, default: Variant) -> Variant:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errorf("Storage", "Failed to get key: No storage file is open")
|
logger.errorf("storage", "Failed to get key: No storage file is open")
|
||||||
return NAN
|
return NAN
|
||||||
logger.diagf("Storage", "Returning storage key \"" + key + "\" (default='" + default + "')")
|
logger.diagf("storage", "Returning storage key \"" + key + "\" (default='" + default + "')")
|
||||||
return storage.get(key, default)
|
return storage.get(key, default)
|
||||||
|
|
||||||
func set_key(key: String, value: Variant, overwrite: bool = true, autosave: bool = true) -> bool:
|
func set_key(key: String, value: Variant, overwrite: bool = true, autosave: bool = true) -> bool:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errorf("Storage", "Failed to set key: No storage file is open")
|
logger.errorf("storage", "Failed to set key: No storage file is open")
|
||||||
return false
|
return false
|
||||||
logger.diagf("Storage", "Updating storage key \"" + key + "\" with value '" + str(value) + "' (overwrite='" + str(overwrite) + "' autosave='" + str(autosave) + "'")
|
logger.diagf("storage", "Updating storage key \"" + key + "\" with value '" + str(value) + "' (overwrite='" + str(overwrite) + "' autosave='" + str(autosave) + "'")
|
||||||
storage.merge({key: value}, overwrite)
|
storage.merge({key: value}, overwrite)
|
||||||
if autosave: save_storage()
|
if autosave: save_storage()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func del_key(key: String, autosave: bool = true) -> bool:
|
func del_key(key: String, autosave: bool = true) -> bool:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errof("Storage", "Failed to delete key: No storage file is open")
|
logger.errof("storage", "Failed to delete key: No storage file is open")
|
||||||
return false
|
return false
|
||||||
logger.diagf("Storage", "Deleting storage key \"" + key + "\" (autosave='" + str(autosave) + "')")
|
logger.diagf("storage", "Deleting storage key \"" + key + "\" (autosave='" + str(autosave) + "')")
|
||||||
storage.erase(key)
|
storage.erase(key)
|
||||||
if autosave: save_storage()
|
if autosave: save_storage()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func get_dict() -> Dictionary:
|
func get_dict() -> Dictionary:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errorf("Storage", "Failed to get dictionary: No storage file is open")
|
logger.errorf("storage", "Failed to get dictionary: No storage file is open")
|
||||||
return {}
|
return {}
|
||||||
logger.verbf("Storage", "Returning storage dictionary")
|
logger.verbf("storage", "Returning storage dictionary")
|
||||||
return storage
|
return storage
|
||||||
|
|
||||||
func save_dict(dict: Dictionary, sanity_check: bool = true, fail_on_sanity_check: bool = false, autosave: bool = true) -> bool:
|
func save_dict(dict: Dictionary, sanity_check: bool = true, fail_on_sanity_check: bool = false, autosave: bool = true) -> bool:
|
||||||
if !is_open:
|
if !is_open:
|
||||||
logger.errorf("Storage", "Failed to save dictionary: No storage file is open")
|
logger.errorf("storage", "Failed to save dictionary: No storage file is open")
|
||||||
return false
|
return false
|
||||||
logger.verbf("Storage", "Saving custom dictionary as storage")
|
logger.verbf("storage", "Saving custom dictionary as storage")
|
||||||
if sanity_check:
|
if sanity_check:
|
||||||
var check_result: Array[String] = perform_sanity_check(dict)
|
var check_result: Array[String] = perform_sanity_check(dict)
|
||||||
if check_result.size() != 0:
|
if check_result.size() != 0:
|
||||||
if fail_on_sanity_check:
|
if fail_on_sanity_check:
|
||||||
logger.errorf("Storage", "Sanity check failed (stopping):")
|
logger.errorf("storage", "Sanity check failed (stopping):")
|
||||||
for error in check_result:
|
for error in check_result:
|
||||||
logger.errorf("Storage", "-> " + error)
|
logger.errorf("storage", "-> " + error)
|
||||||
return false
|
return false
|
||||||
else:
|
else:
|
||||||
logger.warnf("Storage", "Sanity check failed (continuing anyway):")
|
logger.warnf("storage", "Sanity check failed (continuing anyway):")
|
||||||
for error in check_result:
|
for error in check_result:
|
||||||
logger.warnf("Storage", "-> " + error)
|
logger.warnf("storage", "-> " + error)
|
||||||
storage = dict
|
storage = dict
|
||||||
if autosave: save_storage()
|
if autosave: save_storage()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func perform_sanity_check(storage_check: Dictionary) -> Array[String]:
|
func perform_sanity_check(storage_check: Dictionary) -> Array[String]:
|
||||||
logger.verbf("Storage", "Performing a sanity check on some storage dictionary")
|
logger.verbf("storage", "Performing a sanity check on some storage dictionary")
|
||||||
var errors: Array[String] = []
|
var errors: Array[String] = []
|
||||||
for key in storage_check:
|
for key in storage_check:
|
||||||
if typeof(key) != TYPE_STRING:
|
if typeof(key) != TYPE_STRING:
|
||||||
|
@ -155,5 +155,5 @@ func perform_sanity_check(storage_check: Dictionary) -> Array[String]:
|
||||||
if typeof(storage_check[key]) != TYPE_NIL and typeof(storage_check[key]) != TYPE_STRING and typeof(storage_check[key]) != TYPE_INT and typeof(storage_check[key]) != TYPE_FLOAT and typeof(storage_check[key]) != TYPE_BOOL and typeof(storage_check[key]) != TYPE_ARRAY and typeof(storage_check[key]) != TYPE_DICTIONARY:
|
if typeof(storage_check[key]) != TYPE_NIL and typeof(storage_check[key]) != TYPE_STRING and typeof(storage_check[key]) != TYPE_INT and typeof(storage_check[key]) != TYPE_FLOAT and typeof(storage_check[key]) != TYPE_BOOL and typeof(storage_check[key]) != TYPE_ARRAY and typeof(storage_check[key]) != TYPE_DICTIONARY:
|
||||||
errors.append("The value of \"" + key + "\" is not null, a string, an integer, a float, boolean, array or dictionary (type '" + type_string(typeof(key)) + "')")
|
errors.append("The value of \"" + key + "\" is not null, a string, an integer, a float, boolean, array or dictionary (type '" + type_string(typeof(key)) + "')")
|
||||||
|
|
||||||
logger.verbf("Storage", "Completed sanity check with " + str(errors.size()) + " errors")
|
logger.verbf("storage", "Completed sanity check with " + str(errors.size()) + " errors")
|
||||||
return errors
|
return errors
|
||||||
|
|
Loading…
Reference in a new issue