Skip to content

Commit

Permalink
Update so Firestore field types are correct
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangSenff committed Jun 27, 2024
1 parent 91de29f commit d610db3
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion addons/godot-firebase/Utilities.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ static func dict2fields(dict : Dictionary) -> Dictionary:

return {'fields' : fields}

class FirebaseTypeConverter extends Reference:
var converters = {
"nullValue": "_to_null",
"booleanValue": "_to_bool",
"integerValue": "_to_int",
"doubleValue": "_to_float"
}

func convert_value(type, value):
if converters.has(type):
return call(converters[type], value)

return value

func _to_null(value):
return null

func _to_bool(value):
return bool(value)

func _to_int(value):
return int(value)

func _to_float(value):
return float(value)

static func from_firebase_type(value):
if value == null:
return null
Expand All @@ -62,7 +88,8 @@ static func from_firebase_type(value):
elif value.has("timestampValue"):
value = Time.get_datetime_dict_from_datetime_string(value.values()[0], false)
else:
value = value.values()[0]
var converter = FirebaseTypeConverter.new()
value = converter.convert_value(value.keys()[0], value.values()[0])

return value

Expand Down

0 comments on commit d610db3

Please sign in to comment.