diff --git a/ovr-utils/OverlaySettingsSync.tscn b/ovr-utils/OverlaySettingsSync.tscn index 8cda710..45c2bf8 100644 --- a/ovr-utils/OverlaySettingsSync.tscn +++ b/ovr-utils/OverlaySettingsSync.tscn @@ -4,3 +4,9 @@ [node name="OverlaySettingsSync" type="Node"] script = ExtResource( 1 ) + +[node name="SyncTimer" type="Timer" parent="."] +wait_time = 0.2 +autostart = true + +[connection signal="timeout" from="SyncTimer" to="." method="_on_SyncTimer_timeout"] diff --git a/ovr-utils/addons/openvr_overlay/overlay_instance.gd b/ovr-utils/addons/openvr_overlay/overlay_instance.gd index b3a75ec..11f0296 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_instance.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_instance.gd @@ -14,7 +14,7 @@ export (String, "head", "left", "right", "world") var target = "left" setget se export var overlay_scene: PackedScene = \ preload("res://addons/openvr_overlay/MissingOverlay.tscn") setget set_overlay_scene export var width_meters := 0.4 setget set_width_in_meters -export var alpha := 1.0 setget set_alpha +export var alpha := 1.0 setget set_alpha export var add_grabbing := true # add grabbing module export var add_cursor := false # add cursor module diff --git a/ovr-utils/overlay_settings_sync.gd b/ovr-utils/overlay_settings_sync.gd index 6d3bea1..1ea42e8 100644 --- a/ovr-utils/overlay_settings_sync.gd +++ b/ovr-utils/overlay_settings_sync.gd @@ -3,20 +3,25 @@ extends Node onready var p = get_parent() var loaded := false +var _needs_sync := true func _ready() -> void: p = get_parent() call_deferred("load_all") - p.connect("type_changed", self, "save_all") - p.connect("overlay_visible_changed", self, "save_all") - p.connect("width_changed", self, "save_all") - p.connect("alpha_changed", self, "save_all") - p.connect("target_changed", self, "save_all") - p.connect("fallback_changed", self, "save_all") - p.connect("offset_changed", self, "save_all") + p.connect("type_changed", self, "_prop_changed") + p.connect("overlay_visible_changed", self, "_prop_changed") + p.connect("width_changed", self, "_prop_changed") + p.connect("alpha_changed", self, "_prop_changed") + p.connect("target_changed", self, "_prop_changed") + p.connect("fallback_changed", self, "_prop_changed") + p.connect("offset_changed", self, "_prop_changed") -func save_all(_args=null) -> void: +func _prop_changed(_val=null): + _needs_sync = true + + +func save_all() -> void: if not loaded: return if not Settings.s.overlays.has(p.name): @@ -28,6 +33,7 @@ func save_all(_args=null) -> void: _save_prop("target", p.target) _save_prop("fallback", p.fallback) _save_prop("offsets", p._offsets.duplicate(true)) + _needs_sync = false func _save_prop(prop_name: String, prop_value) -> void: @@ -58,3 +64,9 @@ func load_all() -> void: print("FAILED") save_all() loaded = true + + +func _on_SyncTimer_timeout() -> void: + if _needs_sync: + save_all() +