sc4
Version:
A command line utility for automating SimCity 4 modding tasks & modifying savegames
41 lines (40 loc) • 1.11 kB
JavaScript
// # Vector3
// Represents a three-dimensional vector. Note that we consider vectors to be
// *value types*, so any operation on it returns a new vector. We don't modify
// the vector by reference! Compare this how the new JavaScript temporal api is
// designed.
export class Vector3 extends Array {
constructor(x = 0, y = 0, z = 0) {
super(x, y, z);
}
get x() { return this[0]; }
get y() { return this[1]; }
get z() { return this[2]; }
set x(value) { this[0] = value; }
set y(value) { this[1] = value; }
set z(value) { this[2] = value; }
// ## clone()
clone() {
return new Vector3(...this);
}
// ## add()
add(dv) {
let [dx, dy, dz] = dv;
return new Vector3(this.x + dx, this.y + dy, this.z + dz);
}
// ## parse(rs)
parse(rs) {
this[0] = rs.float();
this[1] = rs.float();
this[2] = rs.float();
return this;
}
// ## write(ws)
write(ws) {
ws.float(this[0]);
ws.float(this[1]);
ws.float(this[2]);
return this;
}
}
export default Vector3;