Legend of the Gold Box... A game written for the LOWREZJAM 2018 game jam
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

53 lines
1.3KB

  1. import os
  2. import pygame
  3. class LoadError(Exception):
  4. pass
  5. def calculate_real_path(path):
  6. path = os.path.expandvars(os.path.expanduser(path))
  7. path = os.path.realpath(path)
  8. path = os.path.abspath(path)
  9. return os.path.normcase(os.path.normpath(path))
  10. def join_path(lpath, rpath):
  11. return os.path.normcase(os.path.normpath(os.path.join(lpath, rpath)))
  12. def load_image(filename):
  13. if not os.path.isfile(filename):
  14. raise LoadError("Failed to load '{}'. Path missing or invalid.".format(filename))
  15. with open(filename) as f:
  16. try:
  17. i = pygame.image.load(f, filename)
  18. return i.convert_alpha()
  19. except pygame.error as e:
  20. raise LoadError("Pygame/SDL Exception: {}".format(e.message))
  21. def load_audio(filename):
  22. if not os.path.isfile(filename):
  23. raise LoadError("Failed to load '{}'. Path missing or invalid.".format(filename))
  24. try:
  25. return pygame.mixer.Sound(filename)
  26. except pygame.error as e:
  27. raise LoadError("Pygame Exception: {}".format(e.message))
  28. def load_JSON(filename):
  29. if not os.path.isfile(filename):
  30. raise LoaderError("File '{}' is missing or not a file.".format(filename))
  31. data = None
  32. try:
  33. with open(filename) as f:
  34. data = json.load(f)
  35. return data
  36. except Exception as e:
  37. raise e