asciitorium
Version:
an ASCII CLUI framework
50 lines (49 loc) • 1.93 kB
TypeScript
import { Component, ComponentProps } from '../core/Component.js';
import type { State } from '../core/State.js';
import { Player } from './MapView.js';
import type { MapAsset, LegendEntry } from '../core/AssetManager.js';
export interface FirstPersonViewOptions extends Omit<ComponentProps, 'children'> {
mapAsset: State<MapAsset | null>;
player: State<Player>;
transparency?: boolean;
}
export declare class FirstPersonView extends Component {
focusable: boolean;
private mapAssetState;
private playerState;
private compositor;
private transparency;
private cachedView;
constructor(options: FirstPersonViewOptions);
get mapAsset(): MapAsset | null;
get mapData(): string[];
get legend(): Record<string, LegendEntry>;
get player(): Player;
private isSolid;
/**
* Converts a cardinal direction into a unit vector for coordinate calculations
*
* Coordinate System:
* - X axis: Horizontal (left/right) - positive X goes east (right)
* - Y axis: Vertical (up/down) - positive Y goes south (down)
*
* This matches typical 2D array indexing where:
* - map[y][x] means row Y, column X
* - Moving "down" increases Y (going to higher row indices)
* - Moving "right" increases X (going to higher column indices)
*/
private getDirectionVector;
private getLeftDirection;
private getRightDirection;
/**
* Cast rays using predefined offset cubes to determine what's visible in the first-person view
*
* Uses direction-specific raycast cubes with predefined relative offsets for each position.
* This eliminates coordinate calculation errors and provides complete control over
* which exact positions are checked for each direction.
*
* Returns the actual map character at each position (or null if occluded/out of bounds)
*/
private castRays;
draw(): string[][];
}