Custom types for the inspector
· 2 min read
A property can now hold other properties. A list is ordered and holds one type, a map is keyed, and a record is a fixed set of named fields. The inspector draws a row per entry, each with the editor its type already had.
Declaring one
ofis the spec alist's entries and amap's values take, andfieldsis one spec perrecordfield. Each is a whole property spec, somin,options,assetandcomponentwork at any depth.- A nested spec may leave its
defaultout; the type's zero is written in when the component registers, and a new entry starts there. - A
map'skeyis"string"or"int". A number key is written"7"in the file and reaches the script as the number. stringsandnodesare gone. They werelist of stringandlist of node, and fifteen schema lines were rewritten.
waves = { type = "list", of = { type = "int", min = 0 }, default = [] }
spawns = { type = "map", key = "int", of = { type = "node" }, default = {} }
Exporting one from a script
- A bare export says what it is:
waves: [2, 4, 8]is a list of whole numbers, and an object is a record whose fields keep their own types. - A list holds one type, and an entry of another names itself in the error.
- A node path is resolved wherever the spec puts one, so a list of nodes arrives as the nodes, and a record's node field does too.
- A
structthe script declares is exported as itself: the scene writes its fields, andinitis handed that class, methods and all. The inspector row says which class it is.
struct Wave { hp, name }
pub fn exports() {
#{ waves: [2, 4, 8], wave: Wave { hp: 3, name: "grunt" } }
}
