mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2025-05-31 16:05:11 +02:00
fxconv: add custom conversions
Custom conversions can be used by: * Providing a converters.py in the main directory with a convert() function * Specifying --custom on the fxconv command-line or using a subfolder or assets-{fx,cg} unused by standard fxconv
This commit is contained in:
parent
e3af6a5d4b
commit
ee9c459c69
3 changed files with 33 additions and 4 deletions
|
@ -46,6 +46,12 @@ def err(msg):
|
||||||
def warn(msg):
|
def warn(msg):
|
||||||
print("\x1b[33;1mwarning:\x1b[0m", msg, file=sys.stderr)
|
print("\x1b[33;1mwarning:\x1b[0m", msg, file=sys.stderr)
|
||||||
|
|
||||||
|
# "converters" module from the user project
|
||||||
|
try:
|
||||||
|
import converters
|
||||||
|
except ImportError:
|
||||||
|
converters = None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Default execution mode is to run a Python script for conversion
|
# Default execution mode is to run a Python script for conversion
|
||||||
modes = "script binary image font bopti-image libimg-image"
|
modes = "script binary image font bopti-image libimg-image"
|
||||||
|
@ -53,6 +59,7 @@ def main():
|
||||||
output = None
|
output = None
|
||||||
model = None
|
model = None
|
||||||
target = { 'toolchain': None, 'arch': None, 'section': None }
|
target = { 'toolchain': None, 'arch': None, 'section': None }
|
||||||
|
use_custom = False
|
||||||
|
|
||||||
# Parse command-line arguments
|
# Parse command-line arguments
|
||||||
|
|
||||||
|
@ -61,8 +68,8 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "hsbifo:",
|
longs = "help output= fx cg toolchain= arch= section= custom " + modes
|
||||||
("help output= fx cg toolchain= arch= section= "+modes).split())
|
opts, args = getopt.gnu_getopt(sys.argv[1:], "hsbifo:", longs.split())
|
||||||
except getopt.GetoptError as error:
|
except getopt.GetoptError as error:
|
||||||
err(error)
|
err(error)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -85,6 +92,9 @@ def main():
|
||||||
target['arch'] = value
|
target['arch'] = value
|
||||||
elif name == "--section":
|
elif name == "--section":
|
||||||
target['section'] = value
|
target['section'] = value
|
||||||
|
elif name == "--custom":
|
||||||
|
use_custom = True
|
||||||
|
mode = "custom"
|
||||||
# Other names are modes
|
# Other names are modes
|
||||||
else:
|
else:
|
||||||
mode = name[1] if len(name)==2 else name[2:]
|
mode = name[1] if len(name)==2 else name[2:]
|
||||||
|
@ -148,8 +158,16 @@ def main():
|
||||||
warn("type 'image' is deprecated, use 'bopti-image' instead")
|
warn("type 'image' is deprecated, use 'bopti-image' instead")
|
||||||
params["type"] = "bopti-image"
|
params["type"] = "bopti-image"
|
||||||
|
|
||||||
|
# Use the custom module
|
||||||
|
custom = None
|
||||||
|
if use_custom:
|
||||||
|
if converters is None:
|
||||||
|
err("--custom specified but no [converters] module in wd")
|
||||||
|
sys.exit(1)
|
||||||
|
custom = converters.convert
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fxconv.convert(input, params, target, output, model)
|
fxconv.convert(input, params, target, output, model, custom)
|
||||||
except fxconv.FxconvError as e:
|
except fxconv.FxconvError as e:
|
||||||
err(e)
|
err(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -928,7 +928,7 @@ def r5g6b5(img, color_count=0, alpha=None):
|
||||||
|
|
||||||
return encoded, encoded_palette, alpha
|
return encoded, encoded_palette, alpha
|
||||||
|
|
||||||
def convert(input, params, target, output=None, model=None):
|
def convert(input, params, target, output=None, model=None, custom=None):
|
||||||
"""
|
"""
|
||||||
Convert a data file into an object that exports the following symbols:
|
Convert a data file into an object that exports the following symbols:
|
||||||
* _<varname>
|
* _<varname>
|
||||||
|
@ -942,6 +942,7 @@ def convert(input, params, target, output=None, model=None):
|
||||||
target -- String dictionary keys 'toolchain', 'arch' and 'section'
|
target -- String dictionary keys 'toolchain', 'arch' and 'section'
|
||||||
output -- Output file name [default: <input> with suffix '.o']
|
output -- Output file name [default: <input> with suffix '.o']
|
||||||
model -- 'fx' or 'cg' (some conversions require this) [default: None]
|
model -- 'fx' or 'cg' (some conversions require this) [default: None]
|
||||||
|
custom -- Custom conversion function
|
||||||
|
|
||||||
Produces an output file and returns nothing.
|
Produces an output file and returns nothing.
|
||||||
"""
|
"""
|
||||||
|
@ -969,6 +970,8 @@ def convert(input, params, target, output=None, model=None):
|
||||||
convert_libimg_fx(input, output, params, target)
|
convert_libimg_fx(input, output, params, target)
|
||||||
elif params["type"] == "libimg-image" and model == "cg":
|
elif params["type"] == "libimg-image" and model == "cg":
|
||||||
convert_libimg_cg(input, output, params, target)
|
convert_libimg_cg(input, output, params, target)
|
||||||
|
elif custom is not None:
|
||||||
|
custom(input, output, params, target)
|
||||||
else:
|
else:
|
||||||
raise FxconvError(f'unknown resource type \'{params["type"]}\'')
|
raise FxconvError(f'unknown resource type \'{params["type"]}\'')
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,14 @@ build-cg/assets/bin/%.o: assets-cg/bin/%
|
||||||
@ mkdir -p $(dir $@)
|
@ mkdir -p $(dir $@)
|
||||||
fxconv -b $< -o $@ $(FXCONVCG) name:bin_$(basename $*) $(BIN.$*)
|
fxconv -b $< -o $@ $(FXCONVCG) name:bin_$(basename $*) $(BIN.$*)
|
||||||
|
|
||||||
|
# Custom conversions
|
||||||
|
build-fx/assets/%.o: assets-fx/%
|
||||||
|
@ mkdir -p $(dir $@)
|
||||||
|
fxconv --custom $< -o $@ $(FXCONVFX) type:$(subst /,,$(dir $*)) name:$(subst /,_,$(basename $*))
|
||||||
|
build-cg/assets/%.o: assets-cg/%
|
||||||
|
@ mkdir -p $(dir $@)
|
||||||
|
fxconv --custom $< -o $@ $(FXCONVCG) type:$(subst /,,$(dir $*)) name:$(subst /,_,$(basename $*))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Cleaning and utilities
|
# Cleaning and utilities
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Reference in a new issue