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

Schema

project root 和每个 include module 都可以使用 SCON、TOML、YAML、JSON 或 Lua;新文件推荐 SCON。

project { id = "game_config" }
includes = ["schema/items.scon", "schema/skills.scon"]

每个文件先解析成对应格式的 keyed 表示,再 lower 为格式无关的 schema module。root 必须声明 project;include module 不能声明 root-only 的 project、groups、views、codegen 或 localization。include 可以跨格式,Sora 按声明顺序递归加载,并检测循环、重复 module 和跨 module 重名。

声明名只存在于 key,body 内不再重复 name;未知属性会被拒绝。

命名空间与导入

每个 module 可以声明逻辑命名空间,并为其他命名空间声明别名:

namespace = "game.items"
imports {
  common = "game.common"
}

structs {
  Drop {
    fields {
      reward = "struct<common.Reward>"
    }
  }
}

源文件中的声明仍写本地名;上面的 Drop 的规范名称是 game.items.Drop。struct<Cost> 这类无前缀引用解析到当前命名空间,common.Reward 先通过 imports 展开,其他带点名称按项目绝对限定名处理。ref<items.Item.id> 把最后一段当字段名,前面的全部内容当表名。

namespace、import alias 和声明名的每一段都必须是 ASCII 标识符。空 namespace 表示项目根命名空间。校验、schema lock、fingerprint、bundle 和运行时 table 查找统一使用规范限定名。

enums {
  ItemType = ["Weapon", "Armor", "Material"]
}

structs {
  Cost {
    fields {
      gold = "i32"
    }
  }
}

unions {
  RewardAction {
    variants {
      AddItem {
        fields {
          item_id = "ref<Item.id>"
        }
      }
    }
  }
}

tables {
  Item {
    mode = "map"
    key = "id"
    source {
      file = "Item.xlsx"
      sheet = "Item"
    }
    fields {
      id = "i32"
    }
  }
}

enum values、struct fields、union variants 和 table fields 都保留作者顺序。等价的五格式自然写法见 Schema 格式,表与索引见 Tables,字段类型见 Types,单元格编码见 Cell Parsers。