-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconstruction.buildproxy.js
42 lines (32 loc) · 1 KB
/
construction.buildproxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const Y_MULTIPLIER = 100;
function serializePos(pos) {
return pos.x + (Y_MULTIPLIER * pos.y);
}
function deserializePos(value) {
let x = value % Y_MULTIPLIER;
return { x: x, y: (value - x) / Y_MULTIPLIER };
}
module.exports = class BuildProxy {
constructor(room) {
this.room = room;
this.plan = new Map();
}
planConstruction(x, y, structureType) {
let posValue = serializePos({ x: x, y: y });
if(this.plan.has(posValue)) return false;
this.plan.set(posValue, structureType);
return true;
}
get(x, y) {
return this.plan.get(serializePos({ x: x, y: y }));
}
commit() {
for(let posValueAndType of this.plan) {
let pos = deserializePos(posValueAndType[0]);
let structureType = posValueAndType[1];
this.room.createConstructionSite(pos.x, pos.y, structureType);
}
}
}
const profiler = require("screeps-profiler");
profiler.registerObject(module.exports, 'BuildProxy');