arx-level-generator
Version:
A tool for creating Arx Fatalis maps
69 lines • 2.52 kB
JavaScript
import { Vector3 } from '../../Vector3.js';
export class Cursor {
oldSize = new Vector3(0, 0, 0);
newSize = new Vector3(0, 0, 0);
cursor = new Vector3(0, 0, 0);
saves = {};
move(...dirs) {
dirs.forEach((dir) => {
const axis = dir[0];
const alignment = dir.slice(1);
if (axis === 'y') {
switch (alignment) {
case '++':
// next floor = prev ceiling
this.cursor.y -= this.oldSize.y;
break;
case '+':
// next ceiling = prev ceiling
this.cursor.y -= this.oldSize.y - this.newSize.y;
break;
case '':
// next middle = prev middle
this.cursor.y -= this.oldSize.y / 2 - this.newSize.y / 2;
break;
case '-':
// next floor = prev floor
this.cursor.y += 0;
break;
case '--':
// next ceiling = prev floor
this.cursor.y += this.newSize.y;
break;
}
}
else {
switch (alignment) {
case '++':
this.cursor[axis] += this.oldSize[axis] / 2 + this.newSize[axis] / 2;
break;
case '+':
this.cursor[axis] += this.oldSize[axis] / 2 - this.newSize[axis] / 2;
break;
case '-':
this.cursor[axis] -= this.oldSize[axis] / 2 - this.newSize[axis] / 2;
break;
case '--':
this.cursor[axis] -= this.oldSize[axis] / 2 + this.newSize[axis] / 2;
break;
}
}
});
}
saveAs(key) {
this.saves[key] = {
cursor: this.cursor.clone(),
oldSize: this.oldSize.clone(),
newSize: this.newSize.clone(),
};
}
restore(key) {
if (key in this.saves) {
const { cursor, oldSize, newSize } = this.saves[key];
this.cursor = cursor.clone();
this.oldSize = oldSize.clone();
this.newSize = newSize.clone();
}
}
}
//# sourceMappingURL=Cursor.js.map