Skip to content

Commit 50acb86

Browse files
xziroxMarcus Andersson
and
Marcus Andersson
authored
fixed being able to load a string into a Vector2/Vector2i (#450)
* fixed being able to load a string into a Vector2/Vector2i * added function has_changes_pending() to documents Allows you to see if theres any additions or changes in a document awaiting an update to the collection, see #451 --------- Co-authored-by: Marcus Andersson <marcus.andersson@maloria.org>
1 parent bac6dbd commit 50acb86

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

addons/godot-firebase/Utilities.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ class FirebaseTypeConverter extends RefCounted:
8181
return float(value)
8282

8383
func _to_vector2(value):
84-
return type_convert(value, TYPE_VECTOR2)
84+
return str_to_var(value) as Vector2
8585

8686
func _to_vector2i(value):
87-
return type_convert(value, TYPE_VECTOR2I)
87+
return str_to_var(value) as Vector2i
8888

8989
static func from_firebase_type(value):
9090
if value == null:

addons/godot-firebase/firestore/firestore_collection.gd

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func update(document : FirestoreDocument) -> FirestoreDocument:
110110

111111
if temp_transforms != null:
112112
result._transforms = temp_transforms
113+
114+
document.field_added_or_updated = false
113115

114116
return result
115117

addons/godot-firebase/firestore/firestore_document.gd

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var doc_name : String # only .name
1616
var create_time : String # createTime
1717
var collection_name : String # Name of the collection to which it belongs
1818
var _transforms : FieldTransformArray # The transforms to apply
19+
var field_added_or_updated : bool # true or false if anything has been added or updated since the last update()
1920
signal changed(changes)
2021

2122
func _init(doc : Dictionary = {}):
@@ -129,7 +130,7 @@ func add_or_update_field(field_path : String, value : Variant) -> void:
129130
changes.updated.push_back({ "key" : field_path, "old" : existing_value, "new" : value })
130131
else:
131132
changes.added.push_back({ "key" : field_path, "new" : value })
132-
133+
field_added_or_updated = true
133134
changed.emit(changes)
134135

135136
func on_snapshot(when_called : Callable, poll_time : float = 1.0) -> FirestoreListener.FirestoreListenerConnection:
@@ -159,6 +160,9 @@ func get_value(property : StringName) -> Variant:
159160

160161
return null
161162

163+
func has_changes_pending() -> bool:
164+
return field_added_or_updated
165+
162166
func _get(property: StringName) -> Variant:
163167
return get_value(property)
164168

@@ -182,4 +186,4 @@ func _to_string() -> String:
182186
return ("doc_name: {doc_name}, \ndata: {data}, \ncreate_time: {create_time}\n").format(
183187
{doc_name = self.doc_name,
184188
data = document,
185-
create_time = self.create_time})
189+
create_time = self.create_time})

0 commit comments

Comments
 (0)