mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
easier more straightforward way to computed free slots in gridlogic
This commit is contained in:
@@ -23,30 +23,18 @@ class GridLogic {
|
||||
const i = y*this.w + x;
|
||||
return !this.grid[i] && this.grid[i] !== 0;
|
||||
}
|
||||
getMaxY(){
|
||||
return this.data.reduce((acc, item) => {
|
||||
if (item?.y > acc) {
|
||||
acc = item.y;
|
||||
}
|
||||
return acc;
|
||||
}, 0);
|
||||
}
|
||||
getFreeSlots() {
|
||||
const freeSlots = [];
|
||||
let biggestY = this.getMaxY();
|
||||
let totalSpaces = this.w * (biggestY+1);
|
||||
for(let i=0; i < totalSpaces; i++){
|
||||
if (!this.grid[i] && this.grid[i] !== 0){
|
||||
this.grid[i] = undefined;
|
||||
}
|
||||
}
|
||||
for(let i =0; i < this.grid.length; i++){
|
||||
if (!this.grid[i] && this.grid[i] !== 0){
|
||||
let i = this.w * this.h;
|
||||
|
||||
while (i--) {
|
||||
if (!this.grid[i] && this.grid[i] !== 0) {
|
||||
let x = i % this.w;
|
||||
let y = Math.floor(i / this.w);
|
||||
freeSlots.push({x, y});
|
||||
}
|
||||
}
|
||||
|
||||
return freeSlots;
|
||||
}
|
||||
add(item, prefer) {
|
||||
|
||||
Reference in New Issue
Block a user