一键导入
scaffold-spatial-query
Add a new pure functional spatial index (collision map, grid, lookup) recomputed from GameState each tick
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add a new pure functional spatial index (collision map, grid, lookup) recomputed from GameState each tick
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | scaffold-spatial-query |
| description | Add a new pure functional spatial index (collision map, grid, lookup) recomputed from GameState each tick |
Use when adding collision detection, field-of-view, pathfinding, or any other positional query to the game.
Rule: No persistent spatial structures. Every index is rebuilt from GameState
at the start of each tick as a pure function. This guarantees determinism.
GameState → buildXxxMap(state) → ReadonlyMap<Key, Value>
↓
queryAt / queryNeighbours / isOccupied
All functions live in packages/game/lib/state/ (depends on core/ + state/ only).
For the tactical board, encode a GridCell into a string key or a compact
number:
// String key (simple, readable)
import type { GridCell } from "../core/types.ts";
const gridKey = (cell: GridCell): string => `${cell.column},${cell.row}`;
// Bit-packed number key (faster for large grids — requires bounded coords)
const gridKey = (cell: GridCell): number =>
(cell.column << 16) | (cell.row & 0xffff);
Pick string keys by default; switch to number keys only if profiling shows a hot path.
import type { Enemy, GameState, GridCell } from "../core/types.ts";
type CollisionMap = ReadonlyMap<string, Enemy>;
const buildCollisionMap = (state: GameState): CollisionMap =>
new Map(
state.enemies.flatMap((enemy) =>
enemy.cell === undefined ? [] : [[gridKey(enemy.cell), enemy]],
),
);
const isOccupied = (map: CollisionMap, cell: GridCell): boolean =>
map.has(gridKey(cell));
Note: new Map(...) constructed from an iterable is not mutation — it's allocation.
The returned Map is treated as immutable (ReadonlyMap).
When the map is large, split into fixed-size chunks to avoid rebuilding the full grid every tick:
const CHUNK_SIZE = 16;
type ChunkKey = string; // `${chunkX},${chunkY}`
type Chunk = ReadonlyMap<string, Entity>;
type ChunkedGrid = ReadonlyMap<ChunkKey, Chunk>;
const chunkKey = (cell: GridCell): ChunkKey =>
`${Math.floor(cell.column / CHUNK_SIZE)},${Math.floor(cell.row / CHUNK_SIZE)}`;
const buildChunkedGrid = (state: GameState): ChunkedGrid =>
state.entities.reduce<Map<ChunkKey, Chunk>>((chunks, entity) => {
const key = chunkKey(entity.cell);
const chunk = new Map(chunks.get(key) ?? []);
const nextChunk = new Map([...chunk, [gridKey(entity.cell), entity]]);
return new Map([...chunks, [key, nextChunk]]);
}, new Map());
const queryAt = (map: CollisionMap, cell: GridCell): Enemy | undefined =>
map.get(gridKey(cell));
const queryNeighbours = (
map: CollisionMap,
cell: GridCell,
): ReadonlyArray<Enemy> => {
const offsets = [
[-1, 0],
[1, 0],
[0, -1],
[0, 1],
];
return offsets.flatMap(([dx, dy]) => {
const e = queryAt(map, {
column: cell.column + (dx ?? 0),
row: cell.row + (dy ?? 0),
});
return e ? [e] : [];
});
};
import { describe, expect, it } from "vitest";
import { buildCollisionMap, isOccupied, queryAt } from "./collision-map.js";
describe("buildCollisionMap", () => {
it("maps enemy positions to entities", () => {
const state = /* GameState with one enemy at { column: 3, row: 5 } */;
const map = buildCollisionMap(state);
expect(isOccupied(map, { column: 3, row: 5 })).toBe(true);
expect(isOccupied(map, { column: 0, row: 0 })).toBe(false);
});
it("returns undefined for empty cell", () => {
const map = buildCollisionMap(/* empty state */);
expect(queryAt(map, { column: 10, row: 10 })).toBeUndefined();
});
});
GameState (they are derived, not canonical)GameState inside query functions — pass the pre-built map insteadGameState during each deterministic tick.Write cutting-edge and modern native CSS. Apply this skill whenever writing, reviewing, or refactoring CSS for components, layouts, design systems, or theming, even if the user doesn't say "modern CSS" explicitly. Covers a self-contained design-token scale (color, size, shadow, ease, type), cascade layers (@layer), @scope for component isolation (donut scopes, :scope specificity, scoping proximity), container queries, :has(), OKLCH/color-mix, native nesting, subgrid, fluid typography via clamp(), scroll-driven animations, logical properties, and concrete native replacements for SCSS mixins, maps, and variables.
Apply this skill whenever the task involves web security: writing or auditing HTTP security headers, configuring CSP, CORS, HSTS, or Permissions-Policy, sanitising untrusted HTML (Sanitizer API / DOMPurify), implementing Trusted Types to prevent DOM-XSS, setting up the Reporting API to capture CSP/COEP/deprecation violations, hardening cookies (SameSite, HttpOnly, Secure, Partitioned), implementing WebAuthn / Credential Management, using Web Crypto for client-side cryptography, or auditing code for XSS, CSRF, clickjacking, MIME-sniffing, mixed content, or cross-origin data leakage. Triggers on keywords: XSS, CSRF, CSP, CORS, HSTS, SameSite, innerHTML, eval, Trusted Types, Sanitizer, ReportingObserver, WebAuthn, cross-origin, clickjacking, Content-Security-Policy, Referrer-Policy, Permissions-Policy, subresource integrity, cookie security, secure context, same-origin, mixed content.
Patterns for invoking the GitHub CLI (gh) from agents. Covers structured output, pagination, repo targeting, search vs list, gh api fallback.
Audit and update durable architecture guidance after a cross-layer implementation, file move, package boundary change, coverage config change, or SDTE feature. Use when agent needs to reconcile AGENTS.md, package AGENTS.md files, local .agents/skills, older specs, dynamic imports, and test or coverage configuration with the architecture that was actually implemented.
Run the Spec → Design → Tasks → Execution workflow for non-trivial work — produces /specs/<feature>/{spec,design,tasks}.md, drives atomic per-task execution, and ends with a Review phase. Invoke when starting a new package, new game system, GameState shape change, or any change touching > 3 files or crossing a layer boundary.
Best practices for building scalable plain Web Components without turning custom elements into “god objects”. Provides patterns that keep Web Components modular, reusable, maintainable, and focused on UI concerns.