Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

类型

Sora 的类型表达式在 schema 字段中以字符串形式书写。

原始类型

类型含义
bool布尔值。
i88 位有符号整数。
u88 位无符号整数。
i1616 位有符号整数。
u1616 位无符号整数。
i3232 位有符号整数。
u3232 位无符号整数。
i6464 位有符号整数。
f3232 位浮点数。
f6464 位浮点数。
stringUTF-8 字符串。
duration非负时长,写作 500ms30s15m2h7d1h 30m 这类单位组合。单位必须按从大到小排列:dhmsms。运行时数据存储为毫秒。
text多语言文案 key。见多语言

Sora 会在导出前校验整数宽度范围。部分目标语言没有 unsigned 小整数类型,生成代码可能使用更宽的 signed 类型承载,但 schema 范围语义仍然保留。

[[tables.fields]]
name = "level"
type = "u16"
range = [1, 100]

Named Types

TypeExample
Enumenum<ItemType>
Structstruct<ResourceCost>
Unionunion<RewardAction>
Referenceref<Item.id>

引用必须指向 mode = "map" 表的主键。容器可以包住引用,例如 list<ref<Item.id>>

[[tables.fields]]
name = "item_type"
type = "enum<ItemType>"

[[tables.fields]]
name = "price"
type = "struct<ResourceCost>"
parser = { kind = "tuple" }

Collections

TypeMeaning
list<T>有序重复值。
set<T>唯一重复值。
array<T,N>固定长度重复值。
map<K,V>键值对。
optional<T>可空或可缺省值。
[[tables.fields]]
name = "tags"
type = "set<string>"
parser = { kind = "json" }
default = "[\"misc\"]"

[[tables.fields]]
name = "attributes"
type = "map<string,i32>"
parser = { kind = "map" }

单元格示例

这些例子展示策划在 Excel 或 CSV cell 里会填写什么:

字段类型ParserCell 值
u161001
enum<ItemType>Weapon
list<i32>无或 split1,2,3
duration1h 30m
textquest.1001.title
set<string>json["starter","melee"]
struct<ResourceCost>tupleGold,0,100
struct<ResourceCost>columns展开到 cost_kindcost_idcost_count 多列
map<string,i32>mapatk,10|hp,20
union<EventCondition>json{"type":"QuestCompleted","quest_id":5002}
optional<ref<Item.id>>空 cell 或 1001

Field Rules

[[tables.fields]][[structs.fields]][[unions.variants.fields]] 共享通用字段属性。表字段额外拥有派生值相关属性;这些表专用属性不能写在 struct field 或 union variant field 上。表主键只在表本身用 key = "field_name" 声明一次。

字段是否可缺省由类型表达:optional<T> 表示值可以缺失或为空;其它类型都要求有值,除非 default 填充了缺失值。

对 TOML/JSON/YAML 这类 object 输入,字段可以不存在。对 Excel 和 CSV,表头列必须存在;某一行没有对应 cell、cell 为空,或者 CSV 行列数不够,都会按空 cell 处理。

Schema 字段object 字段不存在Excel/CSV cell 为空
type = "i32"校验错误。校验错误。
type = "optional<i32>"nullnull
type = "i32"default = "1"11
type = "optional<i32>"default = "1"1null
Property适用范围作用
name所有字段字段名。用于源数据、校验错误、生成代码和导出的运行时数据。
type所有字段类型表达式,例如 i32struct<ResourceCost>list<union<RewardAction>>
default除派生字段外的所有字段object 字段不存在,或 required Excel/CSV cell 为空时使用的字符串值。
comment所有字段用于生成 Excel 表头说明。
range数值字段、duration,以及这些类型的集合元素数值闭区间,写作 [min, max]duration 的范围单位是毫秒。
lengthstringlistsetarraymap长度闭区间,写作 [min, max]
parser单元格输入和 default单元格 parser 提示。见单元格 Parser
scope所有字段仅在选定 generation/export scope 下包含该字段。默认是 all
from仅表字段可选的子表来源,用来声明派生字段。

default 写成字符串,因为它会走和源数据相同的类型感知转换路径。

from 用来描述从另一张表匹配行得到的派生字段,详见引用和派生字段。派生字段可以是 list<T>Toptional<T>,且不能声明 default