-
Notifications
You must be signed in to change notification settings - Fork 1
Components
A component is data associated with an entity, differentiated by its schema, a uniquely identifiable template. Or, more specifically, that schema's integer id.
A schema is defined using Harmony's createSchema
function:
const Health = createSchema(formats.float64)
Harmony exports a formats
object which contains multiple numeric types, e.g. uint8
, int16
, float64
, etc.
The term "native" here is misleading; as we will see, the other kind of component that Harmony can store is powered by a native, although esoteric, language feature.
Native components store plain built-in JavaScript values. This currently includes numbers and objects, and will include arrays, maps, and sets in the near future.
We have already defined a number component in the Health
component example above. Any of Harmony's numeric formats (uint, int, float) do not matter here: the component is simply stored in an array of built-in, IEEE 754 numbers.
Native object components are created by providing an object to makeSchema
, where each key is a fixed property name, and its value is either a format or a nested object conforming to the same rules:
const Attributes = createSchema({
strength: formats.uint8,
dexterity: formats.uint8,
// ...
modifiers: {
strength: formats.int8,
// ...
},
})
A component can be added to or removed from an entity using set
and unset
, respectively. Components are then modified using queries.