silphius/public/assets/tomato-seeds/projection-check.js

30 lines
587 B
JavaScript
Raw Normal View History

2024-07-07 17:32:54 -05:00
const layer = ecs.get(1).TileLayers.layer(1)
2024-07-20 07:20:32 -05:00
const {tileSize} = layer;
2024-07-07 17:32:54 -05:00
2024-06-28 12:12:38 -05:00
const filtered = []
2024-07-12 17:41:55 -05:00
for (const position of projected) {
2024-07-20 07:20:32 -05:00
const x0 = position.x * tileSize.x;
const y0 = position.y * tileSize.y;
2024-07-28 18:40:58 -05:00
const entities = ecs.system('MaintainColliderHash').within({
2024-07-02 14:41:54 -05:00
x0,
2024-07-20 07:20:32 -05:00
x1: x0 + tileSize.x - 1,
2024-07-02 14:41:54 -05:00
y0,
2024-07-20 07:20:32 -05:00
y1: y0 + tileSize.y - 1,
});
2024-06-28 14:36:49 -05:00
let hasPlant = false;
2024-07-12 17:41:55 -05:00
for (const {Plant} of entities) {
if (Plant) {
2024-06-28 14:36:49 -05:00
hasPlant = true
2024-07-12 18:32:55 -05:00
break;
2024-06-28 14:36:49 -05:00
}
}
if (!hasPlant) {
2024-07-12 17:41:55 -05:00
if ([7].includes(layer.tile(position))) {
filtered.push(position)
2024-06-28 14:36:49 -05:00
}
2024-06-28 12:12:38 -05:00
}
}
2024-07-20 07:20:32 -05:00
filtered