Skip to content

Commit

Permalink
fix saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Jun 30, 2024
1 parent 6833a77 commit 0629791
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/happyx_native/abstract/saving.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ proc save*[T: enum](filename: string, data: T) =
filename.save(data.symbolName)


proc loadString*(filename: string): string =
proc loadImpl[T](filename: string): string =
## Loads string from filename
##
## On Android it uses SharedPreferences to data loading
Expand All @@ -78,7 +78,7 @@ proc loadString*(filename: string): string =
if not dirExists(getHomeDir() / "hpxnative"):
createDir(getHomeDir() / "hpxnative")
if not fileExists(getHomeDir() / "hpxnative" / filename):
return `tdesc`.default
return T.default
var
userFolder = getHomeDir() / "hpxnative" / filename
f = open(userFolder, fmRead)
Expand All @@ -87,57 +87,65 @@ proc loadString*(filename: string): string =
return data


proc loadString*(filename: string): JsonNode =
## Loads JSON from filename
##
## On Android it uses SharedPreferences to data loading
##
return load[string](filename)


proc loadJson*(filename: string): JsonNode =
## Loads JSON from filename
##
## On Android it uses SharedPreferences to data loading
##
return parseJson(filename.loadString())
return parseJson(load[JsonNode](filename))


proc loadInt*(filename: string): int =
## Loads integer from filename
##
## On Android it uses SharedPreferences to data loading
##
return parseInt(filename.loadString())
return parseInt(load[int](filename))


proc loadFloat*(filename: string): float =
## Loads float from filename
##
## On Android it uses SharedPreferences to data loading
##
return parseFloat(filename.loadString())
return parseFloat(load[float](filename))


proc loadBool*(filename: string): bool =
## Loads boolean from filename
##
## On Android it uses SharedPreferences to data loading
##
return parseBool(filename.loadString())
return parseBool(load[bool](filename))


proc loadHexInt*(filename: string): int =
## Loads integer from filename
##
## On Android it uses SharedPreferences to data loading
##
return parseHexInt(filename.loadString())
return parseHexInt(load[int](filename))


proc loadOctInt*(filename: string): int =
## Loads integer from filename
##
## On Android it uses SharedPreferences to data loading
##
return parseOctInt(filename.loadString())
return parseOctInt(load[int](filename))


proc loadEnum*[T: enum](filename: string): T =
## Loads integer from filename
##
## On Android it uses SharedPreferences to data loading
##
return parseEnum[T](filename.loadString())
return parseEnum[T](load[T](filename))

0 comments on commit 0629791

Please sign in to comment.