Skip to content

Commit

Permalink
feat: introduce Log.gd editor-settings
Browse files Browse the repository at this point in the history
Hooks into the editor_settings.settings_changed signal - towards
supporting setting custom values for Log.gd config options, such as
disable_colors and max_array_size. Not _quite_ working, but this is the
bulk of the work.
  • Loading branch information
russmatney committed Jun 6, 2024
1 parent a1cc3e2 commit 4b137b7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
56 changes: 43 additions & 13 deletions addons/log/log.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,65 @@ static func assoc(opts: Dictionary, key: String, val):

## config ####################################

const KEY_PREFIX = "Loggd"

const KEY_COLOR_SCHEME = "%s/color_scheme" % KEY_PREFIX
const KEY_DISABLE_COLORS = "%s/disable_colors" % KEY_PREFIX
const KEY_MAX_ARRAY_SIZE = "%s/max_array_size" % KEY_PREFIX
const KEY_SKIP_KEYS = "%s/dictionary_skip_keys" % KEY_PREFIX

static func setup_config(editor_settings, opts={}):
var keys = opts.get("update_keys", [
KEY_COLOR_SCHEME,
KEY_DISABLE_COLORS,
KEY_MAX_ARRAY_SIZE,
KEY_SKIP_KEYS,
])

for key in keys:
editor_settings.set_initial_value(key, Log.config.get(key), false)

if editor_settings.has_setting(key):
Log.config[key] = editor_settings.get_setting(key)
else:
editor_settings.set_setting(key, Log.config.get(key))

static var config = {
max_array_size=20,
dictionary_skip_keys=[
# TODO convert to selecting a scheme by name
KEY_COLOR_SCHEME: {},
KEY_DISABLE_COLORS: false,
KEY_MAX_ARRAY_SIZE: 20,
KEY_SKIP_KEYS: [
"layer_0/tile_data", # skip huge tilemap arrays
],
color_scheme={},
disable_colors=false,
}

## config getters

static func get_max_array_size():
return Log.config.get("max_array_size", 20)
return Log.config.get(KEY_MAX_ARRAY_SIZE, 20)

static func get_dictionary_skip_keys():
return Log.config.get("dictionary_skip_keys", [])
return Log.config.get(KEY_SKIP_KEYS, [])

static func get_disable_colors():
return Log.config.get("disable_colors", false)
return Log.config.get(KEY_DISABLE_COLORS, false)

static func get_config_color_scheme():
return Log.config.get(KEY_COLOR_SCHEME, {})

## config setters
# consider setting the editor-settings values of these when the funcs are called
# editor_settings.set_setting(key, config.get(key))

static func disable_colors():
Log.config["disable_colors"] = true
Log.config[KEY_DISABLE_COLORS] = true

static func enable_colors():
Log.config["disable_colors"] = false
Log.config[KEY_DISABLE_COLORS] = false

static func set_color_scheme(scheme):
Log.config["color_scheme"] = scheme

static func get_config_color_scheme():
return Log.config.get("color_scheme", {})
Log.config[KEY_COLOR_SCHEME] = scheme

## colors ###########################################################################

Expand Down
12 changes: 12 additions & 0 deletions addons/log/plugin.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
@tool
extends EditorPlugin

var editor_settings

func _enter_tree():
editor_settings = get_editor_interface().get_editor_settings()
editor_settings.settings_changed.connect(on_settings_changed)

Log.setup_config(editor_settings)

func on_settings_changed():
if editor_settings.check_changed_settings_in_group(Log.KEY_PREFIX):
var changed_keys = editor_settings.get_changed_settings()
Log.setup_config(editor_settings, {updated_keys=changed_keys})
7 changes: 3 additions & 4 deletions src/ExampleScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extends CanvasLayer

func _enter_tree():
print("\\033[31mHello\\033[0m")
# print("\\033[31mHello\\033[0m")

Log.set_colors_pretty()
# Log.disable_colors()
Expand All @@ -12,7 +12,7 @@ class ExampleObj:
func _init(v):
val = v

func to_printable():
func to_pretty():
return {val=val, id=get_instance_id()}

@export var some_custom_types : Array[SomeResource]
Expand Down Expand Up @@ -41,5 +41,4 @@ func _ready():
Log.pr("disabled colors")
print_rich(Log.to_pretty(1, {disable_colors=true}))

print("\\033[31;1;4mHello\\033[0m")

# print("\\033[31;1;4mHello\\033[0m")

0 comments on commit 4b137b7

Please sign in to comment.