This change didn't break my code, but I still took the challenge to look at a possible fix.
I tried to make the fix as easy as possible, but unfortunately I can't redefine the properties of RoomPosition.prototype. So here is one possible solution, which requires just simple replacements in code:
RoomPosition.prototype.expand = function() {
if (!this.__expanded) {
Object.defineProperty(this, 'x', {
enumerable:true,
value: this.x,
writable: true
});
Object.defineProperty(this, 'y', {
enumerable:true,
value: this.y,
writable: true
});
Object.defineProperty(this, 'roomName', {
enumerable:true,
value: this.roomName,
writable: true
});
Object.defineProperty(this, '__expanded', {
enumerable:false,
value: true,
writable: false
});
}
return this;
}
global.newRoomPosition = function(x, y, roomName) {
var pos = new RoomPosition(0, 0, roomName).expand();
pos.__packedPos = (pos.__packedPos & 0xFFFF0000) | ((x & 0xFF) << 8) | (y & 0xFF); // just for completeness
pos.x = x;
pos.y = y;
pos.roomName = roomName;
return pos;
}
This almost restores the old behaviour with little changes in the code.
Then you can use any value for x, y again and roomName can be lower case again. Object.assign({}, rp} also works again if rp was expanded with expand().
You just have to replace all new RoomPosition to newRoomPosition in your code and before you use positions, call expand().
e.g.
var myPos = Game.spawns.Spawn1.pos.expand(); myPos.x = -1;
or
var myPos = Game.creeps.Creep1.pos; myPos.expand().x = -1; myPos.y = -1;
or
var myPos = Object.assign({}, Game.spawns.Spawn1.pos.expand());
This should minimize the effort to migrate the code now.
Whereever an error pops up because you set x, y or roomName wrong, just add a call to expand() and it will be fine.
You can also let the expand()-part out of your code by pasting:
Object.defineProperty(RoomObject.prototype, 'pos', {
get() {
return this._pos.expand();
},
set(value) {
this._pos = value;
}
});
This fails at the first tick, but works on subsequent ticks.
I hope it helps.