Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Add from_folder so users can convert generic folder full of pngs to RSI #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions rsi/rsi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import math
from os import listdir
from os.path import isfile, join
from pathlib import Path
from typing import Dict, Tuple, Union, cast, TextIO, Any, List, Type, Optional
from PIL import Image
Expand Down Expand Up @@ -192,3 +194,23 @@ def from_dmi(cls, path: Union[str, Path]) -> "Rsi":
rsstate.icons[x].append(dmstate.getFrame(direction.to_byond(), y))

return rsi

@classmethod
def from_folder(cls, path: Union[str, Path]) -> "Rsi":

if isinstance(path, Path):
path = str(path)

pngFiles = [f for f in listdir(path) if isfile(join(path, f))]

if pngFiles.count == 0:
raise IOError("Empty folder passed to from_folder().")

firstPng = Image.open(Path(pngFiles[0])) # Is there a better way to figure out the size? Ask the user?
rsi = Rsi((firstPng.width, firstPng.height))

for pngFile in pngFiles:
image = Image.open(Path(pngFile))
rsi.new_state(1, image.name) # it would be nice to create animations based on a filename pattern like thing_1.png, thing_2.png etc

return rsi