Skip to content

Commit

Permalink
fix BPL palette animation (#559)
Browse files Browse the repository at this point in the history
* fix BPL palette animation

* bump skytemple-rust
  • Loading branch information
theCapypara authored Dec 23, 2024
1 parent 928af38 commit 51d5442
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"Pillow >= 6.1.0",
"appdirs >= 1.4.0",
"explorerscript >= 0.2.2, < 0.3.0",
"skytemple-rust >= 1.8.4, < 1.9.0",
"skytemple-rust >= 1.8.5, < 1.9.0",
'pyobjc==10.3.2; sys_platform == "darwin"',
"dungeon-eos==0.0.5",
]
Expand Down
13 changes: 11 additions & 2 deletions skytemple_files/graphics/bpl/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with SkyTemple. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations

import logging

from range_typed_integers import u16_checked, u16

Expand All @@ -30,6 +31,8 @@
)
from skytemple_files.graphics.bpl.protocol import BplAnimationSpecProtocol, BplProtocol

logger = logging.getLogger(__name__)


class BplAnimationSpec(BplAnimationSpecProtocol):
def __init__(self, duration_per_frame: u16, number_of_frames: u16) -> None:
Expand Down Expand Up @@ -138,10 +141,16 @@ def apply_palette_animations(self, frame: int) -> list[list[int]]:
"""
# TODO: First frame is missing: No change!
f_palettes = []
already_used_colors = 0
for i, spec in enumerate(self.animation_specs):
if spec.number_of_frames > 0:
actual_frame_for_pal = frame % spec.number_of_frames
pal_for_frame = self.animation_palette[actual_frame_for_pal]
actual_frame_for_pal = already_used_colors + (frame % spec.number_of_frames)
already_used_colors += spec.number_of_frames
if actual_frame_for_pal >= len(self.animation_palette):
logger.warning("palette animation frame out of bounds, using black")
pal_for_frame = [0] * 3 * 15
else:
pal_for_frame = self.animation_palette[actual_frame_for_pal]
f_palettes.append([0, 0, 0] + pal_for_frame)
else:
f_palettes.append(self.palettes[i])
Expand Down

0 comments on commit 51d5442

Please sign in to comment.