silphius/app/ecs/components/interacts.js

35 lines
832 B
JavaScript
Raw Normal View History

2024-07-01 18:12:53 -05:00
import Component from '@/ecs/component.js';
export default class Interacts extends Component {
instanceFromSchema() {
const {ecs} = this;
2024-07-01 18:12:53 -05:00
return class ControlledInstance extends super.instanceFromSchema() {
aabb() {
const {Direction, Position} = ecs.get(this.entity);
let x0 = Position.x - 8;
let y0 = Position.y - 8;
2024-07-24 09:28:35 -05:00
const direction = Direction.quantize(4);
if (0 === direction) {
2024-07-22 01:43:05 -05:00
x0 += 12
}
2024-07-24 09:28:35 -05:00
if (1 === direction) {
2024-07-22 01:43:05 -05:00
y0 += 12
}
2024-07-24 09:28:35 -05:00
if (2 === direction) {
2024-07-22 01:43:05 -05:00
x0 -= 12
}
2024-07-24 09:28:35 -05:00
if (3 === direction) {
y0 -= 12
}
return {x0, x1: x0 + 15, y0, y1: y0 + 15};
}
2024-07-01 18:12:53 -05:00
toJSON() {
return {};
}
}
}
static properties = {
willInteractWith: {type: 'uint32'},
};
}