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

Commit

Permalink
Fix DMI direction import with multiple delays.
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Apr 20, 2018
1 parent e83e4d0 commit 716f707
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist/

.mypy_cache
files.txt
.vscode
20 changes: 20 additions & 0 deletions rsi/direction.py
Original file line number Diff line number Diff line change
@@ -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()
24 changes: 17 additions & 7 deletions rsi/rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit 716f707

Please sign in to comment.