1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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 = []
|