mirror of
https://github.com/pmret/papermario.git
synced 2024-11-08 12:02:30 +01:00
generate image header
This commit is contained in:
parent
119d7f1264
commit
8b3db7109a
12
configure.py
12
configure.py
@ -120,7 +120,7 @@ def build_image(f: str, segment):
|
||||
if segment.flip_vertical:
|
||||
flags += "--flip-y"
|
||||
|
||||
n.build(out, "img", path + ".png", implicit="tools/convert_image.py", variables={
|
||||
n.build(out, "img", path + ".png", implicit="tools/img/build.py", variables={
|
||||
"img_type": img_type,
|
||||
"img_flags": flags,
|
||||
})
|
||||
@ -261,8 +261,11 @@ async def main():
|
||||
|
||||
# $img_type, $img_flags
|
||||
n.rule("img",
|
||||
command="$python tools/convert_image.py $img_type $in $out $img_flags",
|
||||
command="$python tools/img/build.py $img_type $in $out $img_flags",
|
||||
description="image $in")
|
||||
n.rule("img_header",
|
||||
command="$python tools/img/header.py $in $out",
|
||||
description="image_header $in")
|
||||
n.newline()
|
||||
|
||||
# $sprite_id, $sprite_dir, $sprite_name
|
||||
@ -426,11 +429,14 @@ async def main():
|
||||
if isinstance(segment, dict):
|
||||
# image within a code section
|
||||
out = "$builddir/" + f + ".bin"
|
||||
n.build(out, "img", re.sub(r"\.pal\.png", ".png", f), implicit="tools/convert_image.py", variables={
|
||||
n.build(out, "img", re.sub(r"\.pal\.png", ".png", f), implicit="tools/img/build.py", variables={
|
||||
"img_type": segment["subtype"],
|
||||
"img_flags": "",
|
||||
})
|
||||
|
||||
if ".pal.png" not in f:
|
||||
n.build(add_generated_header(f + ".h"), "img_header", f, implicit="tools/img/header.py")
|
||||
|
||||
n.build("$builddir/" + f + ".o", "bin", out)
|
||||
else:
|
||||
build_image(f, segment)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "coconut.h"
|
||||
#include "battle/item/coconut/coconut.png.h"
|
||||
|
||||
/// 32x32 square.
|
||||
Vtx N(coconutModel)[] = {
|
||||
@ -20,10 +21,10 @@ Gfx N(coconutDL)[] = {
|
||||
gsDPSetTextureConvert(G_TC_FILT),
|
||||
gsDPSetTextureLUT(G_TT_RGBA16),
|
||||
gsDPLoadTLUT_pal16(0, &battle_item_coconut_coconut_pal_png),
|
||||
gsDPLoadTextureTile_4b(&battle_item_coconut_coconut_png, G_IM_FMT_CI, 32, 0, 0, 0, 31, 31, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD),
|
||||
gsDPLoadTextureTile_4b(&battle_item_coconut_coconut_png, G_IM_FMT_CI, battle_item_coconut_coconut_png_width, battle_item_coconut_coconut_png_height, 0, 0, battle_item_coconut_coconut_png_width - 1, battle_item_coconut_coconut_png_height - 1, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD),
|
||||
gsSPClearGeometryMode(G_LIGHTING),
|
||||
gsSPClearGeometryMode(G_SHADING_SMOOTH),
|
||||
gsSPVertex(&N(coconutModel), 4, 0),
|
||||
gsSPVertex(&N(coconutModel), ARRAY_COUNT(N(coconutModel)), 0),
|
||||
gsSP1Triangle(0, 1, 2, 0),
|
||||
gsSP1Triangle(0, 2, 3, 0),
|
||||
gsDPPipeSync(),
|
||||
|
@ -188,7 +188,7 @@ class Converter():
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(argv) < 4:
|
||||
print("usage: convert_image.py MODE INFILE OUTFILE [--flip-y]")
|
||||
print("usage: build.py MODE INFILE OUTFILE [--flip-y]")
|
||||
exit(1)
|
||||
|
||||
Converter(*argv[1:]).convert()
|
28
tools/img/header.py
Executable file
28
tools/img/header.py
Executable file
@ -0,0 +1,28 @@
|
||||
#! /usr/bin/python3
|
||||
|
||||
from sys import argv
|
||||
import re
|
||||
import png
|
||||
|
||||
if __name__ == "__main__":
|
||||
infile, outfile = argv[1:]
|
||||
|
||||
img = png.Reader(infile)
|
||||
width, height, rows, info = img.read()
|
||||
|
||||
cname = re.sub(r"[^0-9a-zA-Z_]", "_", infile)
|
||||
|
||||
if cname.startswith("src_"):
|
||||
cname = cname[4:]
|
||||
elif cname.startswith("assets_"):
|
||||
cname = cname[7:]
|
||||
|
||||
with open(outfile, "w") as f:
|
||||
f.write("// Generated file, do not edit.\n")
|
||||
f.write(f"#ifndef _{cname.upper()}_\n")
|
||||
f.write(f"#define _{cname.upper()}_\n")
|
||||
f.write(f"\n")
|
||||
f.write(f"#define {cname}_width {width}\n")
|
||||
f.write(f"#define {cname}_height {height}\n")
|
||||
f.write(f"\n")
|
||||
f.write(f"#endif\n")
|
0
tools/msg/parse_compile.py
Normal file → Executable file
0
tools/msg/parse_compile.py
Normal file → Executable file
Loading…
Reference in New Issue
Block a user