-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.js
36 lines (33 loc) · 897 Bytes
/
cache.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
var cache = {
run: function() {
//DELETE UNUSED MEMORY
for (let i in Memory.creeps) {
if(!Game.creeps[i]) {
delete Memory.creeps[i];
// console.log('Clearing non-existing creep memory:', name);
}
}
}
};
Object.defineProperty(Structure.prototype, 'memory', {
configurable: true,
get: function() {
if (_.isUndefined(Memory.myStructuresMemory)) {
Memory.myStructuresMemory = {};
}
if (!_.isObject(Memory.myStructuresMemory)) {
return undefined;
}
return Memory.myStructuresMemory[this.id] = Memory.myStructuresMemory[this.id] || {};
},
set: function(value) {
if(_.isUndefined(Memory.myStructuresMemory)) {
Memory.myStructuresMemory = {};
}
if(!_.isObject(Memory.myStructuresMemory)) {
throw new Error('Could not set source memory');
}
Memory.myStructuresMemory[this.id] = value;
}
});
module.exports = cache;