Skip to content

@vaguevoid/fiasco / ecs/resources / Engine

Class: Engine

Defined in: src/ecs/resources.ts:89

The Fiasco Engine.

Provides access to all necessary core features.

Available on the global scope after any ECS Module has loaded - do not call outside of systems.

Methods

addComponents()

addComponents(entityId, components): void

Defined in: src/ecs/resources.ts:147

Add components to an existing entity.

ts
import { Query, Vec2, Colors, EntityId } from '@vaguevoid/fiasco'
import { Components } from '../.fiasco/generated'

type Cat = Component<{ fluffy: boolean }>

// Example showing adding green color to every spawned entity that has a Cat component already.
function system(cats: Query<[EntityId, Cat]>) {
  for (const [entity] of cats) {
    engine.addComponents(entity.id, [
      new Components.Color(Colors.Palette.GREEN)
    ])
  }
}

Parameters

entityId

bigint

The ID of the entity to attach components to.

components

ComponentInstance[]

The bundle of components to attach to the entity.

Returns

void


despawn()

despawn(entityId): void

Defined in: src/ecs/resources.ts:290

Despawn (remove) an existing entity from the world.

Parameters

entityId

bigint

The ID of the entity to despawn from the world.

Returns

void


getEntityLabel()

getEntityLabel(entityId): undefined | string

Defined in: src/ecs/resources.ts:192

Get the label that is attached to an entity.

ts
import { Query, EntityId, Component } from '@vaguevoid/fiasco'

type Cat = Component<{ fluffy: boolean }>

function system(cats: Query<[Cat, EntityId]>) {
  for (const [cat, entity] of cats) {
    const label = engine.getEntityLabel(entity.id)
    console.log(label) // string | undefined
  }
}

Parameters

entityId

bigint

The ID of the entity.

Returns

undefined | string

A string label, or undefined is no label has been attached.


getParent()

getParent(entityId): bigint | "no_parent" | "invalid_id"

Defined in: src/ecs/resources.ts:231

Retrieve the parent entity ID of the given child ID.

ts
import { Query, EntityId, Component } from '@vaguevoid/fiasco'

type Cat = Component<{ fluffy: boolean }>

function system(cats: Query<[EntityId, Cat]>) {
  for (const [entity] of cats) {
     const parentId = engine.getParent(entity.id)
  }
}

Parameters

entityId

bigint

The ID of the entity in which to retrieve it's parent.

Returns

bigint | "no_parent" | "invalid_id"

Returns no_parent if no parent available or invalid_id if the entity id provided is invalid.


removeComponents()

removeComponents(entityId, componentIds): void

Defined in: src/ecs/resources.ts:169

Remove components from an exsiting entity.

Parameters

entityId

bigint

The ID of the entity to remove the components from.

componentIds

number[]

The array of components (ID's) to remove from the entity.

Returns

void


setEntityLabel()

setEntityLabel(entityId, label): void

Defined in: src/ecs/resources.ts:209

Set a label to an entity.

ts
function system() {
  const id = engine.spawn([...])
  engine.setEntityLabel(id, "my new entity")
}

Parameters

entityId

bigint

The ID of the entity.

label

string

A string label to attach the entity

Returns

void


setParent()

setParent(entityId, parentId, keepWorldSpaceTransform): void

Defined in: src/ecs/resources.ts:241

Sets the parent for a given entity, or clears the parent of a given entity.

Parameters

entityId

bigint

The entity ID of the child.

parentId

The entity ID of the parent, or undefined to clear the parent.

undefined | bigint

keepWorldSpaceTransform

boolean = false

Whether the world space transform of the child should be maintained after parenting.

Returns

void


setSystemEnabled()

setSystemEnabled(systemName, enabled): void

Defined in: src/ecs/resources.ts:121

Enable or disable execution of a particular system. If a system is disabled, it will no longer run every frame until re-enabled.

ts
function system1() {
  // disable system2
  engine.setSystemEnabled("system2", false)
}

Parameters

systemName

string

The name of the system, usually the function name.

enabled

boolean

If the system should be enabled or not.

Returns

void


spawn()

spawn(components): bigint

Defined in: src/ecs/resources.ts:268

Spawn an entity into the world with the provided components.

ts
import { Components } from '../.fiasco/generated'

function system() {
  const id = engine.spawn([
    new Components.ColorRender({ visible: true }),
    new Components.Transform({
      // ...
    })
  ])

  console.log("entity just spawned with id", id)
}

Parameters

components

ComponentInstance[]

A list of components to be attached to the entity.

Returns

bigint

The ID of the newly spawned entity.