Skip to content

Commit bac6dbd

Browse files
Merge pull request #448 from xzirox/main
added support for converting stringValues to and from Vector2 & Vector2i
2 parents 52c17c9 + 30c7243 commit bac6dbd

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

addons/godot-firebase/Utilities.gd

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ class FirebaseTypeConverter extends RefCounted:
5858
"nullValue": _to_null,
5959
"booleanValue": _to_bool,
6060
"integerValue": _to_int,
61-
"doubleValue": _to_float
61+
"doubleValue": _to_float,
62+
"vector2Value": _to_vector2,
63+
"vector2iValue": _to_vector2i
6264
}
6365

6466
func convert_value(type, value):
6567
if converters.has(type):
6668
return converters[type].call(value)
67-
6869
return value
6970

7071
func _to_null(value):
@@ -78,6 +79,12 @@ class FirebaseTypeConverter extends RefCounted:
7879

7980
func _to_float(value):
8081
return float(value)
82+
83+
func _to_vector2(value):
84+
return type_convert(value, TYPE_VECTOR2)
85+
86+
func _to_vector2i(value):
87+
return type_convert(value, TYPE_VECTOR2I)
8188

8289
static func from_firebase_type(value):
8390
if value == null:
@@ -91,7 +98,13 @@ static func from_firebase_type(value):
9198
value = Time.get_datetime_dict_from_datetime_string(value.values()[0], false)
9299
else:
93100
var converter = FirebaseTypeConverter.new()
94-
value = converter.convert_value(value.keys()[0], value.values()[0])
101+
var type: String = value.keys()[0]
102+
value = value.values()[0]
103+
if type == "stringValue":
104+
var split_type: String = value.split("(")[0]
105+
if split_type in [ "Vector2", "Vector2i" ]:
106+
type = "{0}Value".format([split_type.to_lower()])
107+
value = converter.convert_value(type, value)
95108

96109
return value
97110

@@ -115,7 +128,10 @@ static func to_firebase_type(value : Variant) -> Dictionary:
115128
TYPE_ARRAY:
116129
var_type = "arrayValue"
117130
value = {"values": array2fields(value)}
118-
131+
TYPE_VECTOR2, TYPE_VECTOR2I:
132+
var_type = "stringValue"
133+
value = var_to_str(value)
134+
119135
return { var_type : value }
120136

121137
# Pass the .fields inside a Firestore Document to print out the Dictionary { 'key' : 'value' }
@@ -343,4 +359,4 @@ class AwaitDetachable extends Node2D:
343359
func _init(freeable_node, await_signal : Signal) -> void:
344360
awaiter = await_signal
345361
add_child(freeable_node)
346-
awaiter.connect(queue_free)
362+
awaiter.connect(queue_free)

0 commit comments

Comments
 (0)