silphius/app/ecs/systems/interactions.js

27 lines
589 B
JavaScript
Raw Normal View History

2024-07-01 18:12:53 -05:00
import {System} from '@/ecs/index.js';
2024-07-02 14:41:54 -05:00
export default class Interactions extends System {
2024-07-01 18:12:53 -05:00
static queries() {
return {
default: ['Interacts'],
};
}
tick() {
for (const entity of this.select('default')) {
2024-07-22 03:17:43 -05:00
const {Collider, Interacts} = entity;
let willInteractWith = 0;
const entities = Collider.closest(Interacts.aabb());
for (const other of entities) {
2024-07-22 03:17:43 -05:00
if (other.Interactive?.interacting) {
willInteractWith = other.id;
break;
}
2024-07-13 00:33:50 -05:00
}
2024-07-22 03:17:43 -05:00
Interacts.willInteractWith = willInteractWith;
2024-07-01 18:12:53 -05:00
}
}
}