silphius/app/ecs/systems/inventory-closer.js
2024-07-28 18:42:28 -05:00

25 lines
554 B
JavaScript

import {System} from '@/ecs/index.js';
import {distance} from '@/util/math.js';
export default class InventoryCloser extends System {
static queries() {
return {
default: ['Player'],
};
}
tick() {
for (const {Player, Position} of this.select('default')) {
const {openInventory} = Player;
if (openInventory) {
const {Position: inventoryPosition} = this.ecs.get(openInventory.entity);
if (distance(Position, inventoryPosition) > 64) {
Player.closeInventory();
}
}
}
}
}