Skip to content

Commit a0b3872

Browse files
authored
feat: new editor-only log type for dev hints (#538)
* feat: new editor only log type for dev hints * fix log string * hint color options * use hint color
1 parent 5c61730 commit a0b3872

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

addons/mod_loader/api/log.gd

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static var logged_messages := {
3131
"info": {},
3232
"success": {},
3333
"debug": {},
34+
"hint": {},
3435
}
3536
}
3637

@@ -42,6 +43,8 @@ static var verbosity: VERBOSITY_LEVEL = VERBOSITY_LEVEL.DEBUG
4243
## Array of mods that should be ignored when logging messages (contains mod IDs as strings)
4344
static var ignored_mods: Array[String] = []
4445

46+
## Highlighting color for hint type log messages
47+
static var hint_color := Color("#70bafa")
4548

4649
## This Sub-Class represents a log entry in ModLoader.
4750
class ModLoaderLogEntry:
@@ -205,6 +208,21 @@ static func debug(message: String, mod_name: String, only_once := false) -> void
205208
_log(message, mod_name, "debug", only_once)
206209

207210

211+
## Logs the message. Prefixed HINT and highligted.[br]
212+
## [br]
213+
## [i]Note: Logged with verbosity level at or above debug (-vvv) and in the editor only. Not written to mod loader log.[/i][br]
214+
## Use this to help other developers debug issues by giving them error-specific hints.[br]
215+
## [br]
216+
## [b]Parameters:[/b][br]
217+
## [param message] ([String]): The message to be logged as a debug.[br]
218+
## [param mod_name] ([String]): The name of the mod or ModLoader class associated with this log entry.[br]
219+
## [param only_once] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br]
220+
## [br]
221+
## [b]Returns:[/b] [code]void[/code]
222+
static func hint(message: String, mod_name: String, only_once := false) -> void:
223+
_log(message, mod_name, "hint", only_once)
224+
225+
208226
## Logs the message formatted with [method JSON.print]. Prefixed DEBUG.[br]
209227
## [br]
210228
## [i]Note: Logged with verbosity level at or above debug (-vvv).[/i] [br]
@@ -361,8 +379,6 @@ static func get_all_entries_as_string(log_entries: Array) -> Array:
361379
return log_entry_strings
362380

363381

364-
365-
366382
# Internal log functions
367383
# =============================================================================
368384

@@ -413,6 +429,9 @@ static func _log(message: String, mod_name: String, log_type: String = "info", o
413429
if verbosity >= VERBOSITY_LEVEL.DEBUG:
414430
print(log_entry.get_prefix() + message)
415431
_write_to_log_file(log_entry.get_entry())
432+
"hint":
433+
if OS.has_feature("editor") and verbosity >= VERBOSITY_LEVEL.DEBUG:
434+
print_rich("[color=%s]%s[/color]" % [hint_color.to_html(false), log_entry.get_prefix() + message])
416435

417436

418437
static func _is_mod_name_ignored(mod_name: String) -> bool:

addons/mod_loader/api/mod.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static func install_script_hooks(vanilla_script_path: String, hook_script_path:
100100

101101
var closest_vanilla: String = vanilla_methods.front()
102102
if closest_vanilla.similarity(hook.name) > 0.8:
103-
ModLoaderLog.debug(
103+
ModLoaderLog.hint(
104104
'Did you mean "%s" instead of "%s"?'
105105
% [closest_vanilla, hook.name], LOG_NAME
106106
)

addons/mod_loader/mod_loader.gd

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ func _init() -> void:
120120
# https://github.com/godotengine/godot/issues/19815
121121
# https://github.com/godotengine/godot/issues/16798
122122
if is_in_editor:
123-
ModLoaderLog.warning(
124-
"Loading any resource packs (.zip/.pck) with `load_resource_pack` will WIPE the entire virtual res:// directory.
125-
If you have any unpacked mods in %s, they will not be loaded.Please unpack your mod ZIPs instead, and add them to %s" %
123+
ModLoaderLog.hint(
124+
"Loading any resource packs (.zip/.pck) with `load_resource_pack` will WIPE the entire virtual res:// directory. " +
125+
"If you have any unpacked mods in %s, they will not be loaded.Please unpack your mod ZIPs instead, and add them to %s" %
126126
[_ModLoaderPath.get_unpacked_mods_dir_path(), _ModLoaderPath.get_unpacked_mods_dir_path()], LOG_NAME, true
127127
)
128128

@@ -216,9 +216,10 @@ func _ready():
216216
# Variables initialized with an autoload property cause errors otherwise.
217217
if ModLoaderStore.any_mod_hooked:
218218
if OS.has_feature("editor"):
219-
ModLoaderLog.warning("No mod hooks .zip will be created when running from the editor.", LOG_NAME)
220-
ModLoaderLog.info("You can test mod hooks by running the preprocessor on the vanilla scripts once.", LOG_NAME)
221-
ModLoaderLog.info("We recommend using the Mod Loader Dev Tool to process scripts in the editor. You can find it here: %s" % ModLoaderStore.MOD_LOADER_DEV_TOOL_URL, LOG_NAME)
219+
_ModLoaderModHookPacker.start()
220+
ModLoaderLog.hint("No mod hooks .zip will be created when running from the editor.", LOG_NAME)
221+
ModLoaderLog.hint("You can test mod hooks by running the preprocessor on the vanilla scripts once.", LOG_NAME)
222+
ModLoaderLog.hint("We recommend using the Mod Loader Dev Tool to process scripts in the editor. You can find it here: %s" % ModLoaderStore.MOD_LOADER_DEV_TOOL_URL, LOG_NAME)
222223
else:
223224
# Generate mod hooks
224225
_ModLoaderModHookPacker.start()

addons/mod_loader/mod_loader_store.gd

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,16 @@ var ml_options: ModLoaderOptionsProfile
118118
func _init():
119119
_update_ml_options_from_options_resource()
120120
_update_ml_options_from_cli_args()
121+
_configure_logger()
121122
# ModLoaderStore is passed as argument so the cache data can be loaded on _init()
122123
_ModLoaderCache.init_cache(self)
123124

124125

126+
func _exit_tree() -> void:
127+
# Save the cache to the cache file.
128+
_ModLoaderCache.save_to_file()
129+
130+
125131
# Update ModLoader's options, via the custom options resource
126132
func _update_ml_options_from_options_resource() -> void:
127133
# Path to the options resource
@@ -178,11 +184,6 @@ func _update_ml_options_from_options_resource() -> void:
178184
ml_options = override_options
179185

180186

181-
func _exit_tree() -> void:
182-
# Save the cache to the cache file.
183-
_ModLoaderCache.save_to_file()
184-
185-
186187
# Update ModLoader's options, via CLI args
187188
func _update_ml_options_from_cli_args() -> void:
188189
# Disable mods
@@ -217,3 +218,10 @@ func _update_ml_options_from_cli_args() -> void:
217218
var ignore_mod_names := _ModLoaderCLI.get_cmd_line_arg_value("--log-ignore")
218219
if not ignore_mod_names == "":
219220
ml_options.ignored_mod_names_in_log = ignore_mod_names.split(",")
221+
222+
223+
# Update static variables from the options
224+
func _configure_logger() -> void:
225+
ModLoaderLog.verbosity = ml_options.log_level
226+
ModLoaderLog.ignored_mods = ml_options.ignored_mod_names_in_log
227+
ModLoaderLog.hint_color = ml_options.hint_color

addons/mod_loader/resources/options_profile.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extends Resource
2121
## [code]ModLoader:Dependency[/code] - ignore the exact name [br]
2222
## [code]ModLoader:*[/code] - ignore all beginning with this name [br]
2323
@export var ignored_mod_names_in_log: Array[String] = []
24+
@export var hint_color := Color("#70bafa")
2425

2526
@export_group("Game Data")
2627
## Steam app id, can be found in the steam page url

0 commit comments

Comments
 (0)