29 lines
953 B
Python
29 lines
953 B
Python
|
import json
|
||
|
import sys
|
||
|
|
||
|
from sprite.Spritesheet import Spritesheet
|
||
|
|
||
|
sys.path.append('./sprite')
|
||
|
|
||
|
|
||
|
# This class is used to load named sprite sheets from the img folder.
|
||
|
class SpritesheetManager:
|
||
|
def __init__(self, sprites_dir, config_file):
|
||
|
self.sprites_dir = sprites_dir
|
||
|
self.spritesheets = {}
|
||
|
self.load_from_config(config_file)
|
||
|
|
||
|
def load_from_config(self, config_file):
|
||
|
print("Loading sprites from sprite sheet config file", config_file)
|
||
|
config = json.load(open(config_file))
|
||
|
|
||
|
for sprite_data in config:
|
||
|
sprite_sheet = Spritesheet(self.sprites_dir, sprite_data)
|
||
|
self.spritesheets[sprite_sheet.sprite_id] = sprite_sheet
|
||
|
print("Loaded", len(self.spritesheets), "sprite sheet(s)")
|
||
|
|
||
|
def get_sheet(self, sheet):
|
||
|
if sheet not in self.spritesheets:
|
||
|
raise ValueError("Invalid/Missing sprite sheet " + sheet)
|
||
|
return self.spritesheets[sheet]
|