Przeglądaj źródła

Reduce over engineered bullshit

Donald Carr 8 lat temu
rodzic
commit
1bf2e44b84
2 zmienionych plików z 34 dodań i 38 usunięć
  1. 32 38
      qml/views/reel/Reel.qml
  2. 2 0
      qml/views/reel/ReelImage.qml

+ 32 - 38
qml/views/reel/Reel.qml

@@ -37,13 +37,8 @@ View {
         }
 
         function killLastImage() {
-            if(!!priorImage) {
-                priorImage.destroy()
-                globalUtil.itemCount--
-            }
-            var col = columnArray[globalSettings.columnCount - 1]
-            priorImage = col.imageArray.shift()
-            reelSettings.deathTransition && priorImage.bowOut()
+            var col = columnArray[columnArray.length - 1]
+            col.imageArray.length && (col.imageArray[0].reviewed = true)
         }
 
         NumberAnimation on t { from: 0; to: 1; duration: 1000; loops: -1 }
@@ -58,66 +53,65 @@ View {
 
             property int columnIndex: index
             property var imageArray: []
-            property var imageQueue: []
-            property bool lastColumn: columnIndex === (globalSettings.columnCount - 1)
-
-            function stackHeight(imageIndex) {
-                var height = 0
-                for(var i = 0; i < imageIndex; i++) {
-                    height += imageArray[i].height
-                }
-                return height
-            }
 
-            function receptive() {
-                return !d.initialized || imageQueue.length < d.imageBuffer
+            function receptive(image) {
+                return !d.initialized || !imageArray.length || imageArray[imageArray.length - 1].y >= (-d.velocity - image.height*d.columnRatio)
             }
 
             function addNewImage() {
                 globalUtil.itemCount++
                 addImage(pictureDelegate.createObject())
-                imageArray.push(imageQueue.pop())
             }
 
             function addImage(image) {
                 image.parent = column
-                image.y = - image.height
-                imageQueue.push(image)
+                image.y = (imageArray.length ? imageArray[imageArray.length-1].y : 0) - image.height
+                imageArray.push(image)
             }
 
             function animationStep() {
-                if (!imageArray.length || imageArray[imageArray.length - 1].y > -1) {
-                    if (imageQueue.length) {
-                        imageArray.push(imageQueue.pop())
-                    } else if (columnIndex === 0) {
-                        if (!(globalSettings.itemLimit > 0 && globalSettings.itemLimit <= globalUtil.itemCount)) {
-                            addNewImage()
-                        }
-                    }
+                if (columnIndex === 0
+                        && !(globalSettings.itemLimit > 0 && globalSettings.itemLimit <= globalUtil.itemCount)
+                        && (!imageArray.length || imageArray[imageArray.length-1].y > -d.velocity))
+                {
+                    addNewImage()
                 }
 
-                for (var i = 0; i < imageArray.length; i++) {
-                    var image = imageArray[i]
-                    var restingY = root.height - image.height - stackHeight(i)
+                if (imageArray.length) {
+                    var image = imageArray[0]
+                    var restingY = root.height - image.height
                     var prospectiveY = image.y + d.velocity
                     var nextColumn = columnArray[columnIndex+1]
 
                     if (image.y > root.height) {
                         imageArray.shift()
-                        nextColumn.addImage(image)
-                    } else if ((lastColumn || !nextColumn.receptive()) && prospectiveY >= restingY) {
+                        if (image.reviewed) {
+                            image.destroy()
+                            globalUtil.itemCount--
+                        } else {
+                            nextColumn.addImage(image)
+                        }
+                    } else if ((!nextColumn || !nextColumn.receptive(image))
+                               && prospectiveY >= restingY
+                               && !image.reviewed) {
                         image.y = restingY
-                        if (lastColumn) {
-                            deathTimer.start()
+                        if (!nextColumn) {
                             if(!d.initialized) {
                                 d.initialized = true
                                 d.velocity = reelSettings.restingVelocity
                             }
+                            deathTimer.start()
                         }
                     } else {
                         image.y = prospectiveY
                     }
                 }
+
+                for (var i = 1; i < imageArray.length; i++) {
+                   var lowerImage = imageArray[i - 1];
+                   var image = imageArray[i]
+                   image.y = lowerImage.y - image.height
+                }
             }
 
             Component.onCompleted: columnArray.push(this)
@@ -125,7 +119,7 @@ View {
             x: d.columnWidth/globalUtil.columnWidthRatio(d.columnRatio, index)
             width: {
                 var colWidth = d.columnWidth*Math.pow(d.columnRatio, index);
-                lastColumn && (globalVars.imageWidthOverride = colWidth)
+                !columnArray[columnIndex+1] && (globalVars.imageWidthOverride = colWidth)
                 return colWidth
             }
             anchors { top: parent.top; bottom: parent.bottom }

+ 2 - 0
qml/views/reel/ReelImage.qml

@@ -5,6 +5,8 @@ import "../.."
 ArtImage {
     id: root
 
+    property bool reviewed: false
+
     function bowOut() {
         deathBow.start()
     }