-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.py
41 lines (30 loc) · 1.17 KB
/
block.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
class BlockManager:
def __init__(self):
self.registeredBlocks = {}
def registerBlock(self, name, imageFile, onLeftClick, onRightClick, data):
self.registeredBlocks[name] = BlockDefinition(name, imageFile, onLeftClick, onRightClick, data)
def getDefinition(self, name):
if name in self.registeredBlocks:
return self.registeredBlocks[name]
else:
raise StandardError("Block %s has not been registered." % name)
def place(self, name, pos):
definition = self.getDefinition(name)
block = definition.createBlock(pos)
return block
class BlockDefinition:
def __init__(self, name, imageFile, onLeftClick, onRightClick, data):
self.name = name
self.imageFile = imageFile
self.onLeftClick = onLeftClick
self.onRightClick = onRightClick
self.data = data
self.blockList = {}
def createBlock(self, pos):
block = Block(self.name, pos)
self.blockList[pos] = block
return block
class Block:
def __init__(self, name, pos):
self.name = name
self.pos = pos