-
Notifications
You must be signed in to change notification settings - Fork 25
/
misc.py
757 lines (594 loc) · 24.8 KB
/
misc.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Miyamoto! Level Editor - New Super Mario Bros. U Level Editor
# Copyright (C) 2009-2021 Treeki, Tempus, angelsl, JasonP27, Kinnay,
# MalStar1000, RoadrunnerWMC, MrRean, Grop, AboodXD, Gota7, John10v10,
# mrbengtsson
# This file is part of Miyamoto!.
# Miyamoto! is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Miyamoto! is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Miyamoto!. If not, see <http://www.gnu.org/licenses/>.
################################################################
################################################################
############ Imports ############
from PyQt5 import QtCore, QtGui, QtWidgets
Qt = QtCore.Qt
if not hasattr(QtWidgets.QGraphicsItem, 'ItemSendsGeometryChanges'):
# enables itemChange being called on QGraphicsItem
QtWidgets.QGraphicsItem.ItemSendsGeometryChanges = QtWidgets.QGraphicsItem.GraphicsItemFlag(0x800)
import globals
#################################
class LevelScene(QtWidgets.QGraphicsScene):
"""
GraphicsScene subclass for the level scene
"""
def __init__(self, *args):
super().__init__(*args)
self.setBackgroundBrush(QtGui.QBrush(globals.theme.color('bg')))
def drawForeground(self, painter, rect):
"""
Draw a foreground grid (only called when taking a screenshot)
"""
drawForegroundGrid(painter, rect)
def drawBackground(self, painter, rect):
"""
Draws all visible tiles
"""
super().drawBackground(painter, rect)
if not hasattr(globals.Area, 'layers'):
return
drawrect = QtCore.QRectF(rect.x() / globals.TileWidth, rect.y() / globals.TileWidth, rect.width() / globals.TileWidth + 1,
rect.height() / globals.TileWidth + 1)
isect = drawrect.intersects
layer0 = []
layer1 = []
layer2 = []
x1 = 1024
y1 = 512
x2 = 0
y2 = 0
# iterate through each object
funcs = [layer0.append, layer1.append, layer2.append]
show = [globals.Layer0Shown, globals.Layer1Shown, globals.Layer2Shown]
for layer, add, process in zip(globals.Area.layers, funcs, show):
if not process: continue
for item in layer:
if not isect(item.LevelRect): continue
add(item)
xs = item.objx
xe = xs + item.width
ys = item.objy
ye = ys + item.height
if xs < x1: x1 = xs
if xe > x2: x2 = xe
if ys < y1: y1 = ys
if ye > y2: y2 = ye
width = x2 - x1
height = y2 - y1
objectDefinitions = globals.ObjectDefinitions
tiles = globals.Tiles
offset = 0x800
items = {1: 26, 2: 27, 3: 16, 4: 17, 5: 18, 6: 19,
7: 20, 8: 21, 9: 22, 10: 25, 11: 23, 12: 24,
14: 32, 15: 33, 16: 34, 17: 35, 18: 42, 19: 36,
20: 37, 21: 38, 22: 41, 23: 39, 24: 40}
# create and draw the tilemaps
for idx, layer in (2, layer2), (1, layer1), (0, layer0):
if not layer:
continue
tmap = [[None] * width for _ in range(height)]
for item in layer:
startx = item.objx - x1
desty = item.objy - y1
exists = True
try:
if objectDefinitions[item.tileset] is None:
exists = False
elif objectDefinitions[item.tileset][item.type] is None:
exists = False
except IndexError:
exists = False
for row in item.objdata:
destrow = tmap[desty]
destx = startx
for tile in row:
# If this object has data, make sure to override it properly
if tile > 0:
if item.data in items:
destrow[destx] = offset + items[item.data]
else:
destrow[destx] = tile
elif not exists:
destrow[destx] = -1
destx += 1
desty += 1
painter.save()
painter.translate(x1 * globals.TileWidth, y1 * globals.TileWidth)
drawPixmap = painter.drawPixmap
desty = 0
for row in tmap:
destx = 0
for tile in row:
pix = None
if tile == -1:
# Draw unknown tiles
pix = tiles[0x800].getCurrentTile()
elif tile is not None:
pix = tiles[tile].getCurrentTile(idx == 1)
if pix is not None:
drawPixmap(destx, desty, pix)
destx += globals.TileWidth
desty += globals.TileWidth
painter.restore()
class HexSpinBox(QtWidgets.QSpinBox):
class HexValidator(QtGui.QValidator):
def __init__(self, min, max):
super().__init__()
self.valid = set('0123456789abcdef')
self.min = min
self.max = max
def validate(self, input, pos):
try:
input = str(input).lower()
except Exception:
return (self.Invalid, input, pos)
valid = self.valid
for char in input:
if char not in valid:
return (self.Invalid, input, pos)
try:
value = int(input, 16)
except ValueError:
# If value == '' it raises ValueError
return (self.Invalid, input, pos)
if value < self.min or value > self.max:
return (self.Intermediate, input, pos)
return (self.Acceptable, input, pos)
def __init__(self, format='%04X', *args):
self.format = format
super().__init__(*args)
self.validator = self.HexValidator(self.minimum(), self.maximum())
def setMinimum(self, value):
self.validator.min = value
QtWidgets.QSpinBox.setMinimum(self, value)
def setMaximum(self, value):
self.validator.max = value
QtWidgets.QSpinBox.setMaximum(self, value)
def setRange(self, min, max):
self.validator.min = min
self.validator.max = max
QtWidgets.QSpinBox.setMinimum(self, min)
QtWidgets.QSpinBox.setMaximum(self, max)
def validate(self, text, pos):
return self.validator.validate(text, pos)
def textFromValue(self, value):
return self.format % value
def valueFromText(self, value):
return int(str(value), 16)
class SpriteDefinition:
"""
Stores and manages the data info for a specific sprite
"""
class ListPropertyModel(QtCore.QAbstractListModel):
"""
Contains all the possible values for a list property on a sprite
"""
def __init__(self, entries, existingLookup, max):
"""
Constructor
"""
super().__init__()
self.entries = entries
self.existingLookup = existingLookup
self.max = max
def rowCount(self, parent=None):
"""
Required by Qt
"""
return len(self.entries)
def data(self, index, role=Qt.DisplayRole):
"""
Get what we have for a specific row
"""
if not index.isValid():
return None
n = index.row()
if n < 0 or n >= len(self.entries):
return None
if role == Qt.DisplayRole:
return '%d: %s' % self.entries[n]
return None
def loadFrom(self, elem):
"""
Loads in all the field data from an XML node
"""
self.fields = []
fields = self.fields
for field in elem:
if field.tag not in ['checkbox', 'list', 'value', 'bitfield']: continue
attribs = field.attrib
if 'comment' in attribs:
comment = globals.trans.string('SpriteDataEditor', 1, '[name]', attribs['title'], '[note]', attribs['comment'])
else:
comment = None
if field.tag == 'checkbox':
# parameters: title, bit, mask, comment
if 'nybble' in attribs:
sbit = attribs['nybble']
sft = 2
else:
sbit = attribs['bit']
sft = 0
if not '-' in sbit:
if not sft:
# just 1 bit
bit = int(sbit)
else:
# just 4 bits
bit = (((int(sbit) - 1) << 2) + 1, (int(sbit) << 2) + 1)
else:
# different number of bits
getit = sbit.split('-')
bit = (((int(getit[0]) - 1) << sft) + 1, (int(getit[1]) << sft) + 1)
if 'mask' in attribs:
mask = int(attribs['mask'])
else:
mask = 1
fields.append((0, attribs['title'], bit, mask, comment))
elif field.tag == 'list':
# parameters: title, bit, model, comment
if 'nybble' in attribs:
sbit = attribs['nybble']
sft = 2
else:
sbit = attribs['bit']
sft = 0
if not '-' in sbit:
if not sft:
# just 1 bit
bit = int(sbit)
max = 2
else:
# just 4 bits
bit = (((int(sbit) - 1) << 2) + 1, (int(sbit) << 2) + 1)
max = 16
else:
# different number of bits
getit = sbit.split('-')
bit = (((int(getit[0]) - 1) << sft) + 1, (int(getit[1]) << sft) + 1)
max = 1 << (bit[1] - bit[0])
entries = []
existing = [None for i in range(max)]
for e in field:
if e.tag != 'entry': continue
i = int(e.attrib['value'])
entries.append((i, e.text))
existing[i] = True
fields.append(
(1, attribs['title'], bit, SpriteDefinition.ListPropertyModel(entries, existing, max), comment))
elif field.tag == 'value':
# parameters: title, bit, max, comment
if 'nybble' in attribs:
sbit = attribs['nybble']
sft = 2
else:
sbit = attribs['bit']
sft = 0
if not '-' in sbit:
if not sft:
# just 1 bit
bit = int(sbit)
max = 2
else:
# just 4 bits
bit = (((int(sbit) - 1) << 2) + 1, (int(sbit) << 2) + 1)
max = 16
else:
# different number of bits
getit = sbit.split('-')
bit = (((int(getit[0]) - 1) << sft) + 1, (int(getit[1]) << sft) + 1)
max = 1 << (bit[1] - bit[0])
fields.append((2, attribs['title'], bit, max, comment))
elif field.tag == 'bitfield':
# parameters: title, startbit, bitnum, comment
startbit = int(attribs['startbit'])
bitnum = int(attribs['bitnum'])
fields.append((3, attribs['title'], startbit, bitnum, comment))
class Metadata:
"""
Class for the new level metadata system
"""
# This new system is much more useful and flexible than the old
# system, but is incompatible with older versions of Miyamoto.
# They will fail to understand the data, and skip it like it
# doesn't exist. The new system is written with forward-compatibility
# in mind. Thus, when newer versions of Miyamoto are created
# with new metadata values, they will be easily able to add to
# the existing ones. In addition, the metadata system is lossless,
# so unrecognized values will be preserved when you open and save.
# Type values:
# 0 = binary
# 1 = string
# 2+ = undefined as of now - future Miyamotos can use them
# Theoretical limit to type values is 4,294,967,296
def __init__(self, data=None):
"""
Creates a metadata object with the data given
"""
self.DataDict = {}
if not data or data[0:4] != b'MD2_': return
# Iterate through the data
idx = 4
while idx < len(data) - 4:
# Read the next (first) four bytes - the key length
rawKeyLen = data[idx:idx + 4]
idx += 4
keyLen = (rawKeyLen[0] << 24) | (rawKeyLen[1] << 16) | (rawKeyLen[2] << 8) | rawKeyLen[3]
# Read the next (key length) bytes - the key (as a str)
rawKey = data[idx:idx + keyLen]
idx += keyLen
key = ''
for b in rawKey: key += chr(b)
# Read the next four bytes - the number of type entries
rawTypeEntries = data[idx:idx + 4]
idx += 4
typeEntries = (rawTypeEntries[0] << 24) | (rawTypeEntries[1] << 16) | (rawTypeEntries[2] << 8) | \
rawTypeEntries[3]
# Iterate through each type entry
for entry in range(typeEntries):
# Read the next four bytes - the type
rawType = data[idx:idx + 4]
idx += 4
type = (rawType[0] << 24) | (rawType[1] << 16) | (rawType[2] << 8) | rawType[3]
# Read the next four bytes - the data length
rawDataLen = data[idx:idx + 4]
idx += 4
dataLen = (rawDataLen[0] << 24) | (rawDataLen[1] << 16) | (rawDataLen[2] << 8) | rawDataLen[3]
# Read the next (data length) bytes - the data (as bytes)
entryData = data[idx:idx + dataLen]
idx += dataLen
# Add it to typeData
self.setOtherData(key, type, entryData)
def binData(self, key):
"""
Returns the binary data associated with key
"""
return self.otherData(key, 0)
def strData(self, key):
"""
Returns the string data associated with key
"""
data = self.otherData(key, 1)
if data is None: return
s = ''
for d in data: s += chr(d)
return s
def otherData(self, key, type):
"""
Returns unknown data, with the given type value, associated with key (as binary data)
"""
if key not in self.DataDict: return
if type not in self.DataDict[key]: return
return self.DataDict[key][type]
def setBinData(self, key, value):
"""
Sets binary data, overwriting any existing binary data with that key
"""
self.setOtherData(key, 0, value)
def setStrData(self, key, value):
"""
Sets string data, overwriting any existing string data with that key
"""
data = []
for char in value: data.append(ord(char))
self.setOtherData(key, 1, data)
def setOtherData(self, key, type, value):
"""
Sets other (binary) data, overwriting any existing data with that key and type
"""
if key not in self.DataDict: self.DataDict[key] = {}
self.DataDict[key][type] = value
def save(self):
"""
Returns a bytes object that can later be loaded from
"""
# Sort self.DataDict
dataDictSorted = []
for dataKey in self.DataDict: dataDictSorted.append((dataKey, self.DataDict[dataKey]))
dataDictSorted.sort(key=lambda entry: entry[0])
data = []
# Add 'MD2_'
data.append(ord('M'))
data.append(ord('D'))
data.append(ord('2'))
data.append(ord('_'))
# Iterate through self.DataDict
for dataKey, types in dataDictSorted:
# Add the key length (4 bytes)
keyLen = len(dataKey)
data.append(keyLen >> 24)
data.append((keyLen >> 16) & 0xFF)
data.append((keyLen >> 8) & 0xFF)
data.append(keyLen & 0xFF)
# Add the key (key length bytes)
for char in dataKey: data.append(ord(char))
# Sort the types
typesSorted = []
for type in types: typesSorted.append((type, types[type]))
typesSorted.sort(key=lambda entry: entry[0])
# Add the number of types (4 bytes)
typeNum = len(typesSorted)
data.append(typeNum >> 24)
data.append((typeNum >> 16) & 0xFF)
data.append((typeNum >> 8) & 0xFF)
data.append(typeNum & 0xFF)
# Iterate through typesSorted
for type, typeData in typesSorted:
# Add the type (4 bytes)
data.append(type >> 24)
data.append((type >> 16) & 0xFF)
data.append((type >> 8) & 0xFF)
data.append(type & 0xFF)
# Add the data length (4 bytes)
dataLen = len(typeData)
data.append(dataLen >> 24)
data.append((dataLen >> 16) & 0xFF)
data.append((dataLen >> 8) & 0xFF)
data.append(dataLen & 0xFF)
# Add the data (data length bytes)
for d in typeData: data.append(d)
if bytes(data) == b'MD2_':
return[]
return data
class BGName:
def __init__(self, name, trans):
self.name = name
self.trans = trans
def __eq__(self, other):
return other in (self.name, self.trans)
@staticmethod
def index(name):
try:
return globals.names_bg.index(name)
except ValueError:
return len(globals.names_bg) - 1
@staticmethod
def getNameForTrans(trans):
return globals.names_bg[BGName.index(trans)].name
@staticmethod
def getTransAll():
return [bg.trans for bg in globals.names_bg]
class Custom:
def __init__(self):
self.name = ''
self.trans = 'Custom filename...'
def __eq__(self, other):
return False
def clipStr(text, idealWidth, font=None):
"""
Returns a shortened string, or None if it need not be shortened
"""
if font is None: font = QtGui.QFont()
width = QtGui.QFontMetrics(font).width(text)
if width <= idealWidth: return None
while width > idealWidth:
text = text[:-1]
width = QtGui.QFontMetrics(font).width(text)
return text
def setting(name, default=None):
"""
Thin wrapper around QSettings, fixes the type=bool bug
"""
types_str = {str: 'str', int: 'int', float: 'float', dict: 'dict', bool: 'bool', QtCore.QByteArray: 'QByteArray', type(None): 'NoneType'}
types = {'str': str, 'int': int, 'float': float, 'dict': dict, 'bool': bool, 'QByteArray': QtCore.QByteArray}
type_ = globals.settings.value('typeof(%s)' % name, types_str[type(default)], str)
if type_ == 'NoneType':
return None
return globals.settings.value(name, default, types[type_])
def setSetting(name, value):
"""
Thin wrapper around QSettings
"""
types_str = {str: 'str', int: 'int', float: 'float', dict: 'dict', bool: 'bool', QtCore.QByteArray: 'QByteArray', type(None): 'NoneType'}
assert isinstance(name, str) and type(value) in types_str
globals.settings.setValue(name, value)
globals.settings.setValue('typeof(%s)' % name, types_str[type(value)])
def SetGamePath(newpath):
"""
Sets the NSMBU game path
"""
# you know what's fun?
# isValidGamePath crashes in os.path.join if QString is used..
# so we must change it to a Python string manually
globals.gamedef.SetGamePath(str(newpath))
def drawForegroundGrid(painter, rect):
"""
Draws a foreground grid
"""
if globals.GridType is None:
return
Zoom = globals.mainWindow.ZoomLevel
drawLine = lambda x1, y1, x2, y2: painter.drawLine(round(x1), round(y1), round(x2), round(y2))
GridColor = globals.theme.color('grid')
if globals.GridType == 'grid': # draw a classic grid
startx = rect.x()
startx -= (startx % globals.TileWidth)
endx = startx + rect.width() + globals.TileWidth
starty = rect.y()
starty -= (starty % globals.TileWidth)
endy = starty + rect.height() + globals.TileWidth
x = startx - globals.TileWidth
while x <= endx:
x += globals.TileWidth
if x % (globals.TileWidth * 8) == 0:
painter.setPen(QtGui.QPen(GridColor, 2 * globals.TileWidth / 24, Qt.DashLine))
drawLine(x, starty, x, endy)
elif x % (globals.TileWidth * 4) == 0:
if Zoom < 25: continue
painter.setPen(QtGui.QPen(GridColor, 1 * globals.TileWidth / 24, Qt.DashLine))
drawLine(x, starty, x, endy)
else:
if Zoom < 50: continue
painter.setPen(QtGui.QPen(GridColor, 1 * globals.TileWidth / 24, Qt.DotLine))
drawLine(x, starty, x, endy)
y = starty - globals.TileWidth
while y <= endy:
y += globals.TileWidth
if y % (globals.TileWidth * 8) == 0:
painter.setPen(QtGui.QPen(GridColor, 2 * globals.TileWidth / 24, Qt.DashLine))
drawLine(startx, y, endx, y)
elif y % (globals.TileWidth * 4) == 0 and Zoom >= 25:
painter.setPen(QtGui.QPen(GridColor, 1 * globals.TileWidth / 24, Qt.DashLine))
drawLine(startx, y, endx, y)
elif Zoom >= 50:
painter.setPen(QtGui.QPen(GridColor, 1 * globals.TileWidth / 24, Qt.DotLine))
drawLine(startx, y, endx, y)
else: # draw a checkerboard
L = 0.2
D = 0.1 # Change these values to change the checkerboard opacity
Light = QtGui.QColor(GridColor)
Dark = QtGui.QColor(GridColor)
Light.setAlpha(min(round(Light.alpha() * L), 255))
Dark.setAlpha(min(round(Dark.alpha() * D), 255))
size = globals.TileWidth if Zoom >= 50 else globals.TileWidth * 8
board = QtGui.QPixmap(8 * size, 8 * size)
board.fill(QtGui.QColor(0, 0, 0, 0))
p = QtGui.QPainter(board)
p.setPen(Qt.NoPen)
p.setBrush(QtGui.QBrush(Light))
for x, y in ((0, size), (size, 0)):
p.drawRect(x + (4 * size), y, size, size)
p.drawRect(x + (4 * size), y + (2 * size), size, size)
p.drawRect(x + (6 * size), y, size, size)
p.drawRect(x + (6 * size), y + (2 * size), size, size)
p.drawRect(x, y + (4 * size), size, size)
p.drawRect(x, y + (6 * size), size, size)
p.drawRect(x + (2 * size), y + (4 * size), size, size)
p.drawRect(x + (2 * size), y + (6 * size), size, size)
p.setBrush(QtGui.QBrush(Dark))
for x, y in ((0, 0), (size, size)):
p.drawRect(x, y, size, size)
p.drawRect(x, y + (2 * size), size, size)
p.drawRect(x + (2 * size), y, size, size)
p.drawRect(x + (2 * size), y + (2 * size), size, size)
p.drawRect(x, y + (4 * size), size, size)
p.drawRect(x, y + (6 * size), size, size)
p.drawRect(x + (2 * size), y + (4 * size), size, size)
p.drawRect(x + (2 * size), y + (6 * size), size, size)
p.drawRect(x + (4 * size), y, size, size)
p.drawRect(x + (4 * size), y + (2 * size), size, size)
p.drawRect(x + (6 * size), y, size, size)
p.drawRect(x + (6 * size), y + (2 * size), size, size)
p.drawRect(x + (4 * size), y + (4 * size), size, size)
p.drawRect(x + (4 * size), y + (6 * size), size, size)
p.drawRect(x + (6 * size), y + (4 * size), size, size)
p.drawRect(x + (6 * size), y + (6 * size), size, size)
del p
painter.drawTiledPixmap(rect, board, QtCore.QPointF(rect.x(), rect.y()))