vxSDK/vxsdk/cli/conv/asset.py

109 lines
3.7 KiB
Python

"""
Vhex asset converter user interface
"""
import os
from core.logger import log
from core.conv import assets_generate
__all__ = [
'conv_asset_cli_parse'
]
__HELP__ = r"""vxsdk-converter-asset
Convert all assets file in the project directory.
USAGE:
vxsdk conv-asset [project path] [OPTIONS]
DESCRIPTION:
Convert all assets file in the asset directory. This part of the converter
module will scan the provided folder (or the current working directory) and
will try to find all `vxconv.txt` file, which describe all assets that
should be converted.
If no argument is provided, then the current working directory is used as
asset prefix and a storag for all generated source file. You can modify this
behaviour using OPTIONS.
The vxconv.txt file is structured like basic key/value file:
```
<exposed_symbols_name>:
type: <image type> (font, bitmap) - required
path: <image path> - required
...
<next_exposed_symbols_name>:
...
```
Each asset file description should have at least type and name information,
and each type have potentially its own requierements.
type = bitmap:
================================== =========================================
Keys name and value type Description
================================== =========================================
profile: <name> Select the bitmap pixel profile
| rgb4 | RGB 4 (indexed)
| rgb4a | RGBA 4 (indexed)
| rgb8 | RGB 8 (indexed)
| rgb8a | RGBA 8 (indexed)
| rgb16 | RGB 16 (5:R, 6:G, 5:B)
| rgb16a | RGBA 16 (5:R, 5:G, 5:B, 1:A)
================================== =========================================
type = font:
================================== =========================================
Keys name and value type Description
================================== =========================================
grid_size: 8x9 (widthxheight) caracter size in pixel
grid_padding: <pixel> space between caracter
grig_border: <pixel> space around grid
proportional: <true,false> caracter are cropped
line_height: <pixel> caracter line alignement
charset: <default,unicode> charset specification
char_spacing <pixel> space between character
================================== =========================================
OPTIONS:
-o <output prefix> The prefix for source file that will be generated
-h, --help Display this help
"""
def conv_asset_cli_parse(argv):
"""Process CLI arguments"""
# check obvious flags
if '-h' in argv or '--help' in argv:
log.user(__HELP__)
return 0
# fetch user indication
manual_output = False
prefix_output = None
prefix_asset = None
for arg in argv:
if arg == '-o':
manual_output = True
continue
if manual_output:
prefix_output = arg
continue
if prefix_asset:
log.warn(f"warning: previous path ({prefix_asset}) dropped")
prefix_asset = arg
# check indication
if not prefix_asset:
prefix_asset = os.getcwd()
if not prefix_output:
prefix_output = os.getcwd()
prefix_asset = os.path.abspath(prefix_asset)
prefix_output = os.path.abspath(prefix_output)
# generate asset information
return assets_generate(prefix_asset, prefix_output)