upgrade settings manager, add default overlay in settings definition

This commit is contained in:
Crispy 2021-05-24 12:39:37 +02:00
parent 919319cc83
commit c51d4aa91d
2 changed files with 80 additions and 52 deletions

View file

@ -5,57 +5,7 @@ signal settings_loaded # emitted when settings are loaded from file, needs to be
var DEBUG_SETTINGS = true var DEBUG_SETTINGS = true
var SETTINGS_PATH = "user://settings.json" var SETTINGS_PATH = "user://settings.json"
const SETTINGS_DEF = { const SETTINGS_DEF = preload("res://addons/settings-manager/settings_definition.gd").DEF
"grab_mode": {
"name": "Grab mode",
"description": "Grab and drag around any overlay",
"flags": ["no_save"],
"type": "bool",
"default": false
},
"overlays": {
"name": "Settings for all overlays",
"type": "dict",
"flags": ["resize"],
"definition": {
"type": "dict",
"definition": {
"width": {
"name": "Width (m)",
"type": "number",
"default": 0.4
},
"target": {
"name": "Tracking target",
"type": "string",
"default": "world"
},
"fallback": {
"name": "Target fallback priority order",
"type": "array",
"default": ["world"]
},
"offsets": {
"name": "Offsets",
"flags": ["resize"],
"type": "dict",
"definition": {
"pos": {
"name": "Offset position",
"type": "vector3",
"default": Vector3()
},
"rot": {
"name": "Offset rotation",
"type": "quat",
"default": Quat()
}
}
}
}
}
}
}
var s: Dictionary = {} var s: Dictionary = {}
@ -77,7 +27,7 @@ func _init_sub_setting(def):
match def.type: match def.type:
"dict": "dict":
if has_flag(def, "resize"): if has_flag(def, "resize"):
return {} return def.default
var _s = {} var _s = {}
for key in def.definition: for key in def.definition:
_s[key] = _init_sub_setting(def.definition[key]) _s[key] = _init_sub_setting(def.definition[key])

View file

@ -0,0 +1,78 @@
extends Node
const DEF = {
"grab_mode": {
"name": "Grab mode",
"description": "Grab and drag around any overlay",
"flags": ["no_save"],
"type": "bool",
"default": false
},
"overlays": {
"name": "Settings for all overlays",
"type": "dict",
"flags": ["resize"],
"definition": {
"type": "dict",
"definition": {
"width": {
"name": "Width (m)",
"type": "number",
"default": 0.4
},
"target": {
"name": "Tracking target",
"type": "string",
"default": "world"
},
"fallback": {
"name": "Target fallback priority order",
"type": "array",
"default": ["world"]
},
"offsets": {
"name": "Offsets",
"flags": ["resize"],
"type": "dict",
"definition": {
"type": "dict",
"definition":{
"pos": {
"name": "Offset position",
"type": "vector3",
"default": Vector3()
},
"rot": {
"name": "Offset rotation",
"type": "quat",
"default": Quat()
}
}
},
"default": {}
}
}
},
"default": {
"main": {
"width": 0.4,
"target": "left",
"fallback": ["left", "right", "head"],
"offsets": {
"left": {
"pos": Vector3(),
"rot": Quat(),
},
"right": {
"pos": Vector3(),
"rot": Quat(),
},
"head": {
"pos": Vector3(0,0,-0.5),
"rot": Quat(),
},
}
}
}
}
}