From 078cd11e5ec83a86fee6ca0fd33baa99a2022386 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 26 Jun 2021 23:48:18 +0200 Subject: [PATCH] add timer to sync overlay properties at most every 0.2s --- ovr-utils/OverlaySettingsSync.tscn | 6 ++++ .../addons/openvr_overlay/overlay_instance.gd | 2 +- ovr-utils/overlay_settings_sync.gd | 28 +++++++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) 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() +