]> git.0d.be Git - panikweb.git/commitdiff
fix vertical stacking in grid
authorFrédéric Péters <fpeters@0d.be>
Wed, 14 Aug 2013 16:13:54 +0000 (18:13 +0200)
committerFrédéric Péters <fpeters@0d.be>
Wed, 14 Aug 2013 16:13:54 +0000 (18:13 +0200)
panikweb/views.py

index 1ae7badff4f983cdf022f9162710fbe638bab0db..d1321d90835935d8299c10aee9974836efed97a4 100644 (file)
@@ -26,7 +26,9 @@ class TimeCell:
     w = 1
     h = 1
 
-    def __init__(self):
+    def __init__(self, i, j):
+        self.x = i
+        self.y = j
         self.emissions = []
 
     def add_emission(self, emission):
@@ -67,7 +69,7 @@ class Grid(TemplateView):
         for i in range(nb_lines):
             grid.append([])
             for j in range(7):
-                grid[-1].append(TimeCell())
+                grid[-1].append(TimeCell(i, j))
 
             nonstop = [x for x in nonstops if i>=x[0]*2 and i<x[1]*2][0]
             for time_cell in grid[-1]:
@@ -101,6 +103,7 @@ class Grid(TemplateView):
                         t += 1
                 except IndexError:
                     pass
+            grid[i] = [x for x in grid[i] if x is not None]
 
         for i in range(nb_lines):
             grid[i] = [x for x in grid[i] if x is not None]
@@ -109,10 +112,14 @@ class Grid(TemplateView):
                     continue
                 t = 1
                 try:
-                    while grid[i+t][j] == cell and grid[i+t][j].w == cell.w:
+                    while True:
+                        same_cell_below = [(bj, x) for bj, x in enumerate(grid[i+cell.h])
+                                           if x == cell and x.y == cell.y and x.w == cell.w]
+                        if not same_cell_below:
+                            break
+                        bj, same_cell_below = same_cell_below[0]
+                        del grid[i+cell.h][bj]
                         cell.h += 1
-                        grid[i+t][j] = None
-                        t += 1
                 except IndexError:
                     pass