constructor(name?: string)
View sourceCreates a name component.
With no argument, the component’s value is the empty string.
Class
Stores an entity’s human-readable name as an ECS component.
A Name component holds a string value for an entity’s name.
Constructing it without an argument starts with an empty string, while a
supplied string becomes the initial value. Serialization uses the raw
string, and Name.validateSerial can check untrusted serialized
data before Name.deserialize creates or populates a component.
import { Query, World } from '@wimaengine/ecs'
import { Name } from '@wimaengine/name'
const world = new World()
world.spawn([new Name('Player')])
const names = new Query(world, [Name])
names.each(([name]) => {
console.log(name.value) // 'Player'
name.value = 'Hero'
})constructor(name?: string)Creates a name component.
With no argument, the component’s value is the empty string.
Human-readable label stored on the entity.
Assigning this field updates the component immediately. The component does not coerce or validate the assigned value at runtime.
copy(source: Name, target?: Name): NameCopies a name into a target component.
Only the string value is copied. When target is omitted, a new
Name component is created and returned.
clone(target: Name): NameCreates a new component with the same value as another name.
Name.clone delegates to Name.copy, so the returned
component is a separate Name instance with a copied primitive
string value.
default(): Nameserialize(value: Name): stringSerializes a name to its raw string value.
The result is the string itself, not an object such as { value: '...' }.
deserialize(value: string, out?: Name): NameDeserializes a raw string into a name component.
If out is supplied, its value is replaced and the same component is
returned. Without an output component, a new Name is created.
This method assigns directly and does not call Name.validateSerial;
validate unknown input before deserializing it.
validateSerial(value: unknown): value is stringChecks whether a value is a valid serialized name.
Validation only checks typeof value === 'string'; it does not enforce a
non-empty name or any other naming convention.