Browse Source

bug #1840: Fixed the map loader to not crash when room exits are defined before their corresponding room definitions

tags/v0.10.4^2
Shaun 2 years ago
parent
commit
4993657076
1 changed files with 12 additions and 6 deletions
  1. +12
    -6
      src/server/world/map.js

+ 12
- 6
src/server/world/map.js View File

@@ -259,12 +259,18 @@ module.exports = {
const layers = [...mapFile.layers.filter(l => l.objects), ...mapFile.layers.filter(l => !l.objects)];

//Rooms need to be ahead of exits
layers.rooms = (layers.rooms || [])
.sort(function (a, b) {
if ((a.exit) && (!b.exit))
return 1;
return 0;
});
const layerRooms = layers.find(l => l.name === 'rooms') || {};
layerRooms.objects.sort((a, b) => {
const isExitA = a?.properties?.some(p => p.name === 'exit');
const isExitB = b?.properties?.some(p => p.name === 'exit');

if (isExitA && !isExitB)
return 1;
else if (!isExitA && isExitB)
return -1;

return 0;
});

for (let i = 0; i < layers.length; i++) {
let layer = layers[i];


Loading…
Cancel
Save