Selaa lähdekoodia

Fixed more bugs on desktop file position assignment

Toby Chui 3 vuotta sitten
vanhempi
commit
18a94ab646
2 muutettua tiedostoa jossa 19 lisäystä ja 12 poistoa
  1. 17 12
      web/desktop.system
  2. 2 0
      web/script/ao_module.js

+ 17 - 12
web/desktop.system

@@ -3504,14 +3504,6 @@
                     targetGridLocation[1] = targetGridLocation[1] - 1;
                     var nextLocation = JSON.parse(JSON.stringify(targetGridLocation));
                     for (var k =0; k < files.length; k++){
-                        if (nextLocation[1] >= gridMaxY && nextLocation[0] >= gridMaxX){
-                            //Desktop full. Force put to 0 0 
-                            nextLocation[0] = 0;
-                            nextLocation[1] = 0;
-                            locations.push(JSON.parse(JSON.stringify(nextLocation)));
-                            continue;
-                        }
-
                         //Add 1 to the file y position
                         nextLocation[1] += 1;
                         if (nextLocation[1] >= gridMaxY){
@@ -3520,11 +3512,21 @@
                             nextLocation[1] = 0;
                         }
 
+                        if (nextLocation[0] >= desktopGrids.length){
+                            //Desktop full. Force put to 0 0 
+                            nextLocation[0] = 0;
+                            nextLocation[1] = 0;
+                            locations.push(JSON.parse(JSON.stringify(nextLocation)));
+                            continue;
+                        }
+
+
                         //Check if this position is occupied, update next placement location if true
+                        console.log("Grid Location:", nextLocation[0], nextLocation[1]);
                         while (getObjectFromGridLocation(nextLocation[0], nextLocation[1]) !== undefined){
                             let gridLocation = getLocationFromGridIndex(nextLocation[0], nextLocation[1]);
                             let newAssignmentLocation = findClostestEmptyGridLocation(gridLocation[0],gridLocation[1]);
-                            nextLocation = newAssignmentLocation;
+                            nextLocation = newAssignmentLocation[1];
                             console.log("Not empty. Updating")
                         }
 
@@ -4030,6 +4032,10 @@
 
         //Similar function to getObjectFromLocation but using grid coordinate instead of pixel coordinate
         function getObjectFromGridLocation(gx, gy){
+            if (desktopGrids[gx] == undefined){
+                //X overflow
+                return false;
+            }
             var pos = JSON.parse(JSON.stringify(desktopGrids[gx][gy]));
             pos[0] = pos[0] + iconOffsetXY[0];
             pos[1] = pos[1] + iconOffsetXY[1];
@@ -4372,12 +4378,11 @@
                                             if (data.error !== undefined){
                                                 console.log(data.error);
                                             }
+                                           
                                         }
                                     });
                                 });
-                                setTimeout(function(){
-                                    refresh(undefined, true);
-                                }, 500);
+                                refresh(undefined, true);
                             }
                         }
                     });

+ 2 - 0
web/script/ao_module.js

@@ -72,12 +72,14 @@ document.addEventListener("DOMContentLoaded", function() {
             }
         }
     }
+    /*
      //Load html2canvas
      if ($){
         $.getScript(ao_root + "script/html2canvas.min.js", function() {
             console.log("Html2canvas loaded")
         });
     }
+    */
 });
 
 /*