-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFileSearch.py
46 lines (39 loc) · 1.02 KB
/
FileSearch.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
"""
File searching tools
Non-reactive
"""
from panda3d.core import Filename
from PandaGlobals import pandaPath
def fileSearch(file, libDir = None, exts = []):
"""
Searches for given file in path
"""
f1 = Filename.expandFrom(file)
if f1.exists():
return f1
for e in exts:
f1.setExtension(e)
if f1.exists():
return f1
if libDir is not None:
f2 = Filename.expandFrom(pandaPath + "/" + libDir + "/" + file)
if f2.exists():
return f2
for e in exts:
f2.setExtension(e)
if f2.exists():
return f2
return None
def findTexture(fileName):
"""
Finds given texture file in path
"""
tFile = fileSearch(fileName, "textures", ["jpg", "png", "jpeg"])
if tFile is None:
tFile = fileSearch("default.jpg", "textures")
return loader.loadTexture(tFile)
def findSound(fileName):
"""
Finds given sound file in path
"""
return fileSearch(fileName, "sounds", ["wav", "mp3"])