Skip to content

Commit 1bb3df1

Browse files
committed
Merge branch 'develop' into improve_static_typing_and_style
2 parents 6245723 + 81ce17e commit 1bb3df1

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

addons/mod_loader/mod_data.gd

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,22 @@ func load_manifest() -> void:
4545
# Load meta data file
4646
var manifest_path := get_required_mod_file_path(required_mod_files.MANIFEST)
4747
var manifest_dict := ModLoaderUtils.get_json_as_dict(manifest_path)
48-
4948
ModLoaderUtils.log_debug_json_print("%s loaded manifest data -> " % dir_name, manifest_dict, LOG_NAME)
5049

5150
var mod_manifest := ModManifest.new(manifest_dict)
5251

53-
if not mod_manifest:
54-
is_loadable = false
55-
return
56-
52+
is_loadable = has_manifest(mod_manifest)
53+
if not is_loadable: return
54+
is_loadable = is_mod_dir_name_same_as_id(mod_manifest)
55+
if not is_loadable: return
5756
manifest = mod_manifest
5857

5958

6059
# Validates if [member dir_name] matches [method ModManifest.get_mod_id]
61-
func is_mod_dir_name_same_as_id() -> bool:
62-
var manifest_id := manifest.get_mod_id()
60+
func is_mod_dir_name_same_as_id(mod_manifest: ModManifest) -> bool:
61+
var manifest_id := mod_manifest.get_mod_id()
6362
if not dir_name == manifest_id:
64-
ModLoaderUtils.log_fatal('Mod directory name "%s" does not match the data in manifest.json. Expected "%s"' % [ dir_name, manifest_id ], LOG_NAME)
65-
is_loadable = false
63+
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)
6664
return false
6765
return true
6866

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

8280

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

8788

8889
# Converts enum indices [member required_mod_files] into their respective file paths

addons/mod_loader/mod_loader_utils.gd

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ static func log_debug_json_print(message: String, json_printable, mod_name: Stri
5656

5757

5858
static func _loader_log(message: String, mod_name: String, log_type: String = "info") -> void:
59-
var ignored_arg := get_cmd_line_arg_value("--log-ignore")
60-
var ignored_names: Array = str2var(ignored_arg)
61-
if ignored_names and mod_name in ignored_names:
59+
if is_mod_name_ignored(mod_name):
6260
return
6361

6462
var date := "%s " % get_date_time_string()
@@ -89,6 +87,16 @@ static func _loader_log(message: String, mod_name: String, log_type: String = "i
8987
_write_to_log_file(log_message)
9088

9189

90+
static func is_mod_name_ignored(mod_name: String) -> bool:
91+
var ignored_arg := get_cmd_line_arg_value("--log-ignore")
92+
93+
if not ignored_arg == "":
94+
var ignored_names: Array = ignored_arg.split(",")
95+
if mod_name in ignored_names:
96+
return true
97+
return false
98+
99+
92100
static func _write_to_log_file(log_entry: String) -> void:
93101
var log_file := File.new()
94102

addons/mod_loader/mod_manifest.gd

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extends Resource
22
# Stores and validates contents of the manifest set by the user
33
class_name ModManifest
44

5+
const LOG_NAME := "ModLoader:ModManifest"
56

67
# Mod name.
78
# Validated by [method is_name_or_namespace_valid]
@@ -95,33 +96,41 @@ func get_package_id() -> String:
9596

9697
# A valid namespace may only use letters (any case), numbers and underscores
9798
# and has to be longer than 3 characters
98-
# /^[a-zA-Z0-9_]{3,}$/
99+
# a-z A-Z 0-9 _ (longer than 3 characters)
99100
static func is_name_or_namespace_valid(name: String) -> bool:
100101
var re := RegEx.new()
101102
re.compile("^[a-zA-Z0-9_]*$") # alphanumeric and _
102103

103104
if re.search(name) == null:
104-
printerr('Invalid name or namespace: "%s". You may only use letters, numbers and underscores.' % name)
105+
ModLoaderUtils.log_fatal('Invalid name or namespace: "%s". You may only use letters, numbers and underscores.' % name, LOG_NAME)
105106
return false
106107

107108
re.compile("^[a-zA-Z0-9_]{3,}$") # at least 3 long
108109
if re.search(name) == null:
109-
printerr('Invalid name or namespace: "%s". Must be longer than 3 characters.' % name)
110+
ModLoaderUtils.log_fatal('Invalid name or namespace: "%s". Must be longer than 3 characters.' % name, LOG_NAME)
110111
return false
111112

112113
return true
113114

114115

115116
# A valid semantic version should follow this format: {mayor}.{minor}.{patch}
116117
# reference https://semver.org/ for details
117-
# /^[0-9]+\\.[0-9]+\\.[0-9]+$/
118+
# {0-9}.{0-9}.{0-9} (no leading 0, shorter than 16 characters total)
118119
static func is_semver_valid(version_number: String) -> bool:
119120
var re := RegEx.new()
120-
re.compile("^[0-9]+\\.[0-9]+\\.[0-9]+$")
121+
re.compile("^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$")
121122

122123
if re.search(version_number) == null:
123-
printerr('Invalid semantic version: "%s". ' +
124-
'You may only use numbers and periods in this format {mayor}.{minor}.{patch}' % version_number)
124+
ModLoaderUtils.log_fatal('Invalid semantic version: "%s". ' +
125+
'You may only use numbers without leading zero and periods following this format {mayor}.{minor}.{patch}' % version_number,
126+
LOG_NAME
127+
)
128+
return false
129+
130+
if version_number.length() > 16:
131+
ModLoaderUtils.log_fatal('Invalid semantic version: "%s". ' +
132+
'Version number must be shorter than 16 characters.', LOG_NAME
133+
)
125134
return false
126135

127136
return true
@@ -151,7 +160,7 @@ static func dict_has_fields(dict: Dictionary, required_fields: Array) -> bool:
151160
missing_fields.erase(key)
152161

153162
if missing_fields.size() > 0:
154-
printerr("Mod data is missing required fields: " + str(missing_fields))
163+
ModLoaderUtils.log_fatal("Mod manifest is missing required fields: %s" % missing_fields, LOG_NAME)
155164
return false
156165

157166
return true

0 commit comments

Comments
 (0)