From 6960082253fecd71e069ba33f57c2555ecaf032b Mon Sep 17 00:00:00 2001 From: Florent Berthaut <florent.berthaut@univ-lille.fr> Date: Fri, 6 Oct 2023 23:45:01 +0200 Subject: [PATCH] Added variable property size mechanism --- core/IvmiNode.gd | 13 ++----------- core/IvmiProperty.gd | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/core/IvmiNode.gd b/core/IvmiNode.gd index a53a245..cf7cb80 100644 --- a/core/IvmiNode.gd +++ b/core/IvmiNode.gd @@ -46,18 +46,9 @@ func declare() : func _allow_send_data(value : bool): _send_data = value -func _add_property(prop, values) : +func _add_property(prop, values) -> void : _properties[prop] = load("res://addons/ivmi-builder/core/IvmiProperty.gd").new() - _properties[prop].set_values(values) - var tags = "" - for v in values : - if v is float : - tags+="f" - elif v is int : - tags+="f" - elif v is String : - tags+="s" - _properties[prop].set_tags(tags) + _properties[prop].init_values(values) _properties[prop].set_ivmi_node(self) _properties[prop].set_name(prop) diff --git a/core/IvmiProperty.gd b/core/IvmiProperty.gd index 49a26be..4316385 100644 --- a/core/IvmiProperty.gd +++ b/core/IvmiProperty.gd @@ -11,16 +11,33 @@ var _tags = "" var _immediate = false var _ivmi_node = null -func set_values(vals) : - for v in range(0, min(_values.size(), vals.size())) : - if vals[v] != _values[v] : - _changed=true - _values.assign(vals) + +func set_values(vals : Array) : + if vals.size() == _values.size() : + for v in range(0, min(_values.size(), vals.size())) : + if vals[v] != _values[v] : + _changed=true + _values.assign(vals) + else : + init_values(vals) if _immediate and _listen : _changed = false _ivmi_node.send_prop(_name) +func init_values(vals : Array) : + var tags = "" + for v in vals : + if v is float : + tags+="f" + elif v is int : + tags+="f" + elif v is String : + tags+="s" + set_tags(tags) + _values.assign(vals) + _changed=true + func set_tags(t): _tags=t -- GitLab