import {System} from '@/ecs/index.js'; import {distance} from '@/util/math.js'; export default class Interactions extends System { static queries() { return { default: ['Interacts'], }; } tick() { for (const entity of this.select('default')) { const {Interacts} = entity; Interacts.willInteractWith = 0 const entities = Array.from(this.ecs.system('Colliders').within(Interacts.aabb())) .filter((other) => other !== entity) .sort(({Position: l}, {Position: r}) => { return distance(entity.Position, l) > distance(entity.Position, r) ? -1 : 1; }); for (const other of entities) { if (other === entity) { continue; } if (other.Interactive && other.Interactive.interacting) { Interacts.willInteractWith = other.id; } } } } }