-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.py
86 lines (65 loc) · 2.54 KB
/
pack.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
'''
Author: Kyle Charters
Description:
The pack module contains all pack related items
Contents:
- Pack
- listPacks()
Notes:
None
'''
import file
import utility
class Pack(object):
def __init__(self, name):
'''
Description
A pack contains all world related textures
Parameters:
name: The name of the pack
Notes:
Loads packs from folders inside the "pack" folder
'''
self.name = name
#Create empty arrays
self.wall = []
self.wallsplit = []
self.sprite = [[], [], [], []]
self.spritesplit = [[], [], [], []]
self.spriteoffset = [[], [], [], []]
directory = "packs/" + name + "/"
if file.exists(directory):
data = file.loadJson(directory + "pack.def")
for texture in data['wall']:
image = file.loadImage(directory + texture)
self.wall.append(image)
self.wallsplit.append(utility.splitSurface(image))
for texture in data['sprite']:
image = file.loadImage(directory + texture[1], (0, 0, 0))
self.sprite[texture[0]].append(image)
self.spritesplit[texture[0]].append(utility.splitSurface(image, (0, 0, 0), True))
self.spriteoffset[texture[0]].append(texture[2])
self.unknown = file.loadImage("core/tex/unknown.png")
self.unknownsplit = utility.splitSurface(self.unknown)
def getWall(self, index):
if 0 < index <= len(self.wall):
return self.wall[index - 1]
return self.unknown
def getWallSplit(self, index):
if 0 < index <= len(self.wallsplit):
return self.wallsplit[index - 1]
return self.unknownsplit
def getSprite(self, variation, index):
if 0 < index <= len(self.sprite[variation]):
return self.sprite[variation][index - 1]
return self.unknown
def getSpriteSplit(self, variation, index):
if 0 < index <= len(self.spritesplit[variation]):
return self.spritesplit[variation][index - 1]
return self.unknownsplit
def getSpriteOffset(self, variation, index):
if 0 < index <= len(self.spriteoffset[variation]):
return self.spriteoffset[variation][index - 1]
return 0
def listPacks():
return list(map(lambda name: name.capitalize(), file.listFolders("packs/")))