Implement CSV / TSV import (#45)

- add csv/tsv importer
- add `make_map` script function
- add `alt name` field property
- add `construction script` field property
- add `construction script` game property
This commit is contained in:
GenevensiS
2025-06-09 04:53:33 +02:00
committed by GitHub
parent 6cac4ae0dc
commit 87fbc0e80e
21 changed files with 521 additions and 63 deletions
+1
View File
@@ -11,6 +11,7 @@ These functions are built into the program, other [[type:function]]s can be defi
| [[fun:to_color]] Convert any value to a [[type:color]]
| [[fun:to_image]] Convert any value to an [[type:image]]
| [[fun:to_date]] Convert any value to a [[type:date]]
| [[fun:make_map]] Create a [[type:map]] from two [[type:list]]s
| [[fun:type_name]] Get the type of a value
! Numbers <<<
+17
View File
@@ -0,0 +1,17 @@
Function: make_map
--Usage--
> make_map(keys: some_list, values: some_list)
Creates a new map. Converts the elements in keys to strings, and uses them as keys for the elements in values.
Produces a warning if keys and values are not of the same size.
nil keys will be ignored.
--Parameters--
! Parameter Type Description
| @keys@ [[type:list]] List of keys.
| @values@ [[type:list]] List of values.
--Examples--
> make_map(keys:["apple", "durian", 3], values:["good", "bad", "not edible"]) == ["apple":"good", "durian":"bad", "3":"not edible"]
+5
View File
@@ -28,6 +28,7 @@ Fields are part of the [[file:style triangle]]:
* @color@
* @info@
| @name@ [[type:string]] ''required'' Name of the field.
| @alt names@ [[type:list]] of [[type:string]] Possible alternate names for this field, mainly to look for it when importing CSV files. They are trimmed, made case insensitive, and don't distinguish between spaces and underscores.
| @description@ [[type:localized string]] @""@ Description of the field, shown in the status bar when the mouse is over the field.
| @icon@ [[type:filename]] Filename of an icon for this field, used for automatically generated [[type:statistics category]]s.
| @editable@ [[type:boolean]] @true@ Can values of this field be edited?
@@ -42,6 +43,10 @@ Fields are part of the [[file:style triangle]]:
| @card list name@ [[type:localized string]] field name Alternate name to use for the card list, for example an abbreviation.
| @card list alignment@ [[type:alignment]] @left@ Alignment of the card list column.
| @sort script@ [[type:script]] Alternate way to sort the card list when using this column to sort the list.
| @construction script@ [[type:script]] Script applied to the value given when creating a card with the new_card function.
For example, the pt field should not be initialized directly, since it is a combination of the power field and toughness field.
So if a value is given for pt, it must be redirected to power and toughness like so: {split := split_text(value, match:"/"); [power:split[0], toughness:split[1]]}.
The script must return a map from field names to values. Use the make_map function to dynamically create maps.
The @type@ determines what values of this field contain:
! Type Values contain Displayed as
+1
View File
@@ -33,6 +33,7 @@ Such a package contains a [[file:format|data file]] called <tt>game</tt> that ha
| @default set style@ [[type:indexmap]] of [[type:style]]s Default style for the set fields, can be overridden by the stylesheet.
| @card fields@ [[type:list]] of [[type:field]]s Fields for each card.
| @card list color script@ [[type:script]] from fields Script that determines the color of an item in the card list. <br/>If not set uses the @card list colors@ property of the first card field that has it.
| @construction script@ [[type:script]] Script that is applied as the last step in the creation of a card in the new_card function. Must return a map from field names to values. Use the make_map function to dynamically create maps.
| @statistics dimensions@ [[type:list]] of [[type:statistics dimension]]s from fields Dimensions for statistics, a dimension is roughly the same as an axis. <br/>By default all card fields with 'show statistics' set to true are used.
| @statistics categories@ [[type:list]] of [[type:statistics category]]s from dimensions DOC_MSE_VERSION: not used since 0.3.6
Choices shown on the statistics panel. <br/>By default all statistics dimensions are used.