UNPKG

shellquest

Version:

Terminal-based procedurally generated dungeon crawler

77 lines (66 loc) 1.88 kB
// Rotation values for tiles (clockwise degrees) export type TileRotation = 0 | 90 | 180 | 270; // A tile reference with optional rotation export interface TileRef { name: string; rotation?: TileRotation; // Default is 0 } // Helper to create a TileRef (allows string shorthand or full object) export type TileInput = string | TileRef; // Normalize a TileInput to a TileRef export function toTileRef(input: TileInput): TileRef { if (typeof input === 'string') { return {name: input, rotation: 0}; } return {name: input.name, rotation: input.rotation ?? 0}; } // Helper to create rotated tile refs export function rotatedTile(name: string, rotation: TileRotation): TileRef { return {name, rotation}; } // Get the tile name from a TileInput (handles both string and TileRef) export function getTileName(input: TileInput): string { if (typeof input === 'string') { return input; } return input.name; } export interface LevelTile { bottomTile: TileInput; solid: boolean; topTile?: TileInput; topTile2?: TileInput; } export interface Tile { name: string; x: number; y: number; layer: 'bottom' | 'sprite' | 'top'; solid?: boolean; flipX?: boolean; flipY?: boolean; } export interface HouseData { x: number; y: number; width: number; height: number; } /** * Minimal interface for positioned game objects (avoids circular imports) */ export interface Positioned { x: number; y: number; } /** * Common interface for level types (Level and DungeonLevel) * Used by entities to interact with the level without knowing the specific type */ export interface GameLevel { isSolid(x: number, y: number): boolean; removeEntity(entity: unknown): void; addEntity(entity: unknown): void; getEntities(): unknown[]; player: Positioned; }