summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authoremilybrooks <emilybrooksemilybrooks@gmail.com>2024-02-21 07:31:13 -0700
committerGitHub <noreply@github.com>2024-02-21 07:31:13 -0700
commita187e97a8a499437bc818356a1d62670772ab8b4 (patch)
tree95fbf4b8aa0a0276d3e914ca5d76c6c90aa3fdd6 /tools
parentc37305bb931ed27851978e394aed19ef395b2bee (diff)
Updated splat, implemented new palette system (#146)
* image_type_in_extension * new palette extension * global_id not found * updated splat * disaster * changed wording * fixed fall texture names * delete bin_to_inc_c script * forgot to rename
Diffstat (limited to 'tools')
-rw-r--r--tools/bin_inc_c.py17
-rw-r--r--tools/splat_ext/af_i4.py22
-rw-r--r--tools/splat_ext/af_i8.py22
-rw-r--r--tools/splat_ext/af_ia8.py22
-rw-r--r--tools/splat_ext/af_palette.py8
-rw-r--r--tools/splat_ext/af_palette2.py35
6 files changed, 39 insertions, 87 deletions
diff --git a/tools/bin_inc_c.py b/tools/bin_inc_c.py
deleted file mode 100644
index 9a78c30..0000000
--- a/tools/bin_inc_c.py
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/env python3
-
-from pathlib import Path
-from sys import argv
-import re
-
-if __name__ == "__main__":
- infile, outfile, cname = argv[1:]
-
- with open(outfile, "w") as f:
- f.write(f"unsigned char {cname}[] = {{ ")
-
- with open(infile, "rb") as i:
- for char in i.read():
- f.write(f"0x{char:02X}, ")
-
- f.write(f"}};\n")
diff --git a/tools/splat_ext/af_i4.py b/tools/splat_ext/af_i4.py
deleted file mode 100644
index 54bd7b1..0000000
--- a/tools/splat_ext/af_i4.py
+++ /dev/null
@@ -1,22 +0,0 @@
-from n64img.image import Image, I4
-from splat.util import log, options
-from splat.segtypes.n64.segment import N64Segment
-
-class N64SegAf_i4(N64Segment):
- def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml):
- super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml),
-
- self.width = args[0]
- self.height = args[1]
-
- def scan(self, rom_bytes: bytes):
- self.n64img: Image = I4(b"", 0, 0)
- self.n64img.width = self.width
- self.n64img.height = self.height
- self.n64img.data = rom_bytes[self.rom_start : self.rom_end]
-
- def split(self, rom_bytes: bytes):
- path = options.opts.asset_path / self.dir / f"{self.name}.i4.png"
- path.parent.mkdir(parents=True, exist_ok=True)
-
- self.n64img.write(path)
diff --git a/tools/splat_ext/af_i8.py b/tools/splat_ext/af_i8.py
deleted file mode 100644
index 9b167f7..0000000
--- a/tools/splat_ext/af_i8.py
+++ /dev/null
@@ -1,22 +0,0 @@
-from n64img.image import Image, I8
-from splat.util import log, options
-from splat.segtypes.n64.segment import N64Segment
-
-class N64SegAf_i8(N64Segment):
- def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml):
- super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml),
-
- self.width = args[0]
- self.height = args[1]
-
- def scan(self, rom_bytes: bytes):
- self.n64img: Image = I8(b"", 0, 0)
- self.n64img.width = self.width
- self.n64img.height = self.height
- self.n64img.data = rom_bytes[self.rom_start : self.rom_end]
-
- def split(self, rom_bytes: bytes):
- path = options.opts.asset_path / self.dir / f"{self.name}.i8.png"
- path.parent.mkdir(parents=True, exist_ok=True)
-
- self.n64img.write(path)
diff --git a/tools/splat_ext/af_ia8.py b/tools/splat_ext/af_ia8.py
deleted file mode 100644
index ce5ffe5..0000000
--- a/tools/splat_ext/af_ia8.py
+++ /dev/null
@@ -1,22 +0,0 @@
-from n64img.image import Image, IA8
-from splat.util import log, options
-from splat.segtypes.n64.segment import N64Segment
-
-class N64SegAf_ia8(N64Segment):
- def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml):
- super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml),
-
- self.width = args[0]
- self.height = args[1]
-
- def scan(self, rom_bytes: bytes):
- self.n64img: Image = IA8(b"", 0, 0)
- self.n64img.width = self.width
- self.n64img.height = self.height
- self.n64img.data = rom_bytes[self.rom_start : self.rom_end]
-
- def split(self, rom_bytes: bytes):
- path = options.opts.asset_path / self.dir / f"{self.name}.ia8.png"
- path.parent.mkdir(parents=True, exist_ok=True)
-
- self.n64img.write(path)
diff --git a/tools/splat_ext/af_palette.py b/tools/splat_ext/af_palette.py
index 8a36c09..974ebc4 100644
--- a/tools/splat_ext/af_palette.py
+++ b/tools/splat_ext/af_palette.py
@@ -1,11 +1,11 @@
import struct
from splat.util import options, log
-from splat.segtypes.common.codesubsegment import CommonSegCodeSubsegment
+from splat.segtypes.n64.palette import N64SegPalette
-class N64SegAf_palette(CommonSegCodeSubsegment):
+class N64SegAf_palette(N64SegPalette):
def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml):
super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml),
-
+
self.data_only = isinstance(yaml, dict) and yaml.get("data_only", False)
def scan(self, rom_bytes: bytes):
@@ -15,7 +15,7 @@ class N64SegAf_palette(CommonSegCodeSubsegment):
if not self.data_only:
lines.append(options.opts.generated_c_preamble)
lines.append("")
- lines.append(f"unsigned short {self.name}[] = {{")
+ lines.append(f"u16 {self.name}[] = {{")
for short in struct.iter_unpack(">H", data):
lines.append(f" 0x{short[0]:04X},")
diff --git a/tools/splat_ext/af_palette2.py b/tools/splat_ext/af_palette2.py
new file mode 100644
index 0000000..b029949
--- /dev/null
+++ b/tools/splat_ext/af_palette2.py
@@ -0,0 +1,35 @@
+import struct
+from splat.util import options, log
+from splat.segtypes.common.codesubsegment import CommonSegCodeSubsegment
+
+class N64SegAf_palette2(CommonSegCodeSubsegment):
+ def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml):
+ super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml),
+
+ self.data_only = isinstance(yaml, dict) and yaml.get("data_only", False)
+
+ def scan(self, rom_bytes: bytes):
+ data = rom_bytes[self.rom_start : self.rom_end]
+ lines = []
+
+ if not self.data_only:
+ lines.append(options.opts.generated_c_preamble)
+ lines.append("")
+ lines.append(f"u16 {self.name}[] = {{")
+
+ for short in struct.iter_unpack(">H", data):
+ lines.append(f" 0x{short[0]:04X},")
+
+ if not self.data_only:
+ lines.append("};")
+
+ lines.append("")
+ self.file_text = "\n".join(lines)
+
+ def split(self, rom_bytes: bytes):
+ path = options.opts.asset_path / self.dir / f"{self.name}.palette.inc.c"
+
+ if self.file_text and path:
+ path.parent.mkdir(parents=True, exist_ok=True)
+ with open(path, "w", newline="\n") as f:
+ f.write(self.file_text)