offsets and overlay properties are saved to settings.json

This commit is contained in:
Crispy 2021-05-25 18:56:52 +02:00
parent c51d4aa91d
commit 70892dcb7b
3 changed files with 42 additions and 5 deletions

View file

@ -88,6 +88,7 @@ func finish_move():
# reset current_target (parent handles fallback) # reset current_target (parent handles fallback)
get_parent().update_current_target() get_parent().update_current_target()
get_parent().save_settings()
_update_target() _update_target()
is_moving = false is_moving = false

View file

@ -30,10 +30,6 @@ onready var container = $OverlayViewport/Container
func _ready() -> void: func _ready() -> void:
current_target = target current_target = target
# TEMP
offsets[current_target].pos = translation
offsets[current_target].rot = transform.basis.get_rotation_quat()
###
ARVRServer.connect("tracker_added", self, "_tracker_changed") ARVRServer.connect("tracker_added", self, "_tracker_changed")
ARVRServer.connect("tracker_removed", self, "_tracker_changed") ARVRServer.connect("tracker_removed", self, "_tracker_changed")
@ -48,6 +44,46 @@ func _ready() -> void:
emit_signal("target_changed") emit_signal("target_changed")
set_notify_transform(true) set_notify_transform(true)
call_deferred("load_settings")
func load_settings():
if Settings.s.overlays.has(name):
target = Settings.s.overlays[name].target
# TODO target fallback
update_current_target()
set_width_in_meters(Settings.s.overlays[name].width)
for t_key in Settings.s.overlays[name].offsets:
var t_offset = Settings.s.overlays[name].offsets[t_key]
offsets[t_key].pos = t_offset.pos
offsets[t_key].rot = t_offset.rot
update_offset()
else:
#TEMP defaults
offsets[current_target].pos = translation
offsets[current_target].rot = transform.basis.get_rotation_quat()
update_offset()
####
Settings.s.overlays[name] = {}
save_settings()
func save_settings():
Settings.s.overlays[name].target = target
Settings.s.overlays[name].width = width_meters
if not Settings.s.overlays[name].has("offsets"):
Settings.s.overlays[name]["offsets"] = {}
for t_key in offsets:
if not Settings.s.overlays[name].offsets.has(t_key):
Settings.s.overlays[name].offsets[t_key] = {}
Settings.s.overlays[name].offsets[t_key].pos = offsets[t_key].pos
Settings.s.overlays[name].offsets[t_key].rot = offsets[t_key].rot
Settings.save_settings()
func update_tracker_id() -> void: func update_tracker_id() -> void:
_tracker_id = -1 _tracker_id = -1

View file

@ -3,7 +3,7 @@ extends Node
signal settings_saved signal settings_saved
signal settings_loaded # emitted when settings are loaded from file, needs to be connected in _init() signal settings_loaded # emitted when settings are loaded from file, needs to be connected in _init()
var DEBUG_SETTINGS = true var DEBUG_SETTINGS = false
var SETTINGS_PATH = "user://settings.json" var SETTINGS_PATH = "user://settings.json"
const SETTINGS_DEF = preload("res://addons/settings-manager/settings_definition.gd").DEF const SETTINGS_DEF = preload("res://addons/settings-manager/settings_definition.gd").DEF