Strata - v1.4.10
    Preparing search index...

    Function createFromArchetype

    • Creates an entity that matches a specific archetype.

      Type-safe entity creation using pre-defined archetypes. Validates that all required components are present and generates an ID if not provided.

      Type Parameters

      Parameters

      • archetype: Archetype<T>

        The archetype definition with required components.

      • components: Partial<T>

        The component values for the entity.

      Returns T

      A new entity matching the archetype.

      If any required archetype components are missing.

      // Using built-in archetypes
      const movable = createFromArchetype(
      ARCHETYPES.MOVABLE,
      {
      position: { x: 0, y: 0, z: 0 },
      velocity: { x: 1, y: 0, z: 0 }
      }
      );
      // Custom archetype
      const PLAYER_ARCHETYPE: Archetype<GameEntity> = {
      name: 'player',
      components: ['position', 'health', 'inventory'],
      tags: ['player', 'combat']
      };

      const player = createFromArchetype(PLAYER_ARCHETYPE, {
      position: { x: 0, y: 0, z: 0 },
      health: 100,
      inventory: []
      });