Skip to content

Commit

Permalink
Use Option for optional pdxinfo fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Nycto committed Feb 26, 2025
1 parent ed9b994 commit 1f220bd
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/playdate/build/pdxinfo.nim
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import std/[os, parsecfg, streams, strutils, strformat, times, osproc], nimbledump
import std/[os, parsecfg, streams, strutils, strformat, times, osproc, options], nimbledump

type PdxInfo* = object
## Details used to populate the pdxinfo file
name*, author*, description*, bundleId*, imagePath*, version*: string
buildNumber*, launchSoundPath*, contentWarning*, contentWarning2*: string
name*, author*, description*, bundleId*, imagePath*, version*, buildNumber*: string
launchSoundPath*, contentWarning*, contentWarning2*: Option[string]

proc isSome(value: string): bool = not value.isEmptyOrWhitespace

proc `$`*(pdx: PdxInfo): string =
for key, value in pdx.fieldPairs:
if value != "":
result &= key & "=" & value & "\n"
if value.isSome:
let str = when value is Option: value.get() else: value
result &= key & "=" & str & "\n"

proc write*(pdx: PdxInfo) =
## Writes the pdxinfo file
Expand All @@ -19,14 +22,16 @@ proc join*(a, b: PdxInfo): PdxInfo =
## Combins two PdxInfo instances
result = a
for current, override in fields(result, b):
if override != "":
if override.isSome:
current = override

proc parsePdx*(data: Stream, filename: string): PdxInfo =
## Parses a pdx config from a string
let dict = loadConfig(data, filename)
for key, value in result.fieldPairs:
value = dict.getSectionValue("", key)
let raw = dict.getSectionValue("", key)
if raw != "":
value = when typeof(value) is Option: some(raw) else: raw

proc readPdx*(path: string): PdxInfo =
## Creates a pdx by reading a local pxinfo file
Expand Down

0 comments on commit 1f220bd

Please sign in to comment.