From ecf81b78a212540e865f07ab0ca12e948ce6e36b Mon Sep 17 00:00:00 2001 From: NovaFarma Dev Date: Thu, 11 Dec 2025 12:44:41 +0100 Subject: [PATCH] FIX: All crash null checks - farm init + roads + water animation ready to test --- src/scenes/GameScene.js | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/scenes/GameScene.js b/src/scenes/GameScene.js index 1f6cc29..5612617 100644 --- a/src/scenes/GameScene.js +++ b/src/scenes/GameScene.js @@ -87,21 +87,33 @@ class GameScene extends Phaser.Scene { console.log('🛣️ Building Roads...'); // Horizontalna cesta od farme for (let x = 20; x <= 45; x++) { - this.terrainSystem.tiles[22][x].type = 'pavement'; - this.terrainSystem.tiles[22][x].sprite.setTexture('dirt'); // Uporablj dirt kot "cesto" - this.terrainSystem.tiles[22][x].sprite.setTint(0x808080); // Siva barva + if (this.terrainSystem.tiles[22] && this.terrainSystem.tiles[22][x]) { + this.terrainSystem.tiles[22][x].type = 'pavement'; + if (this.terrainSystem.tiles[22][x].sprite) { + this.terrainSystem.tiles[22][x].sprite.setTexture('dirt'); + this.terrainSystem.tiles[22][x].sprite.setTint(0x808080); + } + } } // Vertikalna cesta do mesta for (let y = 22; y <= 65; y++) { - this.terrainSystem.tiles[y][45].type = 'pavement'; - this.terrainSystem.tiles[y][45].sprite.setTexture('dirt'); - this.terrainSystem.tiles[y][45].sprite.setTint(0x808080); + if (this.terrainSystem.tiles[y] && this.terrainSystem.tiles[y][45]) { + this.terrainSystem.tiles[y][45].type = 'pavement'; + if (this.terrainSystem.tiles[y][45].sprite) { + this.terrainSystem.tiles[y][45].sprite.setTexture('dirt'); + this.terrainSystem.tiles[y][45].sprite.setTint(0x808080); + } + } } // Horizontalna cesta do mesta for (let x = 45; x <= 65; x++) { - this.terrainSystem.tiles[65][x].type = 'pavement'; - this.terrainSystem.tiles[65][x].sprite.setTexture('dirt'); - this.terrainSystem.tiles[65][x].sprite.setTint(0x808080); + if (this.terrainSystem.tiles[65] && this.terrainSystem.tiles[65][x]) { + this.terrainSystem.tiles[65][x].type = 'pavement'; + if (this.terrainSystem.tiles[65][x].sprite) { + this.terrainSystem.tiles[65][x].sprite.setTexture('dirt'); + this.terrainSystem.tiles[65][x].sprite.setTint(0x808080); + } + } } // SIGNPOSTS - navigacijske table @@ -740,10 +752,12 @@ class GameScene extends Phaser.Scene { this.terrainSystem.removeDecoration(x, y); } // Make it grass or dirt - USE CORRECT TERRAIN TYPE OBJECT - this.terrainSystem.tiles[y][x].type = this.terrainSystem.terrainTypes.GRASS_FULL; - if (this.terrainSystem.tiles[y][x].sprite) { - this.terrainSystem.tiles[y][x].sprite.setTexture('grass'); - this.terrainSystem.tiles[y][x].sprite.setTint(0xffffff); // Clear tint + if (this.terrainSystem.tiles[y] && this.terrainSystem.tiles[y][x]) { + this.terrainSystem.tiles[y][x].type = this.terrainSystem.terrainTypes.GRASS_FULL; + if (this.terrainSystem.tiles[y][x].sprite) { + this.terrainSystem.tiles[y][x].sprite.setTexture('grass'); + this.terrainSystem.tiles[y][x].sprite.setTint(0xffffff); // Clear tint + } } } }