Skip to content

Commit

Permalink
Update so fields have correct types
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangSenff committed Jun 27, 2024
1 parent 091aa11 commit fa306a5
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions addons/godot-firebase/Utilities.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,50 @@ static func dict2fields(dict : Dictionary) -> Dictionary:

return {'fields' : fields}

static func from_firebase_type(value : Variant) -> Variant:

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

func convert_value(type, value):
if converters.has(type):
return converters[type].call(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

if value.has("mapValue"):
value = fields2dict(value.values()[0])
elif value.has("arrayValue"):
value = fields2array(value.values()[0])
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


static func to_firebase_type(value : Variant) -> Dictionary:
var var_type : String = ""

Expand Down

0 comments on commit fa306a5

Please sign in to comment.