Extract graphics and palettes

This commit is contained in:
octorock 2021-09-11 11:01:52 +02:00
parent 6d565ed98d
commit 0ddca212c8
4 changed files with 24 additions and 5 deletions

3
.gitignore vendored
View File

@ -65,5 +65,4 @@ _Deparsed_XSubs.pm
*.py
*.sna
__pycache__
.vscode/settings.json
assets/
.vscode/settings.json

View File

@ -65,7 +65,7 @@ SONG_BUILDDIR = $(OBJ_DIR)/$(SONG_SUBDIR)
MID_BUILDDIR = $(OBJ_DIR)/$(MID_SUBDIR)
ASSET_BUILDDIR = $(OBJ_DIR)/$(ASSET_SUBDIR)
ASFLAGS := -mcpu=arm7tdmi --defsym $(GAME_VERSION)=1 --defsym REVISION=$(REVISION) --defsym $(GAME_LANGUAGE)=1 -I $(ASSET_BUILDDIR)
ASFLAGS := -mcpu=arm7tdmi --defsym $(GAME_VERSION)=1 --defsym REVISION=$(REVISION) --defsym $(GAME_LANGUAGE)=1 -I $(ASSET_SUBDIR) -I $(ASSET_BUILDDIR)
CC1 := tools/agbcc/bin/agbcc
override CFLAGS += -O2 -Wimplicit -Wparentheses -Werror -Wno-multichar

2
assets/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -42,7 +42,8 @@ def extract_assets(variant, assets_folder):
if verbose:
print(f'{path} already extracted.')
else:
print(f'Extracting {path}...')
if verbose:
print(f'Extracting {path}...')
start = 0
if 'start' in asset:
@ -64,6 +65,10 @@ def extract_assets(variant, assets_folder):
output.write(baserom[start:start+size])
if mode == 'tileset':
extract_tileset(path)
elif mode == 'palette':
extract_palette(path)
elif mode == 'graphic':
extract_graphic(path, asset['options'] if 'options' in asset else [])
@ -73,12 +78,25 @@ def run_gbagfx(path_in, path_out, options):
def extract_tileset(path):
assert(path.endswith('.4bpp.lz'))
base = path[0:-8]
subprocess.call(['cp', path, path+'.bkp'])
# subprocess.call(['cp', path, path+'.bkp'])
run_gbagfx(path, base+'.4bpp', []) # decompress
run_gbagfx(base+'.4bpp', base+'.png', ['-mwidth', '32']) # convert to png
# TODO automatically generate tileset entries from tileset_headers.s
# TODO Possible to set the correct palette? Or not, because there is a set of palettes that can be chosen and the correct palette is only defined by the metatile?
def extract_palette(path):
assert(path.endswith('.gbapal'))
base = path[0:-7]
run_gbagfx(path, base+'.pal', [])
def extract_graphic(path, options):
assert(path.endswith('.4bpp'))
base = path[0:-5]
params = []
for key in options:
params.append('-'+key)
params.append(str(options[key]))
run_gbagfx(path, base+'.png', params)
def main():
if len(sys.argv) == 1: