From e21f35b880eadf2f4e3b73e169f1e24db79fc970 Mon Sep 17 00:00:00 2001 From: chfhtw Date: Thu, 16 Apr 2026 10:58:47 +0200 Subject: [PATCH] easier more straightforward way to computed free slots in gridlogic --- public/js/composables/GridLogic.js | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/public/js/composables/GridLogic.js b/public/js/composables/GridLogic.js index d6a38f2ca..b901d115d 100644 --- a/public/js/composables/GridLogic.js +++ b/public/js/composables/GridLogic.js @@ -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) {