mirror of https://github.com/pmret/papermario.git
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:
|
if segment.flip_vertical:
|
||||||
flags += "--flip-y"
|
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_type": img_type,
|
||||||
"img_flags": flags,
|
"img_flags": flags,
|
||||||
})
|
})
|
||||||
|
@ -261,8 +261,11 @@ async def main():
|
||||||
|
|
||||||
# $img_type, $img_flags
|
# $img_type, $img_flags
|
||||||
n.rule("img",
|
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")
|
description="image $in")
|
||||||
|
n.rule("img_header",
|
||||||
|
command="$python tools/img/header.py $in $out",
|
||||||
|
description="image_header $in")
|
||||||
n.newline()
|
n.newline()
|
||||||
|
|
||||||
# $sprite_id, $sprite_dir, $sprite_name
|
# $sprite_id, $sprite_dir, $sprite_name
|
||||||
|
@ -426,11 +429,14 @@ async def main():
|
||||||
if isinstance(segment, dict):
|
if isinstance(segment, dict):
|
||||||
# image within a code section
|
# image within a code section
|
||||||
out = "$builddir/" + f + ".bin"
|
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_type": segment["subtype"],
|
||||||
"img_flags": "",
|
"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)
|
n.build("$builddir/" + f + ".o", "bin", out)
|
||||||
else:
|
else:
|
||||||
build_image(f, segment)
|
build_image(f, segment)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "coconut.h"
|
#include "coconut.h"
|
||||||
|
#include "battle/item/coconut/coconut.png.h"
|
||||||
|
|
||||||
/// 32x32 square.
|
/// 32x32 square.
|
||||||
Vtx N(coconutModel)[] = {
|
Vtx N(coconutModel)[] = {
|
||||||
|
@ -20,10 +21,10 @@ Gfx N(coconutDL)[] = {
|
||||||
gsDPSetTextureConvert(G_TC_FILT),
|
gsDPSetTextureConvert(G_TC_FILT),
|
||||||
gsDPSetTextureLUT(G_TT_RGBA16),
|
gsDPSetTextureLUT(G_TT_RGBA16),
|
||||||
gsDPLoadTLUT_pal16(0, &battle_item_coconut_coconut_pal_png),
|
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_LIGHTING),
|
||||||
gsSPClearGeometryMode(G_SHADING_SMOOTH),
|
gsSPClearGeometryMode(G_SHADING_SMOOTH),
|
||||||
gsSPVertex(&N(coconutModel), 4, 0),
|
gsSPVertex(&N(coconutModel), ARRAY_COUNT(N(coconutModel)), 0),
|
||||||
gsSP1Triangle(0, 1, 2, 0),
|
gsSP1Triangle(0, 1, 2, 0),
|
||||||
gsSP1Triangle(0, 2, 3, 0),
|
gsSP1Triangle(0, 2, 3, 0),
|
||||||
gsDPPipeSync(),
|
gsDPPipeSync(),
|
||||||
|
|
|
@ -188,7 +188,7 @@ class Converter():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(argv) < 4:
|
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)
|
exit(1)
|
||||||
|
|
||||||
Converter(*argv[1:]).convert()
|
Converter(*argv[1:]).convert()
|
|
@ -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")
|
Loading…
Reference in New Issue