diff --git a/.gitignore b/.gitignore index 89c1c49..6d90556 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist/ .mypy_cache files.txt +.vscode diff --git a/rsi/direction.py b/rsi/direction.py new file mode 100644 index 0000000..5ed3ed8 --- /dev/null +++ b/rsi/direction.py @@ -0,0 +1,20 @@ +from enum import Enum + + +class Direction(Enum): + SOUTH = 0 + NORTH = 1 + EAST = 2 + WEST = 3 + + def to_byond(self) -> int: + if self == Direction.NORTH: + return 1 + elif self == Direction.SOUTH: + return 2 + elif self == Direction.EAST: + return 4 + elif self == Direction.WEST: + return 8 + else: + raise ValueError() diff --git a/rsi/rsi.py b/rsi/rsi.py index 5e8585b..6f0a963 100644 --- a/rsi/rsi.py +++ b/rsi/rsi.py @@ -3,8 +3,9 @@ from pathlib import Path from typing import Dict, Tuple, Union, cast, TextIO, Any, List, TypeVar, Type from PIL import Image -from .state import State +from .direction import Direction from .helpers import state_name +from .state import State T = TypeVar("T") RSI_LATEST_COMPATIBLE = 1 @@ -94,6 +95,7 @@ def write(self, path: Union[str, Path]) -> None: image.paste(icon, box=point) count += 1 + # break pngpath = path.joinpath(state.full_name + ".png") # type: Path image.save(pngpath, "PNG") @@ -163,19 +165,27 @@ def from_dmi(cls: Type[T], path: Union[str, Path]) -> "Rsi": rsi = Rsi((dmi.icon_width, dmi.icon_height)) for dmstate in dmi.states.values(): + if dmstate.dirs == 8: + continue + rsstate = rsi.new_state(dmstate.dirs, dmstate.name) # type: State # BYOND does not permit direction specific delays so this is easy. for x in range(rsstate.directions): + direction = Direction(x) rsstate.delays[x] = [] - # Circumvent around a BYOND bug (?) - # where states have more delays than actual frames. for y in range(dmstate.frames): + print(y, dmstate.frames, dmstate.delay) + # Circumvent around a BYOND bug (?) + # where states have more delays than actual frames. + if dmstate.frames <= y: + break + if dmstate.frames != 1: delay = float(dmstate.delay[y]) - rsstate.delays[x].append(delay) - - rsstate.icons[x] = dmstate.icons[x * - dmstate.frames:(x + 1) * dmstate.frames] + else: + delay = 1.0 + rsstate.delays[x].append(delay) + rsstate.icons[x].append(dmstate.getFrame(direction.to_byond(), y)) return rsi