fix texture reuse on run cycle restart + expose debug kill

- Remove existing tilemap/minimap textures before recreating (prevents
  "Texture key already in use" error on second run)
- Expose __game and __debugKill for dev console testing

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Денис Шкабатур
2026-02-12 15:22:49 +03:00
parent 56c96798e3
commit 3d4f710cb0
4 changed files with 20 additions and 3 deletions

View File

@@ -1,4 +1,7 @@
import Phaser from 'phaser'; import Phaser from 'phaser';
import { gameConfig } from './config'; import { gameConfig } from './config';
new Phaser.Game(gameConfig); const game = new Phaser.Game(gameConfig);
// Expose for debug console access
(window as unknown as Record<string, unknown>).__game = game;

View File

@@ -251,6 +251,11 @@ export class GameScene extends Phaser.Scene {
this.time.delayedCall(500, () => { this.time.delayedCall(500, () => {
advancePhase(this.runState); // Awakening → Exploration advancePhase(this.runState); // Awakening → Exploration
}); });
// Debug: expose kill method for testing death cycle
(this as unknown as Record<string, unknown>).__debugKill = () => {
Health.current[this.playerEid] = 0;
};
} }
/** Give the player their school's starting elements */ /** Give the player their school's starting elements */

View File

@@ -82,6 +82,10 @@ export class Minimap {
const canvasW = w * scale; const canvasW = w * scale;
const canvasH = h * scale; const canvasH = h * scale;
// Remove old texture if re-entering scene (run cycle)
if (scene.textures.exists('minimap')) {
scene.textures.remove('minimap');
}
const canvasTexture = scene.textures.createCanvas('minimap', canvasW, canvasH); const canvasTexture = scene.textures.createCanvas('minimap', canvasW, canvasH);
const ctx = canvasTexture.getContext(); const ctx = canvasTexture.getContext();

View File

@@ -15,7 +15,12 @@ export function createWorldTilemap(
const { grid, biome } = worldData; const { grid, biome } = worldData;
const textureKey = `tileset-${biome.id}`; const textureKey = `tileset-${biome.id}`;
// 1. Generate tileset texture // 1. Remove old texture if re-entering scene (run cycle)
if (scene.textures.exists(textureKey)) {
scene.textures.remove(textureKey);
}
// 2. Generate tileset texture
createTilesetTexture(scene, biome.tiles, biome.tileSize, textureKey); createTilesetTexture(scene, biome.tiles, biome.tileSize, textureKey);
// 2. Create tilemap from grid // 2. Create tilemap from grid