From 8455c2e1eb522d305e0a3bd4b665c0ca6f2e5d25 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 14 Apr 2024 23:52:12 +0200 Subject: [PATCH] Rename sms.gd arguments to something meaningful --- docs/docs/reference/sms.md | 14 +++--- src/sms.gd | 98 +++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/docs/docs/reference/sms.md b/docs/docs/reference/sms.md index 6e1a6e7..b5bc182 100644 --- a/docs/docs/reference/sms.md +++ b/docs/docs/reference/sms.md @@ -44,28 +44,28 @@ Do not modify this. A list of all loaded scenes ## Functions -### *bool* add_scene(*String* sname, *Node* sclass, *CoreTypes.SceneType* type) +### *bool* add_scene(*String* scene_name, *Node* scene_class, *CoreTypes.SceneType* scene_type) Adds a scene to some scene collection. -### *bool* remove_scene(*String* sname, *bool* force_remove = *false*) +### *bool* remove_scene(*String* scene_name, *bool* force_remove = *false*) :::danger Don't set `force_remove` to `true`, thanks! ::: Removes a scene from some scene collection. -### *Node* get_scene(*String* sname) +### *Node* get_scene(*String* scene_name) Returns a scene from some scene collection. \ \ Returns `null` if no scene with that name was found. -### *Node* get_scene_collection(*CoreTypes.SceneType* type) +### *Node* get_scene_collection(*CoreTypes.SceneType* scene_type) :::danger Don't change any properties of the scene collection or free it, otherwise you may cause breakage. ::: Returns a scene collection node. \ Useful if you want to change a child's index. -### *Array[Node]* get_scene_collection_list(*CoreTypes.SceneType* type) +### *Array[Node]* get_scene_collection_list(*CoreTypes.SceneType* scene_type) Returns a list of all loaded scenes in some scene collection. -### *int* get_scene_collection_count(*CoreTypes.SceneType* type) +### *int* get_scene_collection_count(*CoreTypes.SceneType* scene_type) Returns the number of loaded scenes in some scene collection. -### *CoresTypes.SceneType* exists(*String* sname) +### *CoresTypes.SceneType* exists(*String* scene_name) Returns the scene collection a scene is loaded in. Returns `CoreTypes.SceneType.NONE` if no scene with that name was found. diff --git a/src/sms.gd b/src/sms.gd index 26138b5..c244855 100644 --- a/src/sms.gd +++ b/src/sms.gd @@ -64,109 +64,109 @@ func _pull_config() -> void: # +++ scene management +++ ## Adds a scene to some scene collection. -func add_scene(sname: String, sclass: Node, type: CoreTypes.SceneType) -> bool: +func add_scene(scene_name: String, scene_class: Node, scene_type: CoreTypes.SceneType) -> bool: if core.config.headless: return false - loggeri.verb("Adding scene \"" + sname + "\" of type " + str(type)) - if exists(sname) != CoreTypes.SceneType.NONE: - loggeri.error("Scene with name \"" + sname + "\" already exists") + loggeri.verb("Adding scene \"" + scene_name + "\" of type " + str(scene_type)) + if exists(scene_name) != CoreTypes.SceneType.NONE: + loggeri.error("Scene with name \"" + scene_name + "\" already exists") return false - if typeof(sclass) != TYPE_OBJECT or !sclass.is_class("Node"): - loggeri.error("Scene class \"" + sname + "\" is not of type Node") + if typeof(scene_class) != TYPE_OBJECT or !scene_class.is_class("Node"): + loggeri.error("Scene class \"" + scene_name + "\" is not of type Node") return false - 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) + scene_class.name = scene_name + match(scene_type): + CoreTypes.SceneType.DEBUG: scenes_debug.add_child(scene_class) + CoreTypes.SceneType.CUTSCENE: scenes_cutscene.add_child(scene_class) + CoreTypes.SceneType.MENU: scenes_menu.add_child(scene_class) + CoreTypes.SceneType.MAIN: scenes_main.add_child(scene_class) + CoreTypes.SceneType.BACKGROUND: scenes_background.add_child(scene_class) CoreTypes.SceneType.NONE: loggeri.error("CoreTypes.SceneType.NONE is not a valid scene type") return false - _: await loggeri.crash("Invalid SceneType " + str(type)) - scenes.merge({ sname: { "type": type, "class": sclass } }) + _: await loggeri.crash("Invalid SceneType " + str(scene_type)) + scenes.merge({ scene_name: { "type": scene_type, "class": scene_class } }) return true ## Removes a scene from some scene collection.[br] ## [b]Danger: [i]Don't set [code]force_remove[/code] to [code]true[/code], thanks![/i][/b] -func remove_scene(sname: String, force_remove: bool = false) -> bool: +func remove_scene(scene_name: String, force_remove: bool = false) -> bool: if core.config.headless and !force_remove: return false if force_remove: await loggeri.crash("force_remove = true is not allowed") - loggeri.verb("Removing scene \"" + sname + "\"") - match(exists(sname)): + loggeri.verb("Removing scene \"" + scene_name + "\"") + match(exists(scene_name)): CoreTypes.SceneType.DEBUG: - scenes_debug.remove_child(scenes[sname]["class"]) - scenes[sname]["class"].queue_free() + scenes_debug.remove_child(scenes[scene_name]["class"]) + scenes[scene_name]["class"].queue_free() CoreTypes.SceneType.CUTSCENE: - scenes_cutscene.remove_child(scenes[sname]["class"]) - scenes[sname]["class"].queue_free() + scenes_cutscene.remove_child(scenes[scene_name]["class"]) + scenes[scene_name]["class"].queue_free() CoreTypes.SceneType.MENU: - scenes_menu.remove_child(scenes[sname]["class"]) - scenes[sname]["class"].queue_free() + scenes_menu.remove_child(scenes[scene_name]["class"]) + scenes[scene_name]["class"].queue_free() CoreTypes.SceneType.MAIN: - scenes_main.remove_child(scenes[sname]["class"]) - scenes[sname]["class"].queue_free() + scenes_main.remove_child(scenes[scene_name]["class"]) + scenes[scene_name]["class"].queue_free() CoreTypes.SceneType.BACKGROUND: - scenes_background.remove_child(scenes[sname]["class"]) - scenes[sname]["class"].queue_free() + scenes_background.remove_child(scenes[scene_name]["class"]) + scenes[scene_name]["class"].queue_free() CoreTypes.SceneType.NONE: - loggeri.error("Scene \"" + sname + "\" does not exist") + loggeri.error("Scene \"" + scene_name + "\" does not exist") return false - _: await loggeri.crash("Invalid SceneType " + str(exists(sname))) - scenes.erase(sname) + _: await loggeri.crash("Invalid SceneType " + str(exists(scene_name))) + scenes.erase(scene_name) return true # +++ getters +++ ## Returns a scene from some scene collection.[br] ## [br] ## Returns [code]null[/code] if no scene with that name was found. -func get_scene(sname: String) -> Node: +func get_scene(scene_name: 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: loggeri.error("Scene \"" + sname + "\" does not exist") - _: await loggeri.crash("Invalid SceneType " + str(exists(sname))) + match(exists(scene_name)): + CoreTypes.SceneType.DEBUG: return scenes[scene_name]["class"] + CoreTypes.SceneType.CUTSCENE: return scenes[scene_name]["class"] + CoreTypes.SceneType.MENU: return scenes[scene_name]["class"] + CoreTypes.SceneType.MAIN: return scenes[scene_name]["class"] + CoreTypes.SceneType.BACKGROUND: return scenes[scene_name]["class"] + CoreTypes.SceneType.NONE: loggeri.error("Scene \"" + scene_name + "\" does not exist") + _: await loggeri.crash("Invalid SceneType " + str(exists(scene_name))) return null ## Returns a scene collection node.[br] ## Useful if you want to change a child's index.[br] ## [b]Danger: [i]Don't change any properties of the scene collection or free it, otherwise you may cause breakage.[/i][/b] -func get_scene_collection(type: CoreTypes.SceneType) -> Node: +func get_scene_collection(scene_type: CoreTypes.SceneType) -> Node: if core.config.headless: return null - match(type): + match(scene_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: loggeri.error("No scene collection was found for CoreTypes.SceneType.NONE") - _: await loggeri.crash("Invalid SceneType " + str(type)) + _: await loggeri.crash("Invalid SceneType " + str(scene_type)) return null ## Returns a list of all loaded scenes in some scene collection. -func get_scene_collection_list(type: CoreTypes.SceneType) -> Array[Node]: +func get_scene_collection_list(scene_type: CoreTypes.SceneType) -> Array[Node]: var list: Array[Node] = [] for scene in scenes: - if scenes[scene]["type"] == type: + if scenes[scene]["type"] == scene_type: list.append(scenes[scene]["class"]) return list ## Returns the number of loaded scenes in some scene collection. -func get_scene_collection_count(type: CoreTypes.SceneType) -> int: +func get_scene_collection_count(scene_type: CoreTypes.SceneType) -> int: var amount: int = 0 for scene in scenes: - if scenes[scene]["type"] == type: + if scenes[scene]["type"] == scene_type: amount += 1 return amount ## Returns the scene collection a scene is loaded in.[br] ## [br] ## [enum CoreTypes.SceneType][code].NONE[/code] if no scene with that name was found. -func exists(sname: String) -> CoreTypes.SceneType: +func exists(scene_name: String) -> CoreTypes.SceneType: for scene in scenes: - if scene == sname: return scenes[scene]["type"] + if scene == scene_name: return scenes[scene]["type"] return CoreTypes.SceneType.NONE