Przeglądaj źródła

ResourceManager can now test is a resource is 'valid'.

master
Bryan Miller 6 lat temu
rodzic
commit
05a9db02c4
2 zmienionych plików z 9 dodań i 2 usunięć
  1. +7
    -1
      game/gbe/resource.py
  2. +2
    -1
      game/gbe/resourceLoaders.py

+ 7
- 1
game/gbe/resource.py Wyświetl plik

@@ -76,6 +76,12 @@ class ResourceManager:
return r
return None

def is_valid(self, rtype, src):
global _RESOURCES
if rtype in _RESOURCES:
return file_exists(join_path(_RESOURCES[rtype]["path"], src))
return false

def has(self, rtype, src):
return (self._getResourceDict(rtype, src) is not None)

@@ -112,7 +118,7 @@ class ResourceManager:
raise ResourceError("No '{}' resource '{}' stored.".format(rtype, src))
if d["instance"] is None:
loader = _RESOURCES[rtype]["loader"]
filename = join_path(self.data_path, src)
filename = join_path(_RESOURCES[rtype]["path"], src)
try:
d["instance"] = loader(filename)
except Exception as e:

+ 2
- 1
game/gbe/resourceLoaders.py Wyświetl plik

@@ -13,7 +13,8 @@ def calculate_real_path(path):
def join_path(lpath, rpath):
return os.path.normcase(os.path.normpath(os.path.join(lpath, rpath)))


def file_exists(path):
return os.path.isfile(path)




Ładowanie…
Anuluj
Zapisz