ecs-systems
Create ECS system functions that mutate the game world
📖 中文导读:Create ECS system functions that mutate the game world 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: ecs-systems description: Create ECS system functions that mutate the game world
ECS Systems
Write system functions in src/ecs/systems/ that implement game logic.
Requirements
- File naming:
*System.ts(e.g.,moveItemSystem.ts) - Must reference:
worldor imported query functions fromsrc/ecs/queries/ - One system per file
Pattern
import { world } from '../world';
import type { Entity } from '../world';
interface SystemNameProps {
entityId: string;
// other parameters
}
interface SystemNameReturn {
success: boolean;
// optional data on success
}
export function systemName(props: SystemNameProps): SystemNameReturn {
const { entityId } = props;
// Query entities
const entity = world.get(entityId);
if (entity === undefined) {
return { success: false };
}
// Perform mutations
world.update(entity, {
/* component changes */
});
return { success: true };
}
Rules
- No pure helper functions - Extract to
src/utils/instead - Props interface - All parameters via single props object
- Return object - Always return
{ success: boolean, ...data } - Query before mutate - Validate entities exist before changing them
- Single responsibility - One logical operation per system
Examples
Good system names:
moveItemSystem- moves an item between gridsdestroyItemSystem- removes an item from the worldequipItemSystem- places item in equipment slot
Bad (should be utils):
findFreePosition- pure calculation, no world accessisSpaceFree- pure validation, no world access