mirror of https://github.com/pret/pokecrystal.git
Merge pull request #138 from yenatch/master
automated png compression + gfx fixes + no more windows
This commit is contained in:
commit
fdc1609f2a
51
Makefile
51
Makefile
|
@ -11,33 +11,22 @@ TEXTFILES = \
|
|||
text/common_3.tx \
|
||||
main.tx
|
||||
|
||||
VERTGFX = \
|
||||
gfx/pics/%.png \
|
||||
gfx/trainers/%.png
|
||||
PNG_PICS = $(shell find gfx/pics/ -type f -name 'front.png')
|
||||
PNG_ANIMS = $(shell find gfx/pics/ -type f -name 'tiles.png')
|
||||
PNG_TRAINERS = gfx/trainers/*.png
|
||||
PNG_GFX = $(PNG_PICS) $(PNG_ANIMS) $(PNG_TRAINERS), $(filter-out $(shell find gfx/ -type f -name '*.png'))
|
||||
|
||||
HORIZGFX = $(filter-out gfx/%.png, $(VERTGFX))
|
||||
LZ_PICS = $(shell find gfx/pics/ -type f -name 'front.lz')
|
||||
LZ_ANIMS = $(shell find gfx/pics/ -type f -name 'tiles.lz')
|
||||
LZ_TRAINERS = gfx/trainers/*.lz
|
||||
LZ_GFX = $(filter-out $(LZ_PICS) $(LZ_ANIMS) $(LZ_TRAINERS), $(shell find gfx/ -type f -name '*.lz'))
|
||||
|
||||
|
||||
# uncomment this build target to enable png import:
|
||||
|
||||
#all: lzs
|
||||
|
||||
# the recompressed graphics may be larger than the originals,
|
||||
# so take care to reorganize accordingly
|
||||
|
||||
all: pokecrystal.gbc
|
||||
cmp baserom.gbc $<
|
||||
|
||||
win: pokecrystal.gbc
|
||||
fc baserom.gbc $<
|
||||
|
||||
clean:
|
||||
rm -f main.tx pokecrystal.o pokecrystal.gbc ${TEXTFILES}
|
||||
|
||||
winclean:
|
||||
del main.tx pokecrystal.o pokecrystal.gbc .\text\sweethoney.tx .\text\phone\bill.tx .\text\phone\elm.tx .\text\phone\mom.tx .\text\phone\trainers1.tx .\text\common.tx .\text\common_2.tx .\text\common_3.tx
|
||||
|
||||
pokecrystal.o: pokecrystal.asm constants.asm wram.asm ${TEXTFILES}
|
||||
pokecrystal.o: pokecrystal.asm constants.asm wram.asm ${TEXTFILES} lzs
|
||||
rgbasm -o pokecrystal.o pokecrystal.asm
|
||||
|
||||
.asm.tx:
|
||||
|
@ -47,19 +36,19 @@ pokecrystal.gbc: pokecrystal.o
|
|||
rgblink -o $@ $<
|
||||
rgbfix -Cjv -i BYTE -k 01 -l 0x33 -m 0x10 -p 0 -r 3 -t PM_CRYSTAL $@
|
||||
|
||||
|
||||
lzs: ${VERTGFX} ${HORIZGFX}
|
||||
|
||||
pngs:
|
||||
cd extras && python gfx.py mass-decompress && python gfx.py dump-pngs
|
||||
|
||||
lzs: $(LZ_PICS) $(LZ_ANIMS) $(LZ_TRAINERS) $(LZ_GFX)
|
||||
|
||||
front.png: tiles.png
|
||||
cd extras && python gfx.py png-to-lz --front $@ $(OBJECT_DIRECTORY)/tiles.2bpp
|
||||
tiles.png:
|
||||
cd extras && python gfx.py png-to-2bpp $@
|
||||
.png:: ${VERTGFX}
|
||||
cd extras && python gfx.py png-to-lz --vert $@
|
||||
.png:: ${HORIZGFX}
|
||||
cd extras && python gfx.py png-to-lz $@
|
||||
gfx/pics/%/front.lz: gfx/pics/%/front.png gfx/pics/%/tiles.2bpp
|
||||
python extras/gfx.py png-to-lz --front $< $(@D)/tiles.2bpp
|
||||
gfx/pics/%/tiles.2bpp:
|
||||
python extras/gfx.py png-to-2bpp $<
|
||||
gfx/pics/%/back.lz: gfx/pics/%/back.png
|
||||
python extras/gfx.py png-to-lz --vert $<
|
||||
gfx/trainers/%.lz: gfx/trainers/%.png
|
||||
python extras/gfx.py png-to-lz --vert $<
|
||||
.png.lz:
|
||||
python extras/gfx.py png-to-lz $<
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
import png
|
||||
import argparse
|
||||
from math import sqrt, floor, ceil
|
||||
|
||||
from crystal import load_rom
|
||||
|
@ -189,6 +189,7 @@ class Compressed:
|
|||
def __init__(self, image = None, mode = 'horiz', size = None):
|
||||
|
||||
assert image, 'need something to compress!'
|
||||
image = list(image)
|
||||
self.image = image
|
||||
self.pic = []
|
||||
self.animtiles = []
|
||||
|
@ -466,7 +467,7 @@ class Compressed:
|
|||
num_alts = 0
|
||||
|
||||
# make sure we don't check for alts at the end of the file
|
||||
if self.address+2 >= self.end: return False
|
||||
if self.address+3 >= self.end: return False
|
||||
|
||||
self.alts.append(self.byte)
|
||||
self.alts.append(ord(self.image[self.address+1]))
|
||||
|
@ -1503,7 +1504,7 @@ def lz_to_png_by_file(filename):
|
|||
"""
|
||||
assert filename[-3:] == ".lz"
|
||||
lz_data = open(filename, "rb").read()
|
||||
bpp = Decompressed(lz).output
|
||||
bpp = Decompressed(lz_data).output
|
||||
bpp_filename = filename.replace(".lz", ".2bpp")
|
||||
to_file(bpp_filename, bpp)
|
||||
to_png(bpp_filename)
|
||||
|
@ -1518,47 +1519,42 @@ def dump_tileset_pngs():
|
|||
lz_to_png_by_file(tileset_filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('cmd', nargs='?', metavar='cmd', type=str)
|
||||
parser.add_argument('arg1', nargs='?', metavar='arg1', type=str)
|
||||
parser.add_argument('arg2', nargs='?', metavar='arg2', type=str)
|
||||
parser.add_argument('arg3', nargs='?', metavar='arg3', type=str)
|
||||
parser.add_argument('arg4', nargs='?', metavar='arg4', type=str)
|
||||
parser.add_argument('arg5', nargs='?', metavar='arg5', type=str)
|
||||
args = parser.parse_args()
|
||||
|
||||
debug = False
|
||||
|
||||
if args.cmd == 'dump-pngs':
|
||||
if sys.argv[1] == 'dump-pngs':
|
||||
mass_to_colored_png()
|
||||
|
||||
elif args.cmd == 'png-to-lz':
|
||||
elif sys.argv[1] == 'lz-to-png':
|
||||
lz_to_png_by_file(sys.argv[2])
|
||||
|
||||
elif sys.argv[1] == 'png-to-lz':
|
||||
# python gfx.py png-to-lz [--front anim(2bpp) | --vert] [png]
|
||||
|
||||
# python gfx.py png-to-lz --front [anim(2bpp)] [png]
|
||||
if args.arg1 == '--front':
|
||||
if sys.argv[2] == '--front':
|
||||
|
||||
# front.png and tiles.png are combined before compression,
|
||||
# so we have to pass in things like anim file and pic size
|
||||
name = os.path.splitext(args.arg3)[0]
|
||||
name = os.path.splitext(sys.argv[4])[0]
|
||||
|
||||
to_2bpp(name+'.png', name+'.2bpp')
|
||||
pic = open(name+'.2bpp', 'rb').read()
|
||||
anim = open(args.arg2, 'rb').read()
|
||||
anim = open(sys.argv[3], 'rb').read()
|
||||
size = int(sqrt(len(pic)/16)) # assume square pic
|
||||
to_file(name+'.lz', Compressed(pic + anim, 'vert', size).output)
|
||||
|
||||
|
||||
# python gfx.py png-to-lz --vert [png]
|
||||
elif args.arg1 == '--vert':
|
||||
elif sys.argv[2] == '--vert':
|
||||
|
||||
# others are vertically oriented (frontpics are always vertical)
|
||||
|
||||
name = os.path.splitext(args.arg2)[0]
|
||||
name = os.path.splitext(sys.argv[3])[0]
|
||||
|
||||
to_2bpp(name+'.png', name+'.2bpp')
|
||||
pic = open(name+'.2bpp', 'rb').read()
|
||||
to_file(name+'.lz', Compressed(pic + anim, 'vert').output)
|
||||
to_file(name+'.lz', Compressed(pic, 'vert').output)
|
||||
|
||||
|
||||
# python gfx.py png-to-lz [png]
|
||||
|
@ -1566,58 +1562,57 @@ if __name__ == "__main__":
|
|||
|
||||
# standard usage
|
||||
|
||||
png_to_lz(args.arg1)
|
||||
png_to_lz(sys.argv[2])
|
||||
|
||||
elif args.cmd == 'png-to-2bpp':
|
||||
to_2bpp(args.arg1)
|
||||
elif sys.argv[1] == 'png-to-2bpp':
|
||||
to_2bpp(sys.argv[2])
|
||||
|
||||
|
||||
elif args.cmd == 'de':
|
||||
elif sys.argv[1] == 'de':
|
||||
# python gfx.py de [addr] [fileout] [mode]
|
||||
|
||||
rom = load_rom()
|
||||
|
||||
addr = int(args.arg1,16)
|
||||
fileout = args.arg2
|
||||
mode = args.arg3
|
||||
addr = int(sys.argv[2],16)
|
||||
fileout = sys.argv[3]
|
||||
mode = sys.argv[4]
|
||||
decompress_from_address(addr, fileout, mode)
|
||||
if debug: print 'decompressed to ' + args.arg2 + ' from ' + hex(int(args.arg1,16)) + '!'
|
||||
if debug: print 'decompressed to ' + sys.argv[3] + ' from ' + hex(int(sys.argv[2],16)) + '!'
|
||||
|
||||
elif args.cmd == 'lz':
|
||||
elif sys.argv[1] == 'lz':
|
||||
# python gfx.py lz [filein] [fileout] [mode]
|
||||
filein = args.arg1
|
||||
fileout = args.arg2
|
||||
mode = args.arg3
|
||||
filein = sys.argv[2]
|
||||
fileout = sys.argv[3]
|
||||
mode = sys.argv[4]
|
||||
compress_file(filein, fileout, mode)
|
||||
if debug: print 'compressed ' + filein + ' to ' + fileout + '!'
|
||||
|
||||
elif args.cmd == 'lzf':
|
||||
elif sys.argv[1] == 'lzf':
|
||||
# python gfx.py lzf [id] [fileout]
|
||||
compress_monster_frontpic(int(args.arg1), args.arg2)
|
||||
compress_monster_frontpic(int(sys.argv[2]), sys.argv[3])
|
||||
|
||||
elif args.cmd == 'un':
|
||||
elif sys.argv[1] == 'un':
|
||||
# python gfx.py un [address] [num_tiles] [filename]
|
||||
rom = load_rom()
|
||||
get_uncompressed_gfx(int(args.arg1,16), int(args.arg2), args.arg3)
|
||||
get_uncompressed_gfx(int(sys.argv[2],16), int(sys.argv[3]), sys.argv[4])
|
||||
|
||||
elif args.cmd == 'pal':
|
||||
elif sys.argv[1] == 'pal':
|
||||
# python gfx.py pal [address] [length]
|
||||
rom = load_rom()
|
||||
print grab_palettes(int(args.arg1,16), int(args.arg2))
|
||||
print grab_palettes(int(sys.argv[2],16), int(sys.argv[3]))
|
||||
|
||||
elif args.cmd == 'png':
|
||||
elif sys.argv[1] == 'png':
|
||||
|
||||
if '.2bpp' in args.arg1:
|
||||
if args.arg3 == 'greyscale':
|
||||
to_png(args.arg1, args.arg2)
|
||||
if '.2bpp' in sys.argv[2]:
|
||||
if sys.argv[4] == 'greyscale':
|
||||
to_png(sys.argv[2], sys.argv[3])
|
||||
else:
|
||||
to_png(args.arg1, args.arg2, args.arg3)
|
||||
to_png(sys.argv[2], sys.argv[3], sys.argv[4])
|
||||
|
||||
elif '.png' in args.arg1:
|
||||
to_2bpp(args.arg1, args.arg2)
|
||||
elif '.png' in sys.argv[2]:
|
||||
to_2bpp(sys.argv[2], sys.argv[3])
|
||||
|
||||
elif args.cmd == 'mass-decompress':
|
||||
elif sys.argv[1] == 'mass-decompress':
|
||||
mass_decompress()
|
||||
if debug: print 'decompressed known gfx to pokecrystal/gfx/!'
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
@set PATH=%PATH%;C:\Program Files (x86)\GnuWin32\bin\;C:\Python27\
|
||||
@make winclean && make win
|
||||
@pause
|
Loading…
Reference in New Issue