✨ add F3 debug view (Issue #6)
F3 toggles a debug overlay with: - FPS - Mouse world/tile coordinates - Tile type under cursor - Resources, buildings, crops on hovered tile - Nisse count broken down by AI state (idle/walking/working/sleeping) - Active jobs by type (chop/mine/farm) - Pathfinding visualization: cyan lines + destination highlight drawn in world space via DebugSystem Added DebugSystem to GameScene. VillagerSystem exposes getActivePaths() for the path visualization. JSDoc added to all previously undocumented methods in VillagerSystem, WorldSystem, GameScene, and UIScene.
This commit is contained in:
@@ -22,10 +22,15 @@ export class WorldSystem {
|
||||
private bgImage!: Phaser.GameObjects.Image
|
||||
private builtLayer!: Phaser.Tilemaps.TilemapLayer
|
||||
|
||||
/** @param scene - The Phaser scene this system belongs to */
|
||||
constructor(scene: Phaser.Scene) {
|
||||
this.scene = scene
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the terrain background canvas from saved tile data,
|
||||
* creates the built-tile tilemap layer, and sets camera bounds.
|
||||
*/
|
||||
create(): void {
|
||||
const state = stateManager.getState()
|
||||
|
||||
@@ -81,10 +86,18 @@ export class WorldSystem {
|
||||
this.scene.cameras.main.setBounds(0, 0, WORLD_TILES * TILE_SIZE, WORLD_TILES * TILE_SIZE)
|
||||
}
|
||||
|
||||
/** Returns the built-tile tilemap layer (floor, wall, soil). */
|
||||
getLayer(): Phaser.Tilemaps.TilemapLayer {
|
||||
return this.builtLayer
|
||||
}
|
||||
|
||||
/**
|
||||
* Places or removes a tile on the built layer.
|
||||
* Built tile types are added; natural types remove the built-layer entry.
|
||||
* @param tileX - Tile column
|
||||
* @param tileY - Tile row
|
||||
* @param type - New tile type to apply
|
||||
*/
|
||||
setTile(tileX: number, tileY: number, type: TileType): void {
|
||||
const BUILT_TILES = new Set([TileType.FLOOR, TileType.WALL, TileType.TILLED_SOIL, TileType.WATERED_SOIL])
|
||||
if (BUILT_TILES.has(type)) {
|
||||
@@ -95,6 +108,12 @@ export class WorldSystem {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the tile at the given coordinates can be walked on.
|
||||
* Out-of-bounds tiles are treated as impassable.
|
||||
* @param tileX - Tile column
|
||||
* @param tileY - Tile row
|
||||
*/
|
||||
isPassable(tileX: number, tileY: number): boolean {
|
||||
if (tileX < 0 || tileY < 0 || tileX >= WORLD_TILES || tileY >= WORLD_TILES) return false
|
||||
const state = stateManager.getState()
|
||||
@@ -102,6 +121,12 @@ export class WorldSystem {
|
||||
return !IMPASSABLE.has(tile)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts world pixel coordinates to tile coordinates.
|
||||
* @param worldX - World X in pixels
|
||||
* @param worldY - World Y in pixels
|
||||
* @returns Integer tile position
|
||||
*/
|
||||
worldToTile(worldX: number, worldY: number): { tileX: number; tileY: number } {
|
||||
return {
|
||||
tileX: Math.floor(worldX / TILE_SIZE),
|
||||
@@ -109,6 +134,12 @@ export class WorldSystem {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts tile coordinates to the world pixel center of that tile.
|
||||
* @param tileX - Tile column
|
||||
* @param tileY - Tile row
|
||||
* @returns World pixel center position
|
||||
*/
|
||||
tileToWorld(tileX: number, tileY: number): { x: number; y: number } {
|
||||
return {
|
||||
x: tileX * TILE_SIZE + TILE_SIZE / 2,
|
||||
@@ -116,11 +147,17 @@ export class WorldSystem {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tile type at the given tile coordinates from saved state.
|
||||
* @param tileX - Tile column
|
||||
* @param tileY - Tile row
|
||||
*/
|
||||
getTileType(tileX: number, tileY: number): TileType {
|
||||
const state = stateManager.getState()
|
||||
return state.world.tiles[tileY * WORLD_TILES + tileX] as TileType
|
||||
}
|
||||
|
||||
/** Destroys the tilemap and background image. */
|
||||
destroy(): void {
|
||||
this.map.destroy()
|
||||
this.bgImage.destroy()
|
||||
|
||||
Reference in New Issue
Block a user