feat(bgm): allow $variants to take multiple csv sources
Expand $variants to accept an array of csv paths, concatenating their rows. Detect a path by a .csv suffix on the first line instead of a newline, so inline csv and paths are self-documenting and the rule applies uniformly to single values and array elements.
This commit is contained in:
+18
-4
@@ -37,9 +37,11 @@ bruce,[]
|
||||
|
||||
### Inline vs file
|
||||
|
||||
`$variants` can be a file/URL path *or* an inline CSV string. If the value
|
||||
contains a newline it is inline CSV; otherwise it is a path. In YAML a block
|
||||
scalar (`|`) is the natural way to write inline CSV; in JSON you'd use `\n`.
|
||||
`$variants` can be a single source or an array of sources. Each source is a
|
||||
file/URL path if its first line ends in `.csv`, otherwise it is inline CSV.
|
||||
This keeps the two forms self-documenting and applies the same rule to single
|
||||
values and array elements alike. In YAML a block scalar (`|`) is the natural
|
||||
way to write inline CSV; in JSON you'd use `\n`.
|
||||
|
||||
```yaml
|
||||
$variants: |
|
||||
@@ -47,9 +49,21 @@ $variants: |
|
||||
string,string,[number;number;number;number]
|
||||
fish,Fish,[0;0;5;2]
|
||||
grain,Grain,[1;0;5;2]
|
||||
wood,Wood,[2;0;5;2]
|
||||
```
|
||||
|
||||
An array of sources concatenates their rows. This lets one part definition
|
||||
pull from several CSVs with different schemas — e.g. a deck where the regular
|
||||
cards share a face sheet but the jokers have their own:
|
||||
|
||||
```yaml
|
||||
$variants:
|
||||
- ./cards.csv
|
||||
- ./jokers.csv
|
||||
```
|
||||
|
||||
Each source is parsed with its own schema, and its rows extend the original
|
||||
object independently.
|
||||
|
||||
### CSV conventions
|
||||
|
||||
CSV is parsed with `typed-csv`:
|
||||
|
||||
Reference in New Issue
Block a user