-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextureBank.py
69 lines (53 loc) · 1.66 KB
/
TextureBank.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
'''
==============================================================================
Texture Bank class for loading multiple textures
(C++ version)
3/11/2014
SDLTutorials.com
Tim Jones
(Python3 version)
22/03/2016
www.inf.ufsm.br/~rtrindade
Rafael Gauna Trindade
==============================================================================
'''
from Texture import Texture
from FileManager import FileManager
from pygame import display
from Log import Log
class TextureBank:
TexList = {}
#=========================================================================
def Init(self):
self.Cleanup()
# Relative to CWD
Files = FileManager().GetFilesInFolder("Textures")
Display = display.get_surface()
for Filename in Files:
Ext = FileManager().GetFilenameExt(Filename)
ID = FileManager().GetFilenameWithoutExt(Filename)
# Skip all non-png files
if Ext != "png":
continue
self.AddTexture(Display, ID, Filename)
return True
#-------------------------------------------------------------------------
def Cleanup(self):
if len(self.TexList) <= 0:
return
self.TexList.clear()
#=========================================================================
def AddTexture(self, Display, ID, Filename):
if ID == "":
return
NewTexture = Texture()
if not NewTexture.Load(Display, Filename):
Log("Unable to Load Texture:",ID)
return
self.TexList[ID] = NewTexture
#-------------------------------------------------------------------------
def Get(self, ID):
return self.TexList.get(ID)
#=========================================================================
def GetInstance(self):
return self