Refactor codebase

This commit is contained in:
Peter Stockings
2026-01-04 15:56:18 +11:00
parent 3785885abe
commit bfe5ebae8c
18 changed files with 380 additions and 191 deletions

View File

@@ -4,15 +4,15 @@ import {
type Vec2,
type Action,
type RunState,
type World,
TILE_SIZE
} from "../game/types";
import { inBounds, isBlocked, isPlayerOnExit } from "../game/world";
import { findPathAStar } from "../game/pathfinding";
import { applyAction, stepUntilPlayerTurn } from "../game/simulation";
import { makeTestWorld } from "../game/generator";
import { DungeonRenderer } from "./DungeonRenderer";
import { GAME_CONFIG } from "../game/config/GameConfig";
type World
} from "../core/types";
import { TILE_SIZE } from "../core/constants";
import { inBounds, isBlocked, isPlayerOnExit } from "../engine/world/world-logic";
import { findPathAStar } from "../engine/world/pathfinding";
import { applyAction, stepUntilPlayerTurn } from "../engine/simulation/simulation";
import { makeTestWorld } from "../engine/world/generator";
import { DungeonRenderer } from "../rendering/DungeonRenderer";
import { GAME_CONFIG } from "../core/config/GameConfig";
export class GameScene extends Phaser.Scene {
private world!: World;
@@ -87,6 +87,12 @@ export class GameScene extends Phaser.Scene {
this.dungeonRenderer.toggleMinimap();
});
this.input.keyboard?.on("keydown-SPACE", () => {
if (!this.awaitingPlayer) return;
if (this.isMenuOpen || this.dungeonRenderer.isMinimapVisible()) return;
this.commitPlayerAction({ type: "wait" });
});
// Listen for Map button click from UI
this.events.on("toggle-minimap", () => {
this.dungeonRenderer.toggleMinimap();
@@ -176,17 +182,14 @@ export class GameScene extends Phaser.Scene {
else if (Phaser.Input.Keyboard.JustDown(this.cursors.down!)) dy = 1;
if (dx !== 0 || dy !== 0) {
console.log("Input: ", dx, dy);
const player = this.world.actors.get(this.playerId)!;
const targetX = player.pos.x + dx;
const targetY = player.pos.y + dy;
console.log("Target: ", targetX, targetY);
// Check for enemy at target position
const targetId = [...this.world.actors.values()].find(
a => a.pos.x === targetX && a.pos.y === targetY && !a.isPlayer
)?.id;
console.log("Found Target ID:", targetId);
if (targetId !== undefined) {
action = { type: "attack", targetId };
@@ -218,14 +221,16 @@ export class GameScene extends Phaser.Scene {
// Process events for visual fx
const allEvents = [...playerEvents, ...enemyStep.events];
if (allEvents.length > 0) console.log("Events:", allEvents);
for (const ev of allEvents) {
if (ev.type === "damaged") {
console.log("Showing damage:", ev.amount, "at", ev.x, ev.y);
this.dungeonRenderer.showDamage(ev.x, ev.y, ev.amount);
} else if (ev.type === "killed") {
console.log("Showing corpse for:", ev.victimType, "at", ev.x, ev.y);
this.dungeonRenderer.spawnCorpse(ev.x, ev.y, ev.victimType || "rat");
} else if (ev.type === "waited" && ev.actorId === this.playerId) {
const player = this.world.actors.get(this.playerId);
if (player) {
this.dungeonRenderer.showWait(player.pos.x, player.pos.y);
}
}
}