Quellcode durchsuchen

Parameters can now be sent to the associated loader using a param dictionary. Loaders should now accept a second argument that will contain a parameter dictionary. Added a font resource loader

master
Bryan Miller vor 6 Jahren
Ursprung
Commit
9cf058c1df
2 geänderte Dateien mit 17 neuen und 5 gelöschten Zeilen
  1. +2
    -2
      game/gbe/resource.py
  2. +15
    -3
      game/gbe/resourceLoaders.py

+ 2
- 2
game/gbe/resource.py Datei anzeigen

@@ -109,7 +109,7 @@ class ResourceManager:
d["instance"] = None
return self

def get(self, rtype, src):
def get(self, rtype, src, params={}):
global _RESOURCES
if rtype not in _RESOURCES:
raise ResourceError("Unknown resource type '{}'.".format(rtype))
@@ -120,7 +120,7 @@ class ResourceManager:
loader = _RESOURCES[rtype]["loader"]
filename = join_path(_RESOURCES[rtype]["path"], src)
try:
d["instance"] = loader(filename)
d["instance"] = loader(filename, params)
except Exception as e:
_l.error(e.message)
return None

+ 15
- 3
game/gbe/resourceLoaders.py Datei anzeigen

@@ -18,7 +18,7 @@ def file_exists(path):



def load_image(filename):
def load_image(filename, params={}):
if not os.path.isfile(filename):
raise LoadError("Failed to load '{}'. Path missing or invalid.".format(filename))
with open(filename) as f:
@@ -29,7 +29,7 @@ def load_image(filename):
raise LoadError("Pygame/SDL Exception: {}".format(e.message))


def load_audio(filename):
def load_audio(filename, params={}):
if not os.path.isfile(filename):
raise LoadError("Failed to load '{}'. Path missing or invalid.".format(filename))
try:
@@ -37,9 +37,21 @@ def load_audio(filename):
except pygame.error as e:
raise LoadError("Pygame Exception: {}".format(e.message))

def load_font(filename, params={}):
if not os.path.isfile(filename):
raise LoadError("Failed to load '{}'. Path missing or invalid.".format(filename))
try:
if pygame.font.get_init():
size = 26
if "size" in params:
if isinstance(params["size"], int) and params["size"] > 0:
size = params["size"]
return pygame.font.Font(filename, size)
except pygame.error as e:
raise LoadError("Pygame Exception: {}".format(e.message))


def load_JSON(filename):
def load_JSON(filename, params={}):
if not os.path.isfile(filename):
raise LoaderError("File '{}' is missing or not a file.".format(filename))
data = None

Laden…
Abbrechen
Speichern