EntityDef class final

Anything in the level that is not geometry: a spawn, a monster, a pickup, a door, a trigger, a note on the wall.

One type with a property bag, rather than a class per kind. There will be thirty kinds before the game is finished, the editor has to handle them all the same way, and a class hierarchy buys type safety at exactly the layer that reads them from JSON and therefore cannot have it anyway. The typed accessors below are where the safety actually goes.

The row in a document

{"id": "k3f9a2b1", "type": "torch", "at": [1, 0, 2], "name": "east",
 "props": {"radius": 3}, "components": {"glow_plugin": {"tint": [1, 0.5, 0]}}}

Since level format 3 the top level of a row is the engine's, every key of it listed in reservedKeys, and what a game says about an entity goes under props; what a plugin says goes under components.<its namespace>. That keeps a later release free to add a top-level key — a layer, a rotation — without colliding with a property somebody already called that. A row without props is the older shape, where every key that is not reserved is a property, and it still reads; it is written back in the new shape.

Constructors

EntityDef({required String type, String? id, WorldPosition? position, double yaw = 0.0, String? name, Map<String, Object?>? properties, Map<String, Map<String, Object?>>? components, String? physicalMaterial, Map<String, Object?> source = const <String, Object?>{}})
An entity of type at position (the world origin when null), facing yaw radians. A null id is derived from the type, name, position and yaw.
EntityDef.fromJson(Map<String, Object?> json)
Reads a row in either shape: with props (format 3), or with its properties at the top (before it).
factory

Properties

components → Map<String, Map<String, Object?>>
What plugins say about this entity, by the plugin's namespace: the row's components. A level that holds any names their namespaces in its envelope's requires, so a reader without the plugin refuses the level rather than dropping them.
final
hashCode → int
The hash code for this object.
no setterinherited
id → String
What this entity is called by everything that has to find it again — a prefab override, the editor's selection. See LevelIds; given when the entity is made, derived from what it is otherwise.
final
name → String?
Referred to by other entities — the lift a button calls, the door a key opens. For people and for references between entities; a tool that has to find this entity again uses id.
final
physicalMaterial → String?
The substance this entity's body is made of: the id of a material in the engine's MaterialCatalog (f3d.oak, <pluginId>.basalt), or null for the material its kind gives it. The row's physicalMaterial; a level naming one no installed plugin declares is refused (Level.requireMaterials).
final
position → WorldPosition
Where it stands, in world space: a WorldPosition, in doubles, as the level file holds it.
final
properties → Map<String, Object?>
What the game says about this entity: the row's props.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
type → String
The kind of thing it is, as EntityKinds knows it: torch, playerSpawn, a game's own word. Never empty.
final
yaw → double
Facing, in radians about Y. Nothing in this game tilts.
final

Methods

flag(String key, {bool orElse = false}) → bool
The bool property key, or orElse when it is absent. A value that is not a bool throws a TypeError.
integer(String key) → int?
The number property key truncated to an int, or null when it is absent or not a number.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
number(String key) → double?
The number property key as a double, or null when it is absent or not a number.
string(String key) → String?
The text property key, or null when it is absent. A value that is not text throws a TypeError.
toJson() → Map<String, Object?>
This entity as a level row in the format-3 shape, written through the row it was read from so unknown keys survive.
toString() → String
A string representation of this object.
inherited
vector(String key) → Vector3?
The property key as a vector from its first three numbers, or null when it is not a list of at least three.
withId(String id) → EntityDef
This entity under another id, everything else as it is.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

reservedKeys → const Set<String>
The top-level keys of a row, which belong to the format and never reach properties.