Browse Source

Revert "chore: removed unused code"

This reverts commit 1537f4c5da
tags/v0.12.0
Big Bad Waffle 1 year ago
parent
commit
6cf99a8a6b
2 changed files with 107 additions and 2 deletions
  1. +2
    -2
      src/server/world/atlas.js
  2. +105
    -0
      src/server/world/customMap.js

+ 2
- 2
src/server/world/atlas.js View File

@@ -49,8 +49,6 @@ module.exports = {
serverObj.zoneId = thread.id;
serverObj.zoneName = thread.name;

serverObj.player.broadcastSelf();

const simpleObj = obj.getSimple ? obj.getSimple(true, true) : obj;

this.send(obj.zoneId, {
@@ -292,6 +290,8 @@ module.exports = {
delete serverObj.zoneId;
delete obj.zoneId;

serverObj.player.broadcastSelf();

const isRezone = true;
await this.addObject(obj, keepPos, isRezone);
},


+ 105
- 0
src/server/world/customMap.js View File

@@ -0,0 +1,105 @@
module.exports = {
instance: null,
ent: null,
tiles: [],
oldTiles: {},

load: function (instance, objToAdd, callback) {
this.instance = instance;

this.ent = instance.mapName + '-' + objToAdd.components.find(c => c.type === 'auth').username;

io.get({
ent: this.ent,
field: 'customMap',
callback: this.onLoad.bind(this, callback)
});
},

onLoad: function (callback, result) {
this.tiles = JSON.parse(result || '[]');
this.build(callback);
},

save: async function () {
await io.setAsync({
key: this.ent,
table: 'customMap',
value: this.tiles,
serialize: true
});
},

build: function (callback) {
this.tiles.forEach(function (t) {
t = t.split('|');
this.customize(t[0], t[1], t[2], true);
}, this);

this.save();

callback();
},

customize: function (x, y, tile, noStore) {
let action = null;
if (arguments.length === 1) {
action = x;
let obj = action.obj;
tile = action.tile;
x = obj.x;
y = obj.y;

if (action.destroy) {
x += action.direction.x;
y += action.direction.y;
}
}

let collide = true;

if (!noStore) {
let exists = this.tiles.find(function (t) {
t = t.split('|');
if ((t[0] === x) && (t[1] === y))
return true;
});
if (exists) {
tile = this.oldTiles[x + '|' + y];
collide = false;

this.tiles.spliceWhere(t => t === exists);
} else if (this.instance.map.clientMap.collisionMap[x][y]) {
//Can't build on natural collisions
return;
} else
this.tiles.push(x + '|' + y + '|' + tile);
}

if ((collide) && (!this.oldTiles[x + '|' + y])) {
let oldTile = this.instance.map.clientMap.map[x][y];
this.oldTiles[x + '|' + y] = oldTile - 1;
}

this.instance.map.clientMap.map[x][y] = tile;

this.instance.map.clientMap.collisionMap[x][y] = collide;
this.instance.physics.graph.grid[x][y] = !collide;

if (!noStore)
this.save();

if (action) {
action.result = {
x: x,
y: y,
tile: tile,
collide: collide
};
}
},

placeTile: function (obj) {
this.customize(obj.x, obj.y, 52);
}
};

Loading…
Cancel
Save