Archipelago/dumpSprites.py

36 lines
1.2 KiB
Python
Raw Normal View History

2020-12-04 22:56:21 +00:00
from Gui import *
import threading
# Target directories
2020-12-04 22:56:21 +00:00
input_dir = local_path("data", "sprites", "alttpr")
output_dir = local_path("WebHostLib", "static", "static")
2021-03-13 00:56:31 +00:00
os.makedirs(os.path.join(output_dir, "sprites"), exist_ok=True)
# update sprites through gui.py's functions
2020-12-04 22:56:21 +00:00
done = threading.Event()
top = Tk()
top.withdraw()
BackgroundTaskProgress(top, update_sprites, "Updating Sprites", lambda succesful, resultmessage: done.set())
while not done.isSet():
top.update()
print("Done updating sprites")
spriteData = []
2020-12-04 22:56:21 +00:00
for file in os.listdir(input_dir):
sprite = Sprite(os.path.join(input_dir, file))
2020-12-04 22:56:21 +00:00
if not sprite.name:
2021-03-13 00:56:31 +00:00
print("Warning:", file, "has no name.")
2020-12-04 22:56:21 +00:00
sprite.name = file.split(".", 1)[0]
if sprite.valid:
2021-03-13 00:56:31 +00:00
with open(os.path.join(output_dir, "sprites", f"{os.path.splitext(file)[0]}.gif"), 'wb') as image:
2020-12-04 22:56:21 +00:00
image.write(get_image_for_sprite(sprite, True))
spriteData.append({"file": file, "author": sprite.author_name, "name": sprite.name})
2020-12-04 22:56:21 +00:00
else:
print(file, "dropped, as it has no valid sprite data.")
spriteData.sort(key=lambda entry: entry["name"])
2020-12-04 22:56:21 +00:00
with open(f'{output_dir}/spriteData.json', 'w') as file:
2020-12-06 16:12:41 +00:00
json.dump({"sprites": spriteData}, file, indent=1)