70 lines
2.8 KiB
TypeScript
70 lines
2.8 KiB
TypeScript
export const TileType = {
|
|
EMPTY: 1,
|
|
WALL: 4,
|
|
GRASS: 15,
|
|
GRASS_SAPLINGS: 2,
|
|
EMPTY_DECO: 24,
|
|
WALL_DECO: 12,
|
|
EXIT: 8,
|
|
WATER: 63, // Unused but kept for safety/legacy
|
|
DOOR_CLOSED: 5,
|
|
DOOR_OPEN: 6,
|
|
TRACK: 30, // Restored to 30 to fix duplicate key error
|
|
SWITCH_OFF: 31,
|
|
SWITCH_ON: 32
|
|
} as const;
|
|
|
|
|
|
export type TileType = typeof TileType[keyof typeof TileType];
|
|
|
|
export interface TileBehavior {
|
|
id: TileType;
|
|
isBlocking: boolean;
|
|
isDestructible: boolean;
|
|
isDestructibleByWalk?: boolean;
|
|
blocksVision?: boolean;
|
|
destructsTo?: TileType;
|
|
}
|
|
|
|
export const TILE_DEFINITIONS: Record<number, TileBehavior> = {
|
|
[TileType.EMPTY]: { id: TileType.EMPTY, isBlocking: false, isDestructible: false },
|
|
[TileType.WALL]: { id: TileType.WALL, isBlocking: true, isDestructible: false },
|
|
[TileType.GRASS]: { id: TileType.GRASS, isBlocking: false, isDestructible: true, isDestructibleByWalk: true, blocksVision: true, destructsTo: TileType.GRASS_SAPLINGS },
|
|
[TileType.GRASS_SAPLINGS]: { id: TileType.GRASS_SAPLINGS, isBlocking: false, isDestructible: false },
|
|
[TileType.EMPTY_DECO]: { id: TileType.EMPTY_DECO, isBlocking: false, isDestructible: false },
|
|
[TileType.WALL_DECO]: { id: TileType.WALL_DECO, isBlocking: true, isDestructible: false },
|
|
[TileType.EXIT]: { id: TileType.EXIT, isBlocking: false, isDestructible: false },
|
|
[TileType.WATER]: { id: TileType.WATER, isBlocking: true, isDestructible: false },
|
|
[TileType.DOOR_CLOSED]: { id: TileType.DOOR_CLOSED, isBlocking: false, isDestructible: true, isDestructibleByWalk: true, blocksVision: true, destructsTo: TileType.DOOR_OPEN },
|
|
[TileType.DOOR_OPEN]: { id: TileType.DOOR_OPEN, isBlocking: false, isDestructible: true, isDestructibleByWalk: true, blocksVision: false, destructsTo: TileType.DOOR_CLOSED },
|
|
[TileType.TRACK]: { id: TileType.TRACK, isBlocking: false, isDestructible: false },
|
|
[TileType.SWITCH_OFF]: { id: TileType.SWITCH_OFF, isBlocking: true, isDestructible: false },
|
|
[TileType.SWITCH_ON]: { id: TileType.SWITCH_ON, isBlocking: true, isDestructible: false }
|
|
};
|
|
|
|
|
|
export function isBlocking(tile: number): boolean {
|
|
const def = TILE_DEFINITIONS[tile];
|
|
return def ? def.isBlocking : false;
|
|
}
|
|
|
|
export function isDestructible(tile: number): boolean {
|
|
const def = TILE_DEFINITIONS[tile];
|
|
return def ? def.isDestructible : false;
|
|
}
|
|
|
|
export function isDestructibleByWalk(tile: number): boolean {
|
|
const def = TILE_DEFINITIONS[tile];
|
|
return def ? !!def.isDestructibleByWalk : false;
|
|
}
|
|
|
|
export function blocksSight(tile: number): boolean {
|
|
const def = TILE_DEFINITIONS[tile];
|
|
return def ? (def.isBlocking || !!def.blocksVision) : false;
|
|
}
|
|
|
|
export function getDestructionResult(tile: number): number | undefined {
|
|
const def = TILE_DEFINITIONS[tile];
|
|
return def ? def.destructsTo : undefined;
|
|
}
|