mirror of
https://github.com/zeldaret/tmc
synced 2026-08-09 02:48:23 -04:00
Use single yaml file instead of multiple csv files
This commit is contained in:
@@ -141,13 +141,13 @@ TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*))
|
||||
TOOLBASE = $(TOOLDIRS:tools/%=%)
|
||||
TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE))
|
||||
|
||||
.PHONY: all setup clean-tools mostlyclean clean tidy $(TOOLDIRS)
|
||||
.PHONY: all setup clean-tools mostlyclean clean tidy $(TOOLDIRS) extractassets
|
||||
|
||||
MAKEFLAGS += --no-print-directory
|
||||
|
||||
AUTO_GEN_TARGETS :=
|
||||
|
||||
all: $(ROM)
|
||||
all: extractassets $(ROM)
|
||||
@$(SHA1) $(BUILD_NAME).sha1
|
||||
|
||||
# kept for backwards compat
|
||||
@@ -156,6 +156,9 @@ compare: $(ROM)
|
||||
|
||||
setup: $(TOOLDIRS)
|
||||
|
||||
extractassets:
|
||||
python tools/asset_extractor/asset_extractor.py $(GAME_VERSION)
|
||||
|
||||
$(TOOLDIRS):
|
||||
@$(MAKE) -C $@
|
||||
|
||||
|
||||
@@ -2,12 +2,9 @@ from pathlib import Path
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import parser
|
||||
import yaml
|
||||
|
||||
# Allow to parse expressions instead of just hex numbers to be able to quickly adapt offsets for different versions
|
||||
def parse_hex(text):
|
||||
code = parser.expr(text).compile()
|
||||
return eval(code)
|
||||
verbose = False
|
||||
|
||||
def extract_assets(variant):
|
||||
print(f'Extract assets from {variant}.')
|
||||
@@ -17,26 +14,57 @@ def extract_assets(variant):
|
||||
'JP': 'baserom_jp.gba',
|
||||
'DEMO': 'baserom_demo.gba'
|
||||
}
|
||||
|
||||
if not os.path.exists(map[variant]):
|
||||
print(f'Error: Baserom {map[variant]} is missing.', file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
baserom = None
|
||||
with open(map[variant], 'rb') as file:
|
||||
baserom = bytearray(file.read())
|
||||
|
||||
with open(f'assets_{variant}.csv', 'r') as file:
|
||||
for line in file:
|
||||
(path,start,size,mode) = line.split(',')
|
||||
mode = mode.strip()
|
||||
start = parse_hex(start)
|
||||
size = parse_hex(size)
|
||||
with open('assets.yaml') as file:
|
||||
current_offset = 0
|
||||
assets = yaml.safe_load(file)
|
||||
for asset in assets:
|
||||
if 'offsets' in asset: # Offset definition
|
||||
if variant in asset['offsets']:
|
||||
current_offset = asset['offsets'][variant]
|
||||
elif 'path' in asset: # Asset definition
|
||||
|
||||
if 'variants' in asset:
|
||||
if variant not in asset['variants']:
|
||||
# This asset is not used in the current variant
|
||||
continue
|
||||
|
||||
path = asset['path']
|
||||
if os.path.isfile(path):
|
||||
if verbose:
|
||||
print(f'{path} already extracted.')
|
||||
else:
|
||||
print(f'Extracting {path}...')
|
||||
|
||||
start = 0
|
||||
if 'start' in asset:
|
||||
# Apply offset to the start of the USA variant
|
||||
start = asset['start'] + current_offset
|
||||
elif 'starts' in asset:
|
||||
# Use start for the current variant
|
||||
start = asset['starts'][variant]
|
||||
|
||||
size = asset['size'] # TODO can different sizes for the different variants ever occur?
|
||||
|
||||
mode = ''
|
||||
if 'type' in asset:
|
||||
mode = asset['type']
|
||||
|
||||
|
||||
Path(os.path.dirname(path)).mkdir(parents=True, exist_ok=True)
|
||||
with open(path, 'wb') as output:
|
||||
output.write(baserom[start:start+size])
|
||||
if mode == 'tileset':
|
||||
extract_tileset(path)
|
||||
|
||||
if os.path.isfile(path):
|
||||
print(f'{path} already extracted.')
|
||||
else:
|
||||
print(f'Extracting {path}...')
|
||||
Path(os.path.dirname(path)).mkdir(parents=True, exist_ok=True)
|
||||
with open(path, 'wb') as output:
|
||||
output.write(baserom[start:start+size])
|
||||
if mode == 'tileset':
|
||||
extract_tileset(path)
|
||||
|
||||
|
||||
def run_gbagfx(path_in: str, path_out:str, options: list[str]) -> None:
|
||||
@@ -45,7 +73,6 @@ def run_gbagfx(path_in: str, path_out:str, options: list[str]) -> None:
|
||||
def extract_tileset(path):
|
||||
assert(path.endswith('.4bpp.lz'))
|
||||
base = path[0:-8]
|
||||
print(base)
|
||||
subprocess.call(['cp', path, path+'.bkp'])
|
||||
run_gbagfx(path, base+'.4bpp', []) # decompress
|
||||
run_gbagfx(base+'.4bpp', base+'.png', ['-mwidth', '32']) # convert to png
|
||||
|
||||
Reference in New Issue
Block a user