add timer to sync overlay properties at most every 0.2s

This commit is contained in:
Crispy 2021-06-26 23:48:18 +02:00
parent 2ff72e5023
commit 078cd11e5e
3 changed files with 27 additions and 9 deletions

View file

@ -4,3 +4,9 @@
[node name="OverlaySettingsSync" type="Node"] [node name="OverlaySettingsSync" type="Node"]
script = ExtResource( 1 ) 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"]

View file

@ -3,20 +3,25 @@ extends Node
onready var p = get_parent() onready var p = get_parent()
var loaded := false var loaded := false
var _needs_sync := true
func _ready() -> void: func _ready() -> void:
p = get_parent() p = get_parent()
call_deferred("load_all") call_deferred("load_all")
p.connect("type_changed", self, "save_all") p.connect("type_changed", self, "_prop_changed")
p.connect("overlay_visible_changed", self, "save_all") p.connect("overlay_visible_changed", self, "_prop_changed")
p.connect("width_changed", self, "save_all") p.connect("width_changed", self, "_prop_changed")
p.connect("alpha_changed", self, "save_all") p.connect("alpha_changed", self, "_prop_changed")
p.connect("target_changed", self, "save_all") p.connect("target_changed", self, "_prop_changed")
p.connect("fallback_changed", self, "save_all") p.connect("fallback_changed", self, "_prop_changed")
p.connect("offset_changed", self, "save_all") 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: if not loaded:
return return
if not Settings.s.overlays.has(p.name): 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("target", p.target)
_save_prop("fallback", p.fallback) _save_prop("fallback", p.fallback)
_save_prop("offsets", p._offsets.duplicate(true)) _save_prop("offsets", p._offsets.duplicate(true))
_needs_sync = false
func _save_prop(prop_name: String, prop_value) -> void: func _save_prop(prop_name: String, prop_value) -> void:
@ -58,3 +64,9 @@ func load_all() -> void:
print("FAILED") print("FAILED")
save_all() save_all()
loaded = true loaded = true
func _on_SyncTimer_timeout() -> void:
if _needs_sync:
save_all()