@@ -2,6 +2,7 @@ extends Resource
2
2
# Stores and validates contents of the manifest set by the user
3
3
class_name ModManifest
4
4
5
+ const LOG_NAME := "ModLoader:ModManifest"
5
6
6
7
# Mod name.
7
8
# Validated by [method is_name_or_namespace_valid]
@@ -95,33 +96,41 @@ func get_package_id() -> String:
95
96
96
97
# A valid namespace may only use letters (any case), numbers and underscores
97
98
# 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)
99
100
static func is_name_or_namespace_valid (name : String ) -> bool :
100
101
var re := RegEx .new ()
101
102
re .compile ("^[a-zA-Z0-9_]*$" ) # alphanumeric and _
102
103
103
104
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 )
105
106
return false
106
107
107
108
re .compile ("^[a-zA-Z0-9_]{3,}$" ) # at least 3 long
108
109
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 )
110
111
return false
111
112
112
113
return true
113
114
114
115
115
116
# A valid semantic version should follow this format: {mayor}.{minor}.{patch}
116
117
# 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)
118
119
static func is_semver_valid (version_number : String ) -> bool :
119
120
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]*) $" )
121
122
122
123
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
+ )
125
134
return false
126
135
127
136
return true
@@ -151,7 +160,7 @@ static func dict_has_fields(dict: Dictionary, required_fields: Array) -> bool:
151
160
missing_fields .erase (key )
152
161
153
162
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 )
155
164
return false
156
165
157
166
return true
0 commit comments