Skip to content

Commit

Permalink
refactor: move config from editor- to projectSettings
Browse files Browse the repository at this point in the history
EditorSettings are per-machine and not accessible when starting
scenes (even from the editor). So instead we use the projectSettings,
to at least get these config vals going.

This might make more sense than editor settings, and could be useful to
override with feature tags and what not.

Still a bit of a mess, naming-wise, and seems to throw errors before the
settings have been created in the project :/
  • Loading branch information
russmatney committed Jun 7, 2024
1 parent 2a4f1c2 commit 0251bdb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
24 changes: 15 additions & 9 deletions addons/log/log.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ static func assoc(opts: Dictionary, key: String, val):

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

const KEY_PREFIX = "Loggd"
const KEY_PREFIX = "log_gd/config"
static var is_config_setup = false

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", [
static func setup_config(opts={}):
var keys = opts.get("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)
if ProjectSettings.has_setting(key):
Log.config[key] = ProjectSettings.get_setting(key)
else:
editor_settings.set_setting(key, Log.config.get(key))
ProjectSettings.set_initial_value(key, Log.config.get(key))
# ProjectSettings.set_setting(key, Log.config[key])

print("updated config", Log.config)
Log.is_config_setup = true

static var config = {
# TODO convert to selecting a scheme by name
Expand Down Expand Up @@ -60,7 +63,7 @@ static func get_config_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))
# ProjectSettings.set_setting(key, config.get(key))

static func disable_colors():
Log.config[KEY_DISABLE_COLORS] = true
Expand Down Expand Up @@ -439,6 +442,9 @@ static func log_prefix(stack):
return "[" + basename + ":" + line_num + "]: "

static func to_printable(msgs, opts={}):
if not Log.is_config_setup:
setup_config()

var stack = opts.get("stack", [])
var pretty = opts.get("pretty", true)
var newlines = opts.get("newlines", false)
Expand Down
12 changes: 3 additions & 9 deletions addons/log/plugin.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
@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)
Log.pr("log.gd entering tree")
ProjectSettings.settings_changed.connect(on_settings_changed)

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})
Log.setup_config()
12 changes: 12 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ enabled=PackedStringArray("res://addons/gdUnit4/plugin.cfg", "res://addons/log/p

report/godot/push_error=true
settings/common/update_notification_enabled=false

[log_gd]

config/color_scheme={}
config/max_array_size=11
config/dictionary_skip_keys=["layer_0/tile_data"]
config/disable_colors=false

[rendering]

renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
2 changes: 2 additions & 0 deletions src/ExampleScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ func _enter_tree():
Log.set_colors_pretty()
# Log.disable_colors()

Log.info(Log.config)

class ExampleObj:
var val
func _init(v):
Expand Down

0 comments on commit 0251bdb

Please sign in to comment.