diff --git a/.gitignore b/.gitignore index 604231b..89c1c49 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build/ dist/ .mypy_cache +files.txt diff --git a/rsi/__main__.py b/rsi/__main__.py new file mode 100644 index 0000000..ce13fdd --- /dev/null +++ b/rsi/__main__.py @@ -0,0 +1,29 @@ +import argparse +from pathlib import Path +from rsi import Rsi + + +def main() -> int: + """ + Entry point for the command line rsi utility script. + """ + parser = argparse.ArgumentParser() + subparser = parser.add_subparsers(dest="command") + + _from_dmi = subparser.add_parser("from_dmi", help="Will create an RSI from a BYOND DMI file.") + _from_dmi.add_argument("input", help="The DMI file to read from.", type=Path) + _from_dmi.add_argument("output", help="The RSI to output to.", type=Path) + + args = parser.parse_args() + + if args.command == "from_dmi": + from_dmi(args.input, args.output) + return 0 + + print("No command specified!") + return 1 + + +def from_dmi(inputf: Path, output: Path) -> None: + rsi = Rsi.from_dmi(inputf) + rsi.write(output) diff --git a/rsi/rsi.py b/rsi/rsi.py index 1cbb46b..5e8585b 100644 --- a/rsi/rsi.py +++ b/rsi/rsi.py @@ -147,12 +147,15 @@ def open(cls: Type[T], path: Union[str, Path]) -> "Rsi": return rsi @classmethod - def from_dmi(cls: Type[T], path: str) -> "Rsi": + def from_dmi(cls: Type[T], path: Union[str, Path]) -> "Rsi": try: from byond.DMI import DMI except ImportError: raise ImportError("Unable to import byondtoolsv3.") + if isinstance(path, Path): + path = str(path) + # N3X15, if you are reading this: # You are awful at API design. dmi = DMI(path) diff --git a/scripts/RSI.py b/scripts/RSI.py new file mode 100755 index 0000000..2b13ef3 --- /dev/null +++ b/scripts/RSI.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import argparse +from pathlib import Path +from rsi import Rsi + + +def main() -> None: + parser = argparse.ArgumentParser() + subparser = parser.add_subparsers(dest="command") + + _from_dmi = subparser.add_parser("from_dmi", help="Will create an RSI from a BYOND DMI file.") + _from_dmi.add_argument("input", help="The DMI file to read from.", type=Path) + _from_dmi.add_argument("output", help="The RSI to output to.", type=Path) + + args = parser.parse_args() + + if args.command == "from_dmi": + from_dmi(args.input, args.output) + return + + print("No command specified!") + + +def from_dmi(inputf: Path, output: Path) -> None: + rsi = Rsi.from_dmi(inputf) + rsi.write(output) + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index b3e7fe6..6bb5960 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3`` from setuptools import setup setup( @@ -21,5 +22,6 @@ "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Python Modules" - ] + ], + entry_points={'console_scripts': ['rsi=rsi.__main__:main']}, ) diff --git a/spec/RSI.md b/spec/RSI.md index e395aad..af1e307 100644 --- a/spec/RSI.md +++ b/spec/RSI.md @@ -57,7 +57,7 @@ The PNG file accompanying a state is always the name of the state, with all sele The file contains the individual states resolved with the directions and delays of the state. The size of the file is always a multiple of the RSI's `size`. Sprites are ordered from the top left to the bottom right, always going horizontally first. The amount of sprites per row or column is always made to be as equal as possible, favoring rows to be longer than columns if the amount of states is not able to be divided perfectly. -Sprites are written per direction, then writing each icon in a direction in order, so with 4 directions, ALL south states get written first, then north states, etc... +Sprites are written grouped by direction, then writing each icon in a direction in order, so with 4 directions, ALL south states get written first, then north states, etc... ### Example JSON