Back to list
narehart

ecs-queries

by narehart

0🍴 0📅 Jan 8, 2026

SKILL.md


name: ecs-queries description: Create ECS query helpers that read from the world without mutations

ECS Queries

Write query helper functions in src/ecs/queries/ that provide reusable read-only access to the world.

Requirements

  • File naming: *Queries.ts (e.g., inventoryQueries.ts)
  • Must reference: world for queries
  • Group related queries in single file

Pattern

import { world } from '../world';
import type { Entity } from '../world';

// Simple query - returns entities
export function getEntitiesWithComponent(): Entity[] {
  return world.with('componentName').entities;
}

// Filtered query - returns subset
export function getEntitiesByType(type: string): Entity[] {
  return world.with('componentName').entities.filter((e) => e.componentName.type === type);
}

// Single entity query - returns entity or undefined
export function getEntityById(id: string): Entity | undefined {
  return world.get(id);
}

// Derived data query - returns computed value
interface GetDerivedDataReturn {
  count: number;
  items: Entity[];
}

export function getDerivedData(): GetDerivedDataReturn {
  const items = world.with('item').entities;
  return {
    count: items.length,
    items,
  };
}

Rules

  1. Read-only - Queries must not mutate the world
  2. Must use world - All queries access world directly
  3. Return typed data - Define return interfaces for complex returns
  4. Group by domain - Related queries in same file (e.g., all inventory queries)
  5. No side effects - Pure functions that only read and return

When to Use Queries vs Utils

Use Query (src/ecs/queries/)Use Util (src/utils/)
Needs world accessPure calculation/transformation
Returns entities or entity dataWorks on any input data
Domain-specific (inventory, etc.)Generic utility (arrays, math)

Examples

Good queries:

  • getEquippedItems() - returns entities with equipment component
  • getGridEntities(gridId) - returns items in a specific grid
  • findItemByName(name) - searches world for matching item

Bad (should be utils):

  • sortByName(items) - pure array sort, no world access
  • calculateWeight(item) - pure calculation on passed data

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon