Skip to content

Commit c4458b7

Browse files
Merge pull request #51 from ithinkandicode/remove-id-meta-tag
Remove `id` meta tag and validate mod ID
2 parents 3e6542b + 604c4ac commit c4458b7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

loader/mod_loader.gd

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const REQUIRED_MANIFEST_KEYS_ROOT = [
6161

6262
# Required keys in manifest's `json.extra.godot`
6363
const REQUIRED_MANIFEST_KEYS_EXTRA = [
64-
"id",
6564
"incompatibilities",
6665
"authors",
6766
"compatible_mod_loader_version",
@@ -179,7 +178,8 @@ func _init():
179178

180179
# Instance every mod and add it as a node to the Mod Loader
181180
for mod in mod_load_order:
182-
mod_log(str("Initializing -> ", mod.meta_data.extra.godot.id), LOG_NAME)
181+
# mod_log(str("Initializing -> ", mod.meta_data.extra.godot.id), LOG_NAME)
182+
mod_log(str("Initializing -> ", _get_mod_full_id(mod)), LOG_NAME)
183183
_init_mod(mod)
184184

185185
dev_log(str("mod_data: ", JSON.print(mod_data, ' ')), LOG_NAME)
@@ -455,6 +455,13 @@ func _load_meta_data(mod_id):
455455
# Add the meta data to the mod
456456
mod.meta_data = meta_data
457457

458+
# Check that the mod ID is correct. This will fail if the mod's folder in
459+
# "res://mods-unpacked" does not match its full ID, which is `namespace.name`
460+
var mod_check_id = _get_mod_full_id(mod)
461+
if mod_id != mod_check_id:
462+
mod_log(str("ERROR - ", mod_id, " - Mod ID does not match the data in manifest.json. Expected '", mod_id ,"', but '{namespace}-{name}' was '", mod_check_id ,"'"), LOG_NAME)
463+
mod.is_loadable = false
464+
458465

459466
# Ensure manifest.json has all required keys
460467
func _check_meta_file(meta_data):
@@ -554,7 +561,8 @@ func _init_mod(mod):
554561
dev_log(str("Loaded script -> ", mod_main_script), LOG_NAME)
555562

556563
var mod_main_instance = mod_main_script.new(self)
557-
mod_main_instance.name = mod.meta_data.extra.godot.id
564+
# mod_main_instance.name = mod.meta_data.extra.godot.id
565+
mod_main_instance.name = _get_mod_full_id(mod)
558566

559567
dev_log(str("Adding child -> ", mod_main_instance), LOG_NAME)
560568
add_child(mod_main_instance, true)
@@ -565,6 +573,12 @@ func _init_mod(mod):
565573

566574
# Util functions used in the mod loading process
567575

576+
func _get_mod_full_id(mod:Dictionary)->String:
577+
var name = mod.meta_data.name
578+
var namespace = mod.meta_data.namespace
579+
return str(namespace, "-", name)
580+
581+
568582
# Check if the provided command line argument was present when launching the game
569583
func _check_cmd_line_arg(argument) -> bool:
570584
for arg in OS.get_cmdline_args():

0 commit comments

Comments
 (0)