ComponentDefinition<T extends Component> class
Everything the engine and editor need to know about one component type, in one place: how to build it, what it persists, how it looks in an inspector, how big it is, and how it draws.
It is the codec — registering a definition makes the component saveable — and the inspector is built from the same fields, so a field cannot be shown without being saved.
Writes {type, fields}. An id — the customComponentId the editor
stored for years — is not written: scene format 1 dropped it, keying
every component by type.
- Inheritance
-
- Object
- ComponentCodec<
T> - ComponentDefinition
- Implementers
Constructors
-
ComponentDefinition({required String type, required T create(), required List<
SchemaField> fields, String? id, List<String> aliases = const [], ComponentHints hints = const ComponentHints(), ComponentExtent? extent, ComponentPainter<Component> ? painter, ComponentDefinition<Component> ? parent, void afterDecode(Component component)?}) -
A definition saved as
type, built bycreateand persistingfields.aliasesare older names it also loads;extentandpainteronly matter to components with a size or that draw themselves.const -
ComponentDefinition.extend(ComponentDefinition<
Component> base, {required String type, required T create(), List<SchemaField> extraFields = const [], String? id, List<String> aliases = const [], ComponentHints? hints, ComponentExtent? extent, ComponentPainter<Component> ? painter, void afterDecode(Component component)?}) -
A definition for a subclass of
base's component: inherits its fields, hints, extent and painter, and persistsextraFieldson top.
Properties
- afterDecode → void Function(Component component)?
-
Runs on a component decode has just filled in, once every saved field
is set: for state that is not saved but has to agree with what was —
a transform's previous pose, which render interpolation reads, has to
be the pose just loaded rather than the origin. Null for none.
final
-
aliases
→ List<
String> -
Other
typestrings (or oldcustomComponentIds) this definition also loads, so a component can be renamed without breaking saved levels.final - componentType → Type
-
The Dart type this codec handles.
no setterinherited
- create → T Function()
-
Builds a component with default values, which decode then overwrites
field by field. A field missing from the JSON keeps its default.
final
- extent → ComponentExtent?
-
Size and resize behaviour, if the component implies an extent.
final
-
fields
→ List<
SchemaField> -
Every persisted property.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hints → ComponentHints
-
Inspector presentation.
final
- id → String?
-
The
customComponentIdthe editor once saved this component under; null for none. Not written to scenes (format 1 keys by type); an old id still loads through aliases.final -
painter
→ ComponentPainter<
Component> ? -
How the render system draws it, if it draws itself.
final
-
parent
→ ComponentDefinition<
Component> ? -
The definition this one extends, if any.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type → String
-
The
typestring written to JSON. Stable: changing it orphans every saved level that used the old name.final
Methods
-
decode(
Map< String, dynamic> json) → T -
Throws a FormatException naming the type and the field when a value
has the wrong type (a field saved as
nullthat cannot be null, a string where a number goes), instead of a bare TypeError.override -
encode(
T component) → Map< String, dynamic> -
Encodes
component. The result must include'type': type.override -
encodeAny(
Component component) → Map< String, dynamic> -
encode for a component typed only as Component.
inherited
-
field(
String name) → SchemaField? -
The field named
name, or null. -
handles(
Component component) → bool -
Whether
componentis one this codec handles.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited