summaryrefslogtreecommitdiff
path: root/src/tileset.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/tileset.py')
-rw-r--r--src/tileset.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/tileset.py b/src/tileset.py
new file mode 100644
index 0000000..7fa8733
--- /dev/null
+++ b/src/tileset.py
@@ -0,0 +1,89 @@
+from common import *
+
+class KPObjectDefinition(object):
+ def __init__(self):
+ self.rows = []
+
+ def render(self, size):
+ buf = []
+
+ beforeRepeat = []
+ inRepeat = []
+ afterRepeat = []
+
+ foundRepeat = False
+ for row in self.rows:
+ if (row[0][0] & 2) != 0:
+ inRepeat.append(row)
+ foundRepeat = True
+ else:
+ if foundRepeat:
+ afterRepeat.append(row)
+ else:
+ beforeRepeat.append(row)
+
+ bC, iC, aC = len(beforeRepeat), len(inRepeat), len(afterRepeat)
+
+ if iC == 0:
+ for y in xrange(size[1]):
+ buf.append(self._renderRow(beforeRepeat[y % bC], size[0]))
+ else:
+ middleUntil = size[1] - aC
+
+ for y in xrange(size[1]):
+ if y < bC:
+ buf.append(self._renderRow(beforeRepeat[y], size[0]))
+ elif y < middleUntil:
+ buf.append(self._renderRow(inRepeat[(y - bC) % iC], size[0]))
+ else:
+ buf.append(self._renderRow(afterRepeat[y - bC - iC], size[0]))
+
+ return buf
+
+ def _renderRow(self, row, width):
+ buf = [-1 for i in xrange(width)]
+
+ beforeRepeat = []
+ inRepeat = []
+ afterRepeat = []
+
+ foundRepeat = False
+ for tile in row:
+ if (tile[0] & 1) != 0:
+ inRepeat.append(tile[1])
+ foundRepeat = True
+ else:
+ if foundRepeat:
+ afterRepeat.append(tile[1])
+ else:
+ beforeRepeat.append(tile[1])
+
+ bC, iC, aC = len(beforeRepeat), len(inRepeat), len(afterRepeat)
+
+ if iC == 0:
+ for x in xrange(width):
+ buf[x] = beforeRepeat[x % bC]
+ else:
+ middleUntil = width - aC
+
+ for x in xrange(width):
+ if x < bC:
+ buf[x] = beforeRepeat[y]
+ elif x < middleUntil:
+ buf[x] = inRepeat[(y - bC) % iC]
+ else:
+ buf[x] = afterRepeat[y - bC - iC]
+
+ return buf
+
+
+
+
+
+
+class KPTileset(object):
+ def __init__(self):
+ self.texture = None
+ self.objects = []
+
+