refactor(slay-the-spire-like): clean up barrel exports and formatting

- Convert explicit barrel exports to `export *` patterns in several
  systems
- Create a new `utils/index.ts` barrel for the system utils
- Rename `validatePlacement` to `validateShapePlacement` for clarity
- Reformat `shape-collision.ts` to use 2-space indentation and
  consistent
  styling
- Fix import paths in `index.ts`
This commit is contained in:
hypercross 2026-04-21 23:01:19 +08:00
parent 03d367c7b0
commit 97ff61985a
6 changed files with 141 additions and 175 deletions

View File

@ -3,5 +3,5 @@ export * from "./system/deck";
export * from "./system/encounter"; export * from "./system/encounter";
export * from "./system/grid-inventory"; export * from "./system/grid-inventory";
export * from "./system/map"; export * from "./system/map";
export * from "./system/utils/parse-shape"; export * from "./system/utils";
export * from "./system/types"; export * from "./system/types";

View File

@ -1,7 +1,2 @@
export type { GameCard, GameCardMeta, PlayerDeck, DeckRegions } from './types'; export * from "./factory";
export { export * from "./types";
generateDeckFromInventory,
createCard,
createPlayerDeck,
generateCardId,
} from './factory';

View File

@ -1,24 +1,3 @@
export type { export * from "./types";
CellCoordinate, export * from "./transform";
CellKey,
GridInventory,
InventoryItem,
MutationResult,
PlacementResult,
} from "./types";
export type { GameItemMeta, GameItem } from "./types";
export {
createGridInventory,
flipItem,
getAdjacentItems,
getItemAtCell,
getOccupiedCellSet,
moveItem,
placeItem,
removeItem,
rotateItem,
validatePlacement,
} from "./transform";
export * from "./factory"; export * from "./factory";

View File

@ -1,24 +1,3 @@
export { MapNodeType, MapLayerType } from "./types"; export * from "./generator";
export type { export * from "./navigation";
MapNode, export * from "./types";
MapLayer,
PointCrawlMap,
MapGenerationConfig,
} from "./types";
export { generatePointCrawlMap } from "./generator";
export {
getNode,
getChildren,
getParents,
hasPath,
findAllPaths,
} from "./generator";
export {
canMoveTo,
moveToNode,
getReachableChildren,
isAtEndNode,
isAtStartNode,
} from "./navigation";

View File

@ -0,0 +1,2 @@
export * from "./parse-shape";
export * from "./shape-collision";

View File

@ -1,4 +1,4 @@
import type { ParsedShape } from './parse-shape'; import type { ParsedShape } from "./parse-shape";
/** /**
* Represents a 2D point in grid coordinates. * Represents a 2D point in grid coordinates.
@ -54,7 +54,7 @@ export function transformPoint(
point: Point2D, point: Point2D,
transform: Transform2D, transform: Transform2D,
shapeWidth: number, shapeWidth: number,
shapeHeight: number shapeHeight: number,
): Point2D { ): Point2D {
let { x, y } = point; let { x, y } = point;
@ -96,10 +96,13 @@ export function transformPoint(
/** /**
* Transforms a shape and returnss its occupied cells in world coordinates. * Transforms a shape and returnss its occupied cells in world coordinates.
*/ */
export function transformShape(shape: ParsedShape, transform: Transform2D): Point2D[] { export function transformShape(
shape: ParsedShape,
transform: Transform2D,
): Point2D[] {
const cells = getOccupiedCells(shape); const cells = getOccupiedCells(shape);
return cells.map(cell => return cells.map((cell) =>
transformPoint(cell, transform, shape.width, shape.height) transformPoint(cell, transform, shape.width, shape.height),
); );
} }
@ -110,12 +113,12 @@ export function checkCollision(
shapeA: ParsedShape, shapeA: ParsedShape,
transformA: Transform2D, transformA: Transform2D,
shapeB: ParsedShape, shapeB: ParsedShape,
transformB: Transform2D transformB: Transform2D,
): boolean { ): boolean {
const cellsA = transformShape(shapeA, transformA); const cellsA = transformShape(shapeA, transformA);
const cellsB = transformShape(shapeB, transformB); const cellsB = transformShape(shapeB, transformB);
const setA = new Set(cellsA.map(c => `${c.x},${c.y}`)); const setA = new Set(cellsA.map((c) => `${c.x},${c.y}`));
for (const cell of cellsB) { for (const cell of cellsB) {
if (setA.has(`${cell.x},${cell.y}`)) { if (setA.has(`${cell.x},${cell.y}`)) {
@ -135,7 +138,7 @@ export function checkCollision(
export function checkBoardCollision( export function checkBoardCollision(
shape: ParsedShape, shape: ParsedShape,
transform: Transform2D, transform: Transform2D,
occupiedCells: Set<string> occupiedCells: Set<string>,
): boolean { ): boolean {
const cells = transformShape(shape, transform); const cells = transformShape(shape, transform);
@ -159,12 +162,17 @@ export function checkBounds(
shape: ParsedShape, shape: ParsedShape,
transform: Transform2D, transform: Transform2D,
boardWidth: number, boardWidth: number,
boardHeight: number boardHeight: number,
): boolean { ): boolean {
const cells = transformShape(shape, transform); const cells = transformShape(shape, transform);
for (const cell of cells) { for (const cell of cells) {
if (cell.x < 0 || cell.x >= boardWidth || cell.y < 0 || cell.y >= boardHeight) { if (
cell.x < 0 ||
cell.x >= boardWidth ||
cell.y < 0 ||
cell.y >= boardHeight
) {
return false; return false;
} }
} }
@ -176,19 +184,19 @@ export function checkBounds(
* Validates that a placement is both in bounds and collision-free. * Validates that a placement is both in bounds and collision-free.
* @returns Object with `valid` flag and optional `reason` string * @returns Object with `valid` flag and optional `reason` string
*/ */
export function validatePlacement( export function validateShapePlacement(
shape: ParsedShape, shape: ParsedShape,
transform: Transform2D, transform: Transform2D,
boardWidth: number, boardWidth: number,
boardHeight: number, boardHeight: number,
occupiedCells: Set<string> occupiedCells: Set<string>,
): { valid: true } | { valid: false; reason: string } { ): { valid: true } | { valid: false; reason: string } {
if (!checkBounds(shape, transform, boardWidth, boardHeight)) { if (!checkBounds(shape, transform, boardWidth, boardHeight)) {
return { valid: false, reason: '超出边界' }; return { valid: false, reason: "超出边界" };
} }
if (checkBoardCollision(shape, transform, occupiedCells)) { if (checkBoardCollision(shape, transform, occupiedCells)) {
return { valid: false, reason: '与已有形状重叠' }; return { valid: false, reason: "与已有形状重叠" };
} }
return { valid: true }; return { valid: true };
@ -199,10 +207,13 @@ export function validatePlacement(
* @param current The current transform * @param current The current transform
* @param degrees Degrees to rotate (typically 90, 180, or 270) * @param degrees Degrees to rotate (typically 90, 180, or 270)
*/ */
export function rotateTransform(current: Transform2D, degrees: number): Transform2D { export function rotateTransform(
current: Transform2D,
degrees: number,
): Transform2D {
return { return {
...current, ...current,
rotation: ((current.rotation + degrees) % 360 + 360) % 360, rotation: (((current.rotation + degrees) % 360) + 360) % 360,
}; };
} }