From 30c7243777aef42b2dd9da57d9fc4aecc43d2ec7 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Thu, 21 Nov 2024 23:16:08 +0100 Subject: [PATCH] added support for converting stringValues to and from Vector2 & Vector2i --- addons/godot-firebase/Utilities.gd | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/godot-firebase/Utilities.gd b/addons/godot-firebase/Utilities.gd index d9ae3b5..420de93 100644 --- a/addons/godot-firebase/Utilities.gd +++ b/addons/godot-firebase/Utilities.gd @@ -58,13 +58,14 @@ class FirebaseTypeConverter extends RefCounted: "nullValue": _to_null, "booleanValue": _to_bool, "integerValue": _to_int, - "doubleValue": _to_float + "doubleValue": _to_float, + "vector2Value": _to_vector2, + "vector2iValue": _to_vector2i } func convert_value(type, value): if converters.has(type): return converters[type].call(value) - return value func _to_null(value): @@ -78,6 +79,12 @@ class FirebaseTypeConverter extends RefCounted: func _to_float(value): return float(value) + + func _to_vector2(value): + return type_convert(value, TYPE_VECTOR2) + + func _to_vector2i(value): + return type_convert(value, TYPE_VECTOR2I) static func from_firebase_type(value): if value == null: @@ -91,7 +98,13 @@ static func from_firebase_type(value): value = Time.get_datetime_dict_from_datetime_string(value.values()[0], false) else: var converter = FirebaseTypeConverter.new() - value = converter.convert_value(value.keys()[0], value.values()[0]) + var type: String = value.keys()[0] + value = value.values()[0] + if type == "stringValue": + var split_type: String = value.split("(")[0] + if split_type in [ "Vector2", "Vector2i" ]: + type = "{0}Value".format([split_type.to_lower()]) + value = converter.convert_value(type, value) return value @@ -115,7 +128,10 @@ static func to_firebase_type(value : Variant) -> Dictionary: TYPE_ARRAY: var_type = "arrayValue" value = {"values": array2fields(value)} - + TYPE_VECTOR2, TYPE_VECTOR2I: + var_type = "stringValue" + value = var_to_str(value) + return { var_type : value } # Pass the .fields inside a Firestore Document to print out the Dictionary { 'key' : 'value' } @@ -343,4 +359,4 @@ class AwaitDetachable extends Node2D: func _init(freeable_node, await_signal : Signal) -> void: awaiter = await_signal add_child(freeable_node) - awaiter.connect(queue_free) + awaiter.connect(queue_free) \ No newline at end of file