Name

View source

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.

Examples

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


constructor(name?: string)

View source

Creates a name component.

With no argument, the component’s value is the empty string.

Parameters

NameDescriptionDefault
name?

Initial entity name.

''

Properties


value: string

View source

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.

Methods


staticcopy(source: Name, target?: Name): Name

View source

Copies a name into a target component.

Only the string value is copied. When target is omitted, a new Name component is created and returned.

Parameters

NameDescriptionDefault
source

Component whose value should be copied.

—
target?

Component to populate.

...

Returns

The populated target component.

staticclone(target: Name): Name

View source

Creates 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.

Parameters

NameDescriptionDefault
target

Component to clone.

—

Returns

A new component containing the same value.

staticserialize(value: Name): string

View source

Serializes a name to its raw string value.

The result is the string itself, not an object such as { value: '...' }.

Parameters

NameDescriptionDefault
value

Component to serialize.

—

Returns

The component’s value.

staticdeserialize(value: string, out?: Name): Name

View source

Deserializes 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.

Parameters

NameDescriptionDefault
value

Serialized name string.

—
out?

Component to populate.

...

Returns

The populated component.

staticvalidateSerial(value: unknown): value is string

View source

Checks 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.

Parameters

NameDescriptionDefault
value

Value to validate.

—

Returns

Whether the value is a string.