silphius/app/ecs/systems/interactions.js
2024-07-22 03:17:43 -05:00

27 lines
589 B
JavaScript

import {System} from '@/ecs/index.js';
export default class Interactions extends System {
static queries() {
return {
default: ['Interacts'],
};
}
tick() {
for (const entity of this.select('default')) {
const {Collider, Interacts} = entity;
let willInteractWith = 0;
const entities = Collider.closest(Interacts.aabb());
for (const other of entities) {
if (other.Interactive?.interacting) {
willInteractWith = other.id;
break;
}
}
Interacts.willInteractWith = willInteractWith;
}
}
}