Skip to content

Commit

Permalink
move the short array into classes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Apr 21, 2024
1 parent 0ec2df6 commit bbdbaa6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
29 changes: 28 additions & 1 deletion fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from ...utility import PluginError, decodeSegmentedAddr, is_bit_active
from ..sm64_constants import MAX_U16
from ..sm64_utility import SM64_ShortArray

from .utility import RomReading, eval_num_from_str
from .c_parser import Initialization, ParsedValue
Expand Down Expand Up @@ -652,6 +651,34 @@ def table_to_c(self, generate_enums: bool):
return text_data.getvalue()


class SM64_ShortArray:
def __init__(self, name, signed):
self.name = name
self.data = []
self.signed = signed

def to_binary(self):
data = bytearray(0)
for short in self.data:
data += short.to_bytes(2, "big", signed=True)
return data

def to_c(self):
data = StringIO()
data.write(f"static const {'s' if self.signed else 'u'}16 {self.name}[] = {{\n\t")

wrap_counter = 0
for short in self.data:
u_short = int.from_bytes(short.to_bytes(2, "big", signed=True), "big", signed=False)
data.write(f"0x{format(u_short, '04X')}, ")
wrap_counter += 1
if wrap_counter > 8:
data.write("\n\t")
wrap_counter = 0
data.write("\n};\n")
return data.getvalue()


def create_tables(anims_data: list[SM64_AnimData], values_name: str = None):
"""Can generate multiple indices table with only one value table, which improves compression"""
"""This feature is used in table exports"""
Expand Down
28 changes: 0 additions & 28 deletions fast64_internal/sm64/sm64_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,3 @@ def check_expanded(filepath: str):
raise PluginError(
f"ROM at {filepath} is too small.\nYou may be using an unexpanded ROM.\nYou can expand a ROM by opening it in SM64 Editor or ROM Manager."
)


class SM64_ShortArray:
def __init__(self, name, signed):
self.name = name
self.data = []
self.signed = signed

def to_binary(self):
data = bytearray(0)
for short in self.data:
data += short.to_bytes(2, "big", signed=True)
return data

def to_c(self):
data = StringIO()
data.write(f"static const {'s' if self.signed else 'u'}16 {self.name}[] = {{\n\t")

wrap_counter = 0
for short in self.data:
u_short = int.from_bytes(short.to_bytes(2, "big", signed=True), "big", signed=False)
data.write(f"0x{format(u_short, '04X')}, ")
wrap_counter += 1
if wrap_counter > 8:
data.write("\n\t")
wrap_counter = 0
data.write("\n};\n")
return data.getvalue()

0 comments on commit bbdbaa6

Please sign in to comment.