nalaganje tiled mape. ozadje ni OK.
This commit is contained in:
@@ -10,7 +10,7 @@ class PathfindingSystem {
|
||||
// Ustvarimo workerja
|
||||
this.worker = new Worker('src/workers/pathfinding.worker.js');
|
||||
this.worker.onmessage = this.handleMessage.bind(this);
|
||||
console.log('✅ PathfindingWorker initialized.');
|
||||
console.log('✅ PathfindingWorker initialized (v2.1 - Tiled Support Ready).');
|
||||
this.initialized = true;
|
||||
} catch (err) {
|
||||
console.error('❌ Failed to init PathfindingWorker:', err);
|
||||
@@ -31,26 +31,46 @@ class PathfindingSystem {
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
let blocked = 0;
|
||||
const tile = ts.tiles[y][x];
|
||||
|
||||
// 1. Voda in void
|
||||
if (!tile || tile.type === 'water' || tile.type === 'void') {
|
||||
blocked = 1;
|
||||
} else {
|
||||
// 2. Dekoracije (Ovire)
|
||||
// Uporabimo že obstoječo logiko v TerrainSystemu (če obstaja) ali preverimo dekoracije
|
||||
const key = `${x},${y}`;
|
||||
const decor = ts.decorationsMap.get(key);
|
||||
if (decor) {
|
||||
const solidTypes = [
|
||||
'tree', 'tree_green', 'tree_blue', 'tree_dead',
|
||||
'tree_green_new', 'tree_blue_new', 'tree_dead_new',
|
||||
'rock', 'rock_asset', 'rock_new', 'rock_small', 'rock_1', 'rock_2',
|
||||
'wall', 'fence', 'house', 'gravestone'
|
||||
];
|
||||
// Preverimo substring za tipe (npr. 'tree' ujame 'tree_blue')
|
||||
const isSolid = solidTypes.some(t => decor.type.includes(t));
|
||||
if (isSolid) blocked = 1;
|
||||
// 🗺️ 1. TILED MAP SUPPORT
|
||||
if (ts.tiledMap) {
|
||||
// Check various obstacle layers
|
||||
const obstacleLayers = ['Obstacles', 'Buildings', 'Fences', '02_Obstacles', '03_Fences', '04_Buildings'];
|
||||
let isBlocked = false;
|
||||
|
||||
for (const layerName of obstacleLayers) {
|
||||
const tile = ts.tiledMap.getTileAt(x, y, true, layerName);
|
||||
if (tile && tile.index !== -1) {
|
||||
isBlocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlocked) {
|
||||
blocked = 1;
|
||||
}
|
||||
}
|
||||
// 📊 2. PROCEDURAL / FLAT TILES SUPPORT
|
||||
else {
|
||||
const tile = ts.tiles && ts.tiles[y] ? ts.tiles[y][x] : null;
|
||||
|
||||
// 1. Voda in void
|
||||
if (!tile || tile.type === 'water' || tile.type === 'void') {
|
||||
blocked = 1;
|
||||
} else {
|
||||
// 2. Dekoracije (Ovire)
|
||||
const key = `${x},${y}`;
|
||||
const decor = ts.decorationsMap.get(key);
|
||||
if (decor) {
|
||||
const solidTypes = [
|
||||
'tree', 'tree_green', 'tree_blue', 'tree_dead',
|
||||
'tree_green_new', 'tree_blue_new', 'tree_dead_new',
|
||||
'rock', 'rock_asset', 'rock_new', 'rock_small', 'rock_1', 'rock_2',
|
||||
'wall', 'fence', 'house', 'gravestone'
|
||||
];
|
||||
const isSolid = solidTypes.some(t => decor.type && decor.type.includes(t));
|
||||
if (isSolid) blocked = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user