27 lines
589 B
JavaScript
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;
|
|
}
|
|
}
|
|
|
|
}
|