Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions addons/mod_loader/classes/mod_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func _init(_dir_path: String) -> void:

# Load meta data from a mod's manifest.json file
func load_manifest() -> void:
if not has_required_files():
if not _has_required_files():
return

ModLoaderLog.info("Loading mod_manifest (manifest.json) for -> %s" % dir_name, LOG_NAME)
Expand All @@ -64,15 +64,15 @@ func load_manifest() -> void:

var mod_manifest := ModManifest.new(manifest_dict)

is_loadable = has_manifest(mod_manifest)
is_loadable = _has_manifest(mod_manifest)
if not is_loadable: return
is_loadable = is_mod_dir_name_same_as_id(mod_manifest)
is_loadable = _is_mod_dir_name_same_as_id(mod_manifest)
if not is_loadable: return
manifest = mod_manifest


# Validates if [member dir_name] matches [method ModManifest.get_mod_id]
func is_mod_dir_name_same_as_id(mod_manifest: ModManifest) -> bool:
func _is_mod_dir_name_same_as_id(mod_manifest: ModManifest) -> bool:
var manifest_id := mod_manifest.get_mod_id()
if not dir_name == manifest_id:
ModLoaderLog.fatal('Mod directory name "%s" does not match the data in manifest.json. Expected "%s" (Format: {namespace}-{name})' % [ dir_name, manifest_id ], LOG_NAME)
Expand All @@ -81,7 +81,7 @@ func is_mod_dir_name_same_as_id(mod_manifest: ModManifest) -> bool:


# Confirms that all files from [member required_mod_files] exist
func has_required_files() -> bool:
func _has_required_files() -> bool:
for required_file in required_mod_files:
var file_path := get_required_mod_file_path(required_mod_files[required_file])

Expand All @@ -92,7 +92,7 @@ func has_required_files() -> bool:


# Validates if manifest is set
func has_manifest(mod_manifest: ModManifest) -> bool:
func _has_manifest(mod_manifest: ModManifest) -> bool:
if mod_manifest == null:
ModLoaderLog.fatal("Mod manifest could not be created correctly due to errors.", LOG_NAME)
return false
Expand Down
4 changes: 2 additions & 2 deletions addons/mod_loader/internal/cli.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static func is_running_with_command_line_arg(argument: String) -> bool:

# Get the command line argument value if present when launching the game
static func get_cmd_line_arg_value(argument: String) -> String:
var args := get_fixed_cmdline_args()
var args := _get_fixed_cmdline_args()

for arg_index in args.size():
var arg := args[arg_index] as String
Expand All @@ -40,7 +40,7 @@ static func get_cmd_line_arg_value(argument: String) -> String:
return ""


static func get_fixed_cmdline_args() -> PoolStringArray:
static func _get_fixed_cmdline_args() -> PoolStringArray:
return fix_godot_cmdline_args_string_space_splitting(OS.get_cmdline_args())


Expand Down
10 changes: 5 additions & 5 deletions addons/mod_loader/internal/dependency.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LOG_NAME := "ModLoader:Dependency"
# loading if they are missing.
#
# Returns: A boolean indicating whether a circular dependency was detected.
static func _check_dependencies(mod: ModData, is_required := true, dependency_chain := []) -> bool:
static func check_dependencies(mod: ModData, is_required := true, dependency_chain := []) -> bool:
var dependency_type := "required" if is_required else "optional"
# Get the dependency array based on the is_required flag
var dependencies := mod.manifest.dependencies if is_required else mod.manifest.optional_dependencies
Expand Down Expand Up @@ -58,7 +58,7 @@ static func _check_dependencies(mod: ModData, is_required := true, dependency_ch

# Check if the dependency has any dependencies of its own
if dependency.manifest.dependencies.size() > 0:
if _check_dependencies(dependency, is_required, dependency_chain):
if check_dependencies(dependency, is_required, dependency_chain):
return true

# Return false if all dependencies have been resolved
Expand All @@ -68,7 +68,7 @@ static func _check_dependencies(mod: ModData, is_required := true, dependency_ch
# Run load before check on a mod, checking any load_before entries it lists in its
# mod_manifest (ie. its manifest.json file). Add the mod to the dependency of the
# mods inside the load_before array.
static func _check_load_before(mod: ModData) -> void:
static func check_load_before(mod: ModData) -> void:
# Skip if no entries in load_before
if mod.manifest.load_before.size() == 0:
return
Expand Down Expand Up @@ -97,7 +97,7 @@ static func _check_load_before(mod: ModData) -> void:


# Get the load order of mods, using a custom sorter
static func _get_load_order(mod_data_array: Array) -> Array:
static func get_load_order(mod_data_array: Array) -> Array:
# Add loadable mods to the mod load order array
for mod in mod_data_array:
mod = mod as ModData
Expand All @@ -121,7 +121,7 @@ static func _handle_missing_dependency(mod_id: String, dependency_id: String) ->
ModLoaderStore.mod_missing_dependencies[mod_id].append(dependency_id)


# Inner class so the sort function can be called by _get_load_order()
# Inner class so the sort function can be called by get_load_order()
class CompareImportance:
# Custom sorter that orders mods by important
static func _compare_importance(a: ModData, b: ModData) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions addons/mod_loader/internal/file.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ static func get_json_as_dict(path: String) -> Dictionary:
ModLoaderLog.error("Error opening file. Code: %s" % error, LOG_NAME)

var content := file.get_as_text()
return get_json_string_as_dict(content)
return _get_json_string_as_dict(content)


# Parses JSON from a given [String] and returns a [Dictionary].
# Returns an empty [Dictionary] on error (check with size() < 1)
static func get_json_string_as_dict(string: String) -> Dictionary:
static func _get_json_string_as_dict(string: String) -> Dictionary:
if string == "":
return {}
var parsed := JSON.parse(string)
Expand All @@ -47,7 +47,7 @@ static func get_json_string_as_dict(string: String) -> Dictionary:
# =============================================================================

# Saves a dictionary to a file, as a JSON string
static func save_string_to_file(save_string: String, filepath: String) -> bool:
static func _save_string_to_file(save_string: String, filepath: String) -> bool:
# Create directory if it doesn't exist yet
var file_directory := filepath.get_base_dir()
var dir := Directory.new()
Expand Down Expand Up @@ -81,7 +81,7 @@ static func save_string_to_file(save_string: String, filepath: String) -> bool:
# Saves a dictionary to a file, as a JSON string
static func save_dictionary_to_json_file(data: Dictionary, filepath: String) -> bool:
var json_string = JSON.print(data, "\t")
return save_string_to_file(json_string, filepath)
return _save_string_to_file(json_string, filepath)


# Checks
Expand Down
4 changes: 2 additions & 2 deletions addons/mod_loader/internal/godot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const LOG_NAME := "ModLoader:Godot"
# Returns a bool if the position does not match.
# Optionally triggers a fatal error
static func check_autoload_position(autoload_name: String, position_index: int, trigger_error: bool = false) -> bool:
var autoload_array := _get_autoload_array()
var autoload_array := get_autoload_array()
var autoload_index := autoload_array.find(autoload_name)
var position_matches := autoload_index == position_index

Expand All @@ -29,7 +29,7 @@ static func check_autoload_position(autoload_name: String, position_index: int,


# Get an array of all autoloads -> ["autoload/AutoloadName", ...]
static func _get_autoload_array() -> Array:
static func get_autoload_array() -> Array:
var autoloads := []

# Get all autoload settings
Expand Down
6 changes: 3 additions & 3 deletions addons/mod_loader/internal/mod_loader_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const LOG_NAME := "ModLoader:ModLoaderUtils"
# This is a dummy func. It is exclusively used to show notes in the code that
# stay visible after decompiling a PCK, as is primarily intended to assist new
# modders in understanding and troubleshooting issues
static func code_note(_msg:String):
static func _code_note(_msg:String):
pass


Expand Down Expand Up @@ -56,7 +56,7 @@ static func register_global_classes_from_array(new_global_classes: Array) -> voi
var registered_class_icons: Dictionary = ProjectSettings.get_setting("_global_script_class_icons")

for new_class in new_global_classes:
if not is_valid_global_class_dict(new_class):
if not _is_valid_global_class_dict(new_class):
continue
for old_class in registered_classes:
if old_class.class == new_class.class:
Expand All @@ -75,7 +75,7 @@ static func register_global_classes_from_array(new_global_classes: Array) -> voi

# Checks if all required fields are in the given [Dictionary]
# Format: { "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" }
static func is_valid_global_class_dict(global_class_dict: Dictionary) -> bool:
static func _is_valid_global_class_dict(global_class_dict: Dictionary) -> bool:
var required_fields := ["base", "class", "language", "path"]
if not global_class_dict.has_all(required_fields):
ModLoaderLog.fatal("Global class to be registered is missing one of %s" % required_fields, LOG_NAME)
Expand Down
10 changes: 5 additions & 5 deletions addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func _init() -> void:
_check_autoload_positions()

# Log the autoloads order. Helpful when providing support to players
ModLoaderLog.debug_json_print("Autoload order", _ModLoaderGodot._get_autoload_array(), LOG_NAME)
ModLoaderLog.debug_json_print("Autoload order", _ModLoaderGodot.get_autoload_array(), LOG_NAME)

# Log game install dir
ModLoaderLog.info("game_install_directory: %s" % _ModLoaderPath.get_local_folder_dir(), LOG_NAME)
Expand Down Expand Up @@ -114,7 +114,7 @@ func _load_mods() -> void:
var mod: ModData = ModLoaderStore.mod_data[dir_name]
if not mod.is_loadable:
continue
_ModLoaderDependency._check_load_before(mod)
_ModLoaderDependency.check_load_before(mod)


# Run optional dependency checks after loading mod_manifest.
Expand All @@ -124,7 +124,7 @@ func _load_mods() -> void:
var mod: ModData = ModLoaderStore.mod_data[dir_name]
if not mod.is_loadable:
continue
var _is_circular := _ModLoaderDependency._check_dependencies(mod, false)
var _is_circular := _ModLoaderDependency.check_dependencies(mod, false)


# Run dependency checks after loading mod_manifest. If a mod depends on another
Expand All @@ -133,10 +133,10 @@ func _load_mods() -> void:
var mod: ModData = ModLoaderStore.mod_data[dir_name]
if not mod.is_loadable:
continue
var _is_circular := _ModLoaderDependency._check_dependencies(mod)
var _is_circular := _ModLoaderDependency.check_dependencies(mod)

# Sort mod_load_order by the importance score of the mod
ModLoaderStore.mod_load_order = _ModLoaderDependency._get_load_order(ModLoaderStore.mod_data.values())
ModLoaderStore.mod_load_order = _ModLoaderDependency.get_load_order(ModLoaderStore.mod_data.values())

# Log mod order
var mod_i := 1
Expand Down
2 changes: 1 addition & 1 deletion addons/mod_loader/mod_loader_store.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const LOG_NAME = "ModLoader:Store"
# Vars
# =============================================================================

# Order for mods to be loaded in, set by `_get_load_order`
# Order for mods to be loaded in, set by `get_load_order`
var mod_load_order := []

# Stores data for every found/loaded mod
Expand Down
8 changes: 4 additions & 4 deletions addons/mod_loader/setup/setup_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static func register_global_classes_from_array(new_global_classes: Array) -> voi
var registered_class_icons: Dictionary = ProjectSettings.get_setting("_global_script_class_icons")

for new_class in new_global_classes:
if not is_valid_global_class_dict(new_class):
if not _is_valid_global_class_dict(new_class):
continue
for old_class in registered_classes:
if old_class.class == new_class.class:
Expand All @@ -97,7 +97,7 @@ static func register_global_classes_from_array(new_global_classes: Array) -> voi

# Checks if all required fields are in the given [Dictionary]
# Format: { "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" }
static func is_valid_global_class_dict(global_class_dict: Dictionary) -> bool:
static func _is_valid_global_class_dict(global_class_dict: Dictionary) -> bool:
var ModLoaderSetupLog: Object = load("res://addons/mod_loader/setup/setup_log.gd")
var required_fields := ["base", "class", "language", "path"]
if not global_class_dict.has_all(required_fields):
Expand All @@ -124,7 +124,7 @@ static func is_running_with_command_line_arg(argument: String) -> bool:

# Get the command line argument value if present when launching the game
static func get_cmd_line_arg_value(argument: String) -> String:
var args := get_fixed_cmdline_args()
var args := _get_fixed_cmdline_args()

for arg_index in args.size():
var arg := args[arg_index] as String
Expand All @@ -145,7 +145,7 @@ static func get_cmd_line_arg_value(argument: String) -> String:
return ""


static func get_fixed_cmdline_args() -> PoolStringArray:
static func _get_fixed_cmdline_args() -> PoolStringArray:
return fix_godot_cmdline_args_string_space_splitting(OS.get_cmdline_args())


Expand Down