Skip to content

Commit 64efef4

Browse files
committed
rename ModDetails to ModManifest, remove logs for now
1 parent c58d6a4 commit 64efef4

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

addons/mod_loader/mod_data.gd

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum required_mod_files {
1414
MANIFEST,
1515
}
1616

17-
## Directory of the mod. Has to be identical to [method ModDetails.get_mod_id]
17+
## Directory of the mod. Has to be identical to [method ModManifest.get_mod_id]
1818
var dir_name := ""
1919
## Path to the Mod's Directory
2020
var dir_path := ""
@@ -23,7 +23,7 @@ var is_loadable := true
2323
## Is increased for every mod depending on this mod. Highest importance is loaded first
2424
var importance := 0
2525
## Contents of the manifest
26-
var details: ModDetails
26+
var manifest: ModManifest
2727
## Updated in _load_mod_configs
2828
var config := {}
2929

@@ -36,32 +36,32 @@ func _init(_dir_path: String) -> void:
3636

3737

3838
## Load meta data from a mod's manifest.json file
39-
func load_details(modLoader = ModLoader) -> void:
39+
func load_manifest() -> void:
4040
if not has_required_files():
4141
return
4242

43-
modLoader.mod_log("Loading mod_details (manifest.json) for -> %s" % dir_name, LOG_NAME)
43+
# ModLoader.mod_log("Loading mod_manifest (manifest.json) for -> %s" % dir_name, LOG_NAME)
4444

4545
# Load meta data file
4646
var manifest_path = get_required_mod_file_path(required_mod_files.MANIFEST)
47-
var manifest_dict = modLoader._get_json_as_dict(manifest_path) # todo get from utils
47+
var manifest_dict = _get_json_as_dict(manifest_path) # todo get from utils
4848

49-
modLoader.dev_log("%s loaded manifest data -> %s" % [dir_name, manifest_dict], LOG_NAME)
49+
# ModLoader.mod_log("%s loaded manifest data -> %s" % [dir_name, manifest_dict], LOG_NAME)
5050

51-
var mod_details := ModDetails.new(manifest_dict)
51+
var mod_manifest := ModManifest.new(manifest_dict)
5252

53-
if not mod_details:
53+
if not mod_manifest:
5454
is_loadable = false
5555
return
5656

57-
details = mod_details
57+
manifest = mod_manifest
5858

5959

60-
## Validates if [member dir_name] matches [method ModDetails.get_mod_id]
60+
## Validates if [member dir_name] matches [method ModManifest.get_mod_id]
6161
func is_mod_dir_name_same_as_id() -> bool:
62-
var manifest_id = details.get_mod_id()
62+
var manifest_id = manifest.get_mod_id()
6363
if dir_name != manifest_id:
64-
ModLoader.mod_log('ERROR - Mod directory name "%s" does not match the data in manifest.json. Expected "%s"' % [ dir_name, manifest_id ], LOG_NAME)
64+
# ModLoader.mod_log('ERROR - Mod directory name "%s" does not match the data in manifest.json. Expected "%s"' % [ dir_name, manifest_id ], LOG_NAME)
6565
is_loadable = false
6666
return false
6767
return true
@@ -75,14 +75,14 @@ func has_required_files() -> bool:
7575
var file_path = get_required_mod_file_path(required_mod_files[required_file])
7676

7777
if !file_check.file_exists(file_path):
78-
ModLoader.mod_log("ERROR - %s is missing a required file: %s" % [dir_name, file_path], LOG_NAME)
78+
# ModLoader.mod_log("ERROR - %s is missing a required file: %s" % [dir_name, file_path], LOG_NAME)
7979
is_loadable = false
8080
return is_loadable
8181

8282

83-
## Validates if details are set
84-
func has_details() -> bool:
85-
return not details == null
83+
## Validates if manifest is set
84+
func has_manifest() -> bool:
85+
return not manifest == null
8686

8787

8888
## Converts enum indices [member required_mod_files] into their respective file paths
@@ -95,6 +95,25 @@ func get_required_mod_file_path(required_file: int) -> String:
9595
return ""
9696

9797

98+
## Parses JSON from a given file path and returns a dictionary.
99+
## Returns an empty dictionary if no file exists (check with size() < 1)
100+
static func _get_json_as_dict(path:String) -> Dictionary: # todo move to utils
101+
var file = File.new()
102+
103+
if !file.file_exists(path):
104+
file.close()
105+
return {}
106+
107+
file.open(path, File.READ)
108+
var content = file.get_as_text()
109+
110+
var parsed := JSON.parse(content)
111+
if parsed.error:
112+
# log error
113+
return {}
114+
return parsed.result
115+
116+
98117
#func _to_string() -> String:
99118
# todo if we want it pretty printed
100119

addons/mod_loader/mod_loader.gd

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ func _init():
123123
# required properties (REQUIRED_META_TAGS)
124124
for dir_name in mod_data:
125125
var mod: ModData = mod_data[dir_name]
126-
mod.load_details(self)
126+
mod.load_manifest()
127127

128128
mod_log("DONE: Loaded all meta data", LOG_NAME)
129129

130-
# Run dependency checks after loading mod_details. If a mod depends on another
130+
# Run dependency checks after loading mod_manifest. If a mod depends on another
131131
# mod that hasn't been loaded, that dependent mod won't be loaded.
132132
for dir_name in mod_data:
133133
var mod: ModData = mod_data[dir_name]
134134
if not mod.is_loadable:
135135
continue
136-
_check_dependencies(dir_name, mod.details.dependencies)
136+
_check_dependencies(dir_name, mod.manifest.dependencies)
137137

138138
# Sort mod_load_order by the importance score of the mod
139139
_get_load_order()
@@ -147,8 +147,8 @@ func _init():
147147

148148
# Instance every mod and add it as a node to the Mod Loader
149149
for mod in mod_load_order:
150-
# mod_log(str("Initializing -> ", mod.mod_details.extra.godot.id), LOG_NAME)
151-
mod_log("Initializing -> %s" % mod.details.get_mod_id(), LOG_NAME)
150+
# mod_log(str("Initializing -> ", mod.mod_manifest.extra.godot.id), LOG_NAME)
151+
mod_log("Initializing -> %s" % mod.manifest.get_mod_id(), LOG_NAME)
152152
_init_mod(mod)
153153

154154
dev_log(str("mod_data: ", JSON.print(mod_data, ' ')), LOG_NAME)
@@ -315,7 +315,7 @@ func _load_mod_configs():
315315

316316
for dir_name in mod_data:
317317
var json_path = configs_path.plus_file(dir_name + ".json")
318-
var mod_config = _get_json_as_dict(json_path)
318+
var mod_config = ModData._get_json_as_dict(json_path)
319319

320320
dev_log(str("Config JSON: Looking for config at path: ", json_path), LOG_NAME)
321321

@@ -334,7 +334,7 @@ func _load_mod_configs():
334334
var new_path = mod_config.load_from
335335
if new_path != "" && new_path != str(dir_name, ".json"):
336336
mod_log(str("Config JSON: Following load_from path: ", new_path), LOG_NAME)
337-
var new_config = _get_json_as_dict(configs_path + new_path)
337+
var new_config = ModData._get_json_as_dict(configs_path + new_path)
338338
if new_config.size() > 0 != null:
339339
mod_config = new_config
340340
mod_log(str("Config JSON: Loaded from custom json: ", new_path), LOG_NAME)
@@ -373,7 +373,7 @@ func _init_mod_data(mod_folder_path):
373373

374374

375375
# Run dependency checks on a mod, checking any dependencies it lists in its
376-
# mod_details (ie. its manifest.json file). If a mod depends on another mod that
376+
# mod_manifest (ie. its manifest.json file). If a mod depends on another mod that
377377
# hasn't been loaded, the dependent mod won't be loaded.
378378
func _check_dependencies(mod_id:String, deps:Array):
379379
dev_log(str("Checking dependencies - mod_id: ", mod_id, " dependencies: ", deps), LOG_NAME)
@@ -386,7 +386,7 @@ func _check_dependencies(mod_id:String, deps:Array):
386386
continue
387387

388388
var dependency = mod_data[dependency_id]
389-
var dependency_mod_details = mod_data[dependency_id].mod_details
389+
var dependency_mod_manifest = mod_data[dependency_id].mod_manifest
390390

391391
# Init the importance score if it's missing
392392

@@ -395,8 +395,8 @@ func _check_dependencies(mod_id:String, deps:Array):
395395
dev_log(str("Dependency -> ", dependency_id, " importance -> ", dependency.importance), LOG_NAME)
396396

397397
# check if dependency has dependencies
398-
if(dependency_mod_details.dependencies.size() > 0):
399-
_check_dependencies(dependency_id, dependency_mod_details.dependencies)
398+
if(dependency_mod_manifest.dependencies.size() > 0):
399+
_check_dependencies(dependency_id, dependency_mod_manifest.dependencies)
400400

401401

402402
# Handle missing dependencies: Sets `is_loadable` to false and logs an error
@@ -445,8 +445,8 @@ func _init_mod(mod: ModData):
445445
dev_log("Loaded script -> %s" % mod_main_script, LOG_NAME)
446446

447447
var mod_main_instance = mod_main_script.new(self)
448-
# mod_main_instance.name = mod.mod_details.extra.godot.id
449-
mod_main_instance.name = mod.details.get_mod_id()
448+
# mod_main_instance.name = mod.mod_manifest.extra.godot.id
449+
mod_main_instance.name = mod.manifest.get_mod_id()
450450

451451
dev_log("Adding child -> %s" % mod_main_instance, LOG_NAME)
452452
add_child(mod_main_instance, true)
@@ -494,22 +494,6 @@ func _get_local_folder_dir(subfolder:String = ""):
494494
return game_install_directory.plus_file(subfolder)
495495

496496

497-
# Parses JSON from a given file path and returns a dictionary.
498-
# Returns an empty dictionary if no file exists (check with size() < 1)
499-
func _get_json_as_dict(path:String)->Dictionary:
500-
# mod_log(str("getting JSON as dict from path -> ", path), LOG_NAME)
501-
var file = File.new()
502-
503-
if !file.file_exists(path):
504-
file.close()
505-
return {}
506-
507-
file.open(path, File.READ)
508-
var content = file.get_as_text()
509-
510-
return JSON.parse(content).result
511-
512-
513497
func _get_file_name(path, is_lower_case = true, is_no_extension = false):
514498
# mod_log(str("Get file name from path -> ", path), LOG_NAME)
515499
var file_name = path.get_file()
@@ -673,7 +657,7 @@ func get_mod_config(mod_id:String = "", key:String = "")->Dictionary:
673657
# Mod ID is valid
674658
if error_num == 0:
675659
var config_data = mod_data[mod_id].config
676-
defaults = mod_data[mod_id].mod_details.extra.godot.config_defaults
660+
defaults = mod_data[mod_id].mod_manifest.extra.godot.config_defaults
677661

678662
# No custom JSON file
679663
if config_data.size() == 0:

addons/mod_loader/mod_details.gd renamed to addons/mod_loader/mod_manifest.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extends Resource
22
## Stores and validates contents of the manifest set by the user
3-
class_name ModDetails
3+
class_name ModManifest
44

55

66
## Mod name.

0 commit comments

Comments
 (0)