Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix txa warn #1148

Closed
wants to merge 13 commits into from
Closed
1 change: 0 additions & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
- i-love-continuous-deployment # TEMP obviously
jobs:
doxygen:
runs-on: ubuntu-latest
Expand Down
19 changes: 17 additions & 2 deletions tools/build/sprite/npc_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def pack_color(r, g, b, a):
return s


def resolve_image_path(
sprite_dir: Path,
sub_dir: str,
img_name: str,
asset_stack: Tuple[Path, ...],
) -> str:
try:
img_path = get_asset_path(sprite_dir / sub_dir / img_name, asset_stack)
except FileNotFoundError:
# Allow missing subdirectory for backwards compatibility with Star Rod
img_path = get_asset_path(sprite_dir / img_name, asset_stack)
print(f"warning: please move {sprite_dir}/{img_path.name} to '{sub_dir}' subdirectory")
return str(img_path)


def from_dir(
sprite_name: str,
asset_stack: Tuple[Path, ...],
Expand Down Expand Up @@ -66,7 +81,7 @@ def from_dir(
for Palette in SpriteSheet.findall("./PaletteList/Palette"):
if asset_stack is not None and load_images:
img_name = Palette.attrib["src"]
img_path = str(get_asset_path(sprite_dir / "palettes" / img_name, asset_stack))
img_path = resolve_image_path(sprite_dir, "palettes", img_name, asset_stack)
img = png.Reader(img_path)
img.preamble(True)
palette = img.palette(alpha="force")
Expand All @@ -83,7 +98,7 @@ def from_dir(
for Raster in SpriteSheet.findall("./RasterList/Raster"):
if asset_stack is not None and load_images:
img_name = Raster.attrib["src"]
img_path = str(get_asset_path(sprite_dir / "rasters" / img_name, asset_stack))
img_path = resolve_image_path(sprite_dir, "rasters", img_name, asset_stack)
width, height, raster, info = png.Reader(img_path).read_flat()

palette_index = int(Raster.attrib["palette"], base=16)
Expand Down
13 changes: 11 additions & 2 deletions tools/splat_ext/pm_sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
sys.path.insert(0, str(Path(__file__).parent))
from sprite_common import AnimComponent, iter_in_groups, read_offset_list

sys.path.insert(0, str(Path(__file__).parent.parent))
from common import get_asset_path

# TODO move into yaml
PLAYER_PAL_TO_RASTER: Dict[str, int] = {
"8bit": 0x57C90,
Expand Down Expand Up @@ -832,11 +835,17 @@ def split(self, rom_bytes) -> None:

def get_linker_entries(self):
from splat.segtypes.linker_entry import LinkerEntry
import splat.scripts.split as split

src_paths = [options.opts.asset_path / "sprite"]

# for NPC
src_paths += [options.opts.asset_path / "sprite" / "npc" / sprite_name for sprite_name in self.npc_cfg]
# read npc.xml - we can't use self.npc_cfg because nonvanilla asset packs can change it
# for each sprite, add to src_paths
asset_stack = tuple(Path(p) for p in split.config["asset_stack"])
orderings_tree = ET.parse(get_asset_path(Path("sprite") / NPC_SPRITE_MEDADATA_XML_FILENAME, asset_stack))
for sprite_tag in orderings_tree.getroot()[0]:
name = sprite_tag.attrib["name"]
src_paths.append(options.opts.asset_path / "sprite" / "npc" / name)

return [LinkerEntry(self, src_paths, self.out_path(), self.get_linker_section(), self.get_linker_section())]

Expand Down
2 changes: 2 additions & 0 deletions tools/splat_ext/sprite_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ def from_xml(xml: ET.Element):
commands.append(0x8100 + (int(cmd.attrib[XML_ATTR_INDEX]) & 0xFF))
elif cmd.tag == "SetNotify":
commands.append(0x8200 + (int(cmd.attrib[XML_ATTR_VALUE]) & 0xFF))
elif cmd.tag == "Command": # old Star Rod compatibility
commands.append(int(cmd.attrib["val"], 16))
else:
raise ValueError(f"unknown command {cmd.tag}")
x, y, z = xml.attrib[XML_ATTR_XYZ].split(",")
Expand Down
4 changes: 2 additions & 2 deletions tools/splat_ext/tex_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,13 @@ def pack_color(r, g, b, a):
palette_count = (0x20 if fmt_str == "CI4" else 0x200) // 2
if len(palette) > palette_count:
palette = palette[:palette_count]
self.warn(f"{self.img_name} has more than {palette_count} colors, truncating")
print(f"{self.img_name} has more than {palette_count} colors, truncating")
elif len(palette) < palette_count:
palette += [(0, 0, 0, 0)] * (palette_count - len(palette))

for rgba in palette:
if rgba[3] not in (0, 0xFF):
self.warn("alpha mask mode but translucent pixels used")
print("alpha mask mode but translucent pixels used")

color = pack_color(*rgba)
out_pal += color.to_bytes(2, byteorder="big")
Expand Down
Loading