From aac26f672025b75fb5d0a152e2a32994c7252db5 Mon Sep 17 00:00:00 2001 From: chfhtw Date: Fri, 17 Apr 2026 10:02:34 +0200 Subject: [PATCH] replace with faster logic --- public/js/composables/GridLogic.js | 45 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/public/js/composables/GridLogic.js b/public/js/composables/GridLogic.js index 1a540ea06..21c2936c0 100644 --- a/public/js/composables/GridLogic.js +++ b/public/js/composables/GridLogic.js @@ -104,8 +104,6 @@ class GridLogic { prefer = DIR_RIGHT; } - const originalFrame = Array.isArray(item.frame) ? [...item.frame] : [item.frame]; - const currItem = {...item}; currItem.x = x; currItem.y = y; @@ -122,7 +120,6 @@ class GridLogic { const targetAndItemOverlap = this.getItemFrame(item).some(frame => currItem.frame.includes(frame)) if (!targetAndItemOverlap) { - let occupiersData = occupiers.map(occupier => this.data[occupier]); // checks if target contains widget with the same high and width // so swapping is possible const occupiersFrame = occupiers.map(occupier => this.data[occupier].frame).flat(); @@ -130,19 +127,35 @@ class GridLogic { if (occupiersInsideMovingItem) { // every slot of all items in the target zone is inside said zone - let replaceUpdate = []; - let newOccupierFrames = []; - for(let f of originalFrame){ - if(newOccupierFrames.includes(f)){ - continue; - } - let occ = occupiersData.shift(); - if(occ){ - newOccupierFrames = [...newOccupierFrames, ...this.getItemFrame({ ...occ, ...this.getSingleFramePosition(f) })]; - replaceUpdate[occ.index] = { index: occ.index, ...this.getSingleFramePosition(f)} - } - } - replaceUpdate[item.index] = { index: item.index, x, y }; + const replaceUpdate = []; + + const diffX = item.x - x; + const diffY = item.y - y; + + occupiers.forEach(occupier => { + const data = { ...this.data[occupier] }; + data.x += diffX; + data.y += diffY; + data.frame = this.getItemFrame(data); + this.remove(data); + this.add(data); + replaceUpdate[occupier] = { + index: data.index, + x: data.x, + y: data.y, + w: data.w, + h: data.h + }; + }); + + this.add({ ...item, x, y }); + replaceUpdate[item.index] = { + index: item.index, + x, + y, + w: item.w, + h: item.h + }; return replaceUpdate; }