Skip to main content
Custom types for the inspector

Custom types for the inspector

· 2 min read
Balaur

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.

The inspector drawing a map keyed by numbers, a Wave class of two fields and a list of three numbers, each entry on its own row

Declaring one

  • of is the spec a list's entries and a map's values take, and fields is one spec per record field. Each is a whole property spec, so min, options, asset and component work at any depth.
  • A nested spec may leave its default out; the type's zero is written in when the component registers, and a new entry starts there.
  • A map's key is "string" or "int". A number key is written "7" in the file and reaches the script as the number.
  • strings and nodes are gone. They were list of string and list 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 struct the script declares is exported as itself: the scene writes its fields, and init is 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" } }
}

Docs