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

Commit

Permalink
Include RSI converter script.
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Apr 20, 2018
1 parent 1a2a05f commit 2b7891e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
dist/

.mypy_cache
files.txt
29 changes: 29 additions & 0 deletions rsi/__main__.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 4 additions & 1 deletion rsi/rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions scripts/RSI.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 3 additions & 1 deletion setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3``
from setuptools import setup

setup(
Expand All @@ -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']},
)
2 changes: 1 addition & 1 deletion spec/RSI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2b7891e

Please sign in to comment.