Skip to content

Add writeIniFile() for song.ini emission#100

Open
elicwhite wants to merge 2 commits into
Geomitron:masterfrom
elicwhite:write-ini-file
Open

Add writeIniFile() for song.ini emission#100
elicwhite wants to merge 2 commits into
Geomitron:masterfrom
elicwhite:write-ini-file

Conversation

@elicwhite
Copy link
Copy Markdown
Contributor

Context

First of the upstream writer stack: adds `song.ini` serialization.

```ts
export function writeIniFile(metadata: IniMetadata): string
export type IniMetadata = Partial & {
extraIniFields?: { [key: string]: string }
}
```

Emission rules

  • `[song]` header
  • Known fields emitted in the canonical `defaultMetadata` order (derived from `Object.keys(defaultMetadata)` — no hardcoded field list, so new fields added to `defaultMetadata` automatically participate in writing)
  • Fields whose value is `undefined` are skipped
  • Booleans format as `True`/`False` (Clone Hero convention)
  • `extraIniFields` appended after known fields, in insertion order
  • CRLF line endings

Round-trips cleanly through `scanIni`.

Depends on

PRs #97 + #98 + #99 — stacked above them.

Builds a minimal valid ParsedChart from scratch: default 480 resolution,
120 BPM at tick 0, 4/4 time signature at tick 0, empty tracks/sections/
metadata/vocal parts/unrecognized events. chartBytes defaults to an empty
Uint8Array (no source bytes), format defaults to 'chart', iniChartModifiers
to the library defaults.

Options let callers override resolution, bpm, timeSignature, and format.

Useful for programmatic chart generation (e.g. downstream code that builds
charts up from scratch rather than parsing source bytes).
Serializes IniMetadata (Partial<typeof defaultMetadata> + extraIniFields)
back to song.ini text with:
- [song] header
- Known fields emitted in the canonical defaultMetadata order
- Undefined values skipped
- Booleans as True/False (Clone Hero convention)
- extraIniFields appended in insertion order
- CRLF line endings

Derives its field order from Object.keys(defaultMetadata) rather than
hardcoding a separate FIELD_ORDER list, so new fields added to
defaultMetadata automatically participate in writing.

Tests exercise writeIniFile only via round-trip through parseChartAndIni,
per reviewer feedback: build a metadata object, write it, re-parse, and
assert on parsedChart.metadata. No assertions about the serialized ini
text itself (CRLF, field order, True/False formatting, quoting) — those
are implementation details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant