Skip to content

Commit

Permalink
Merge pull request #68 from Qubus0/fix_missing_mod_dir_name
Browse files Browse the repository at this point in the history
fix validating mod dir name
  • Loading branch information
Qubus0 authored Jan 20, 2023
2 parents 6b931f9 + 2205e52 commit ad1f2b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions addons/mod_loader/mod_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,22 @@ func load_manifest() -> void:
# Load meta data file
var manifest_path := get_required_mod_file_path(required_mod_files.MANIFEST)
var manifest_dict := ModLoaderUtils.get_json_as_dict(manifest_path)

ModLoaderUtils.log_debug_json_print("%s loaded manifest data -> " % dir_name, manifest_dict, LOG_NAME)

var mod_manifest := ModManifest.new(manifest_dict)

if not mod_manifest:
is_loadable = false
return

is_loadable = has_manifest(mod_manifest)
if not is_loadable: return
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() -> bool:
var manifest_id := manifest.get_mod_id()
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:
ModLoaderUtils.log_fatal('Mod directory name "%s" does not match the data in manifest.json. Expected "%s"' % [ dir_name, manifest_id ], LOG_NAME)
is_loadable = false
ModLoaderUtils.log_fatal('Mod directory name "%s" does not match the data in manifest.json. Expected "%s" (Format: {namespace}-{name})' % [ dir_name, manifest_id ], LOG_NAME)
return false
return true

Expand All @@ -81,8 +79,11 @@ func has_required_files() -> bool:


# Validates if manifest is set
func has_manifest() -> bool:
return not manifest == null
func has_manifest(mod_manifest: ModManifest) -> bool:
if mod_manifest == null:
ModLoaderUtils.log_fatal("Mod manifest could not be created correctly due to errors.", LOG_NAME)
return false
return true


# Converts enum indices [member required_mod_files] into their respective file paths
Expand Down
1 change: 1 addition & 0 deletions addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func _init_mod_data(mod_folder_path):
var local_mod_path = str(UNPACKED_DIR, dir_name)

var mod := ModData.new(local_mod_path)
mod.dir_name = dir_name
mod_data[dir_name] = mod

# Get the mod file paths
Expand Down

0 comments on commit ad1f2b1

Please sign in to comment.