Skip to content

Commit 1dcaa62

Browse files
Merge pull request #32 from ithinkandicode/snake-case
Convert to snake case
2 parents 0edb3b9 + 05786e2 commit 1dcaa62

File tree

2 files changed

+53
-50
lines changed

2 files changed

+53
-50
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ Some properties in the JSON are not checked in the code, and are only used for r
7272

7373
Use these when creating your mods. As above, see the [docs for Delta-V Modding](https://gitlab.com/Delta-V-Modding/Mods/-/blob/main/MODDING.md) for more details.
7474

75-
### installScriptExtension
75+
### install_script_extension
7676

77-
installScriptExtension(childScriptPath:String)
77+
func install_script_extension(child_script_path:String)
7878

79-
Add a script that extends a vanilla script. `childScriptPath` is the path to your mod's extender script path, eg `MOD/extensions/singletons/utils.gd`.
79+
Add a script that extends a vanilla script. `child_script_path` is the path to your mod's extender script path, eg `MOD/extensions/singletons/utils.gd`.
8080

8181
Inside that extender script, it should include `extends {target}`, where {target} is the vanilla path, eg: `extends "res://singletons/utils.gd"`.
8282

@@ -99,23 +99,23 @@ yourmod.zip
9999
└───debug_service.gd
100100
```
101101

102-
### addTranslationFromResource
102+
### add_translation_from_resource
103103

104-
addTranslationFromResource(resourcePath: String)
104+
add_translation_from_resource(resource_path: String)
105105

106106
Add a translation file, eg "mytranslation.en.translation". The translation file should have been created in Godot already: When you import a CSV, such a file will be created for you.
107107

108108
Note that this function is exclusive to ModLoader, and departs from Delta-V's two functions [addTranslationsFromCSV](https://gitlab.com/Delta-V-Modding/Mods/-/blob/main/MODDING.md#addtranslationsfromcsv) and [addTranslationsFromJSON](https://gitlab.com/Delta-V-Modding/Mods/-/blob/main/MODDING.md#addtranslationsfromjson), which aren't available in ModLoader.
109109

110-
### appendNodeInScene
110+
### append_node_in_scene
111111

112-
appendNodeInScene(modifiedScene, nodeName:String = "", nodeParent = null, instancePath:String = "", isVisible:bool = true)
112+
append_node_in_scene(modified_scene, node_name:String = "", node_parent = null, instance_path:String = "", is_visible:bool = true)
113113

114114
Create and add a node to a instanced scene.
115115

116-
### saveScene
116+
### save_scene
117117

118-
saveScene(modifiedScene, scenePath:String)
118+
save_scene(modified_scene, scenePath:String)
119119

120120
Save the scene as a PackedScene, overwriting Godot's cache if needed.
121121

loader/mod_loader.gd

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var os_mods_path_override = ""
9292
var mod_missing_dependencies = {}
9393

9494
# Things to keep to ensure they are not garbage collected (used by `saveScene`)
95-
var _savedObjects = []
95+
var _saved_objects = []
9696

9797

9898
# Main
@@ -329,7 +329,7 @@ func _init_mod_data(mod_folder_path):
329329
# not needed anymore. It can be useful when debugging, but it's also an expensive
330330
# operation if a mod has a large number of files (eg. Brotato's Invasion mod,
331331
# which has ~1,000 files). That's why it's disabled by default
332-
mod_data[mod_id].file_paths = get_flat_view_dict(local_mod_path)
332+
mod_data[mod_id].file_paths = _get_flat_view_dict(local_mod_path)
333333

334334
for required_filename in REQUIRED_MOD_FILES:
335335
# Eg:
@@ -455,11 +455,11 @@ func _get_load_order():
455455
mod_load_order.append(mod)
456456

457457
# Sort mods by the importance value
458-
mod_load_order.sort_custom(self, "_compare_Importance")
458+
mod_load_order.sort_custom(self, "_compare_importance")
459459

460460

461461
# Custom sorter that orders mods by important
462-
func _compare_Importance(a, b):
462+
func _compare_importance(a, b):
463463
# if true a -> b
464464
# if false b -> a
465465
if(a.importance > b.importance):
@@ -472,11 +472,14 @@ func _compare_Importance(a, b):
472472
# Runs mods in the order stored in mod_load_order.
473473
func _init_mod(mod):
474474
var mod_main_path = mod.required_files_path["mod_main.gd"]
475+
475476
dev_log(str("Loading script from -> ", mod_main_path), LOG_NAME)
476477
var mod_main_script = ResourceLoader.load(mod_main_path)
477478
dev_log(str("Loaded script -> ", mod_main_script), LOG_NAME)
479+
478480
var mod_main_instance = mod_main_script.new(self)
479481
mod_main_instance.name = mod.meta_data.extra.godot.id
482+
480483
dev_log(str("Adding child -> ", mod_main_instance), LOG_NAME)
481484
add_child(mod_main_instance, true)
482485

@@ -509,23 +512,23 @@ func _get_cmd_line_arg(argument) -> String:
509512

510513
# Get the path to the (packed) mods folder, ie "res://mods" or the OS's equivalent
511514
func _get_mod_folder_dir():
512-
var gameInstallDirectory = OS.get_executable_path().get_base_dir()
515+
var game_install_directory = OS.get_executable_path().get_base_dir()
513516

514517
if OS.get_name() == "OSX":
515-
gameInstallDirectory = gameInstallDirectory.get_base_dir().get_base_dir().get_base_dir()
518+
game_install_directory = game_install_directory.get_base_dir().get_base_dir().get_base_dir()
516519

517520
# Fix for running the game through the Godot editor (as the EXE path would be
518521
# the editor's own EXE, which won't have any mod ZIPs)
519522
# if OS.is_debug_build():
520523
if OS.has_feature("editor"):
521-
gameInstallDirectory = "res://"
524+
game_install_directory = "res://"
522525

523526
if (os_mods_path_override != ""):
524-
gameInstallDirectory = os_mods_path_override
527+
game_install_directory = os_mods_path_override
525528

526-
mod_log(str("gameInstallDirectory: ", gameInstallDirectory), LOG_NAME)
529+
mod_log(str("game_install_directory: ", game_install_directory), LOG_NAME)
527530

528-
return gameInstallDirectory.plus_file("mods")
531+
return game_install_directory.plus_file("mods")
529532

530533

531534
# Parses JSON from a given file path and returns a dictionary
@@ -559,7 +562,7 @@ func _get_file_name(path, is_lower_case = true, is_no_extension = false):
559562
# original version of this script, before becoming deprecated. It may still be
560563
# used if DEBUG_ENABLE_STORING_FILEPATHS is true.
561564
# Source: https://gist.github.com/willnationsdev/00d97aa8339138fd7ef0d6bd42748f6e
562-
func get_flat_view_dict(p_dir = "res://", p_match = "", p_match_is_regex = false):
565+
func _get_flat_view_dict(p_dir = "res://", p_match = "", p_match_is_regex = false):
563566
var regex = null
564567
if p_match_is_regex:
565568
regex = RegEx.new()
@@ -613,19 +616,19 @@ func get_flat_view_dict(p_dir = "res://", p_match = "", p_match_is_regex = false
613616

614617
# Helper functions to build mods
615618

616-
# Add a script that extends a vanilla script. `childScriptPath` should point
619+
# Add a script that extends a vanilla script. `child_script_path` should point
617620
# to your mod's extender script, eg "MOD/extensions/singletons/utils.gd".
618621
# Inside that extender script, it should include "extends {target}", where
619622
# {target} is the vanilla path, eg: `extends "res://singletons/utils.gd"`.
620623
# Note that your extender script doesn't have to follow the same directory path
621624
# as the vanilla file, but it's good practice to do so.
622-
func installScriptExtension(childScriptPath:String):
625+
func install_script_extension(child_script_path:String):
623626
# Check path to file exists
624-
if !File.new().file_exists(childScriptPath):
625-
mod_log("ERROR - The child script path '%s' does not exist" % [childScriptPath], LOG_NAME)
627+
if !File.new().file_exists(child_script_path):
628+
mod_log("ERROR - The child script path '%s' does not exist" % [child_script_path], LOG_NAME)
626629
return
627630

628-
var childScript = ResourceLoader.load(childScriptPath)
631+
var child_script = ResourceLoader.load(child_script_path)
629632

630633
# Force Godot to compile the script now.
631634
# We need to do this here to ensure that the inheritance chain is
@@ -634,46 +637,46 @@ func installScriptExtension(childScriptPath:String):
634637
# This is also needed to make Godot instantiate the extended class
635638
# when creating singletons.
636639
# The actual instance is thrown away.
637-
childScript.new()
640+
child_script.new()
638641

639-
var parentScript = childScript.get_base_script()
640-
var parentScriptPath = parentScript.resource_path
641-
mod_log("Installing script extension: %s <- %s" % [parentScriptPath, childScriptPath], LOG_NAME)
642-
childScript.take_over_path(parentScriptPath)
642+
var parent_script = child_script.get_base_script()
643+
var parent_script_path = parent_script.resource_path
644+
mod_log("Installing script extension: %s <- %s" % [parent_script_path, child_script_path], LOG_NAME)
645+
child_script.take_over_path(parent_script_path)
643646

644647

645648
# Add a translation file, eg "mytranslation.en.translation". The translation
646649
# file should have been created in Godot already: When you improt a CSV, such
647650
# a file will be created for you.
648-
func addTranslationFromResource(resourcePath: String):
649-
var translation_object = load(resourcePath)
651+
func add_translation_from_resource(resource_path: String):
652+
var translation_object = load(resource_path)
650653
TranslationServer.add_translation(translation_object)
651654
mod_log("Added Translation from Resource", LOG_NAME)
652655

653656

654-
func appendNodeInScene(modifiedScene, nodeName:String = "", nodeParent = null, instancePath:String = "", isVisible:bool = true):
655-
var newNode
656-
if instancePath != "":
657-
newNode = load(instancePath).instance()
657+
func append_node_in_scene(modified_scene, node_name:String = "", node_parent = null, instance_path:String = "", is_visible:bool = true):
658+
var new_node
659+
if instance_path != "":
660+
new_node = load(instance_path).instance()
658661
else:
659-
newNode = Node.instance()
660-
if nodeName != "":
661-
newNode.name = nodeName
662-
if isVisible == false:
663-
newNode.visible = false
664-
if nodeParent != null:
665-
var tmpNode = modifiedScene.get_node(nodeParent)
666-
tmpNode.add_child(newNode)
667-
newNode.set_owner(modifiedScene)
662+
new_node = Node.instance()
663+
if node_name != "":
664+
new_node.name = node_name
665+
if is_visible == false:
666+
new_node.visible = false
667+
if node_parent != null:
668+
var tmp_node = modified_scene.get_node(node_parent)
669+
tmp_node.add_child(new_node)
670+
new_node.set_owner(modified_scene)
668671
else:
669-
modifiedScene.add_child(newNode)
670-
newNode.set_owner(modifiedScene)
672+
modified_scene.add_child(new_node)
673+
new_node.set_owner(modified_scene)
671674

672675

673-
func saveScene(modifiedScene, scenePath:String):
676+
func save_scene(modified_scene, scenePath:String):
674677
var packed_scene = PackedScene.new()
675-
packed_scene.pack(modifiedScene)
678+
packed_scene.pack(modified_scene)
676679
dev_log(str("packing scene -> ", packed_scene), LOG_NAME)
677680
packed_scene.take_over_path(scenePath)
678681
dev_log(str("saveScene - taking over path - new path -> ", packed_scene.resource_path), LOG_NAME)
679-
_savedObjects.append(packed_scene)
682+
_saved_objects.append(packed_scene)

0 commit comments

Comments
 (0)