Skip to content

Commit

Permalink
make use-all the default behavior when running compose.py (I-am-Erk#2138
Browse files Browse the repository at this point in the history
)

* make use_all the default behavior

* re-add --use-all command to prevent legacy script issues
  • Loading branch information
smileynet authored Oct 23, 2023
1 parent 835933b commit 414f526
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions tools/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Examples:
%(prog)s ../CDDA-Tilesets/gfx/Retrodays/
%(prog)s --use-all ../CDDA-Tilesets/gfx/UltimateCataclysm/
%(prog)s --no-use-all ../CDDA-Tilesets/gfx/UltimateCataclysm/
By default, output is written back to the source directory. Pass an output
directory as the last argument to place output files there instead. The
Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(
self,
source_dir: Path,
output_dir: Path,
use_all: bool = False,
no_use_all: bool = False,
obsolete_fillers: bool = False,
palette_copies: bool = False,
palette: bool = False,
Expand All @@ -234,7 +234,7 @@ def __init__(
) -> None:
self.source_dir = source_dir
self.output_dir = output_dir
self.use_all = use_all
self.no_use_all = no_use_all
self.obsolete_fillers = obsolete_fillers
self.palette_copies = palette_copies
self.palette = palette
Expand Down Expand Up @@ -370,7 +370,7 @@ def create_tile_entries_for_unused(
unused: list,
fillers: bool,
) -> None:
# the list must be empty without use_all
# the list must be on no_use_all
mode = unused if no_tqdm or run_silent else tqdm(unused)
for unused_png in mode:
if unused_png in self.processed_ids:
Expand Down Expand Up @@ -494,21 +494,23 @@ def handle_unreferenced_sprites(
'''
Either warn about unused sprites or return the list
'''
if self.use_all:
return self.unreferenced_pngnames[sheet_type]

for pngname in self.unreferenced_pngnames[sheet_type]:
if pngname in self.processed_ids:
log.error(
'%(1)s.png not used when %(1)s ID '
'is mentioned in a tile entry',
{'1': pngname})
if self.no_use_all:
for pngname in self.unreferenced_pngnames[sheet_type]:
if pngname in self.processed_ids:
log.error(
'%(1)s.png not used when %(1)s ID '
'is mentioned in a tile entry',
{'1': pngname})

else:
log.warning(
'sprite filename %s was not used in any %s %s entries',
pngname, sheet_type, self.output_conf_file)
return []

return self.unreferenced_pngnames[sheet_type]

else:
log.warning(
'sprite filename %s was not used in any %s %s entries',
pngname, sheet_type, self.output_conf_file)
return []


class Tilesheet:
Expand Down Expand Up @@ -923,8 +925,11 @@ def main() -> Union[int, ComposingException]:
'output_dir', nargs='?', type=Path,
help='Output directory path')
arg_parser.add_argument(
'--use-all', dest='use_all', action='store_true',
'--no-use-all', dest='no_use_all', action='store_true',
help='Add unused images with id being their basename')
arg_parser.add_argument(
'--use-all', dest='use_all', action='store_true',
help='Legacy argument for script compatability, enabled by default')
arg_parser.add_argument(
'--obsolete-fillers', dest='obsolete_fillers', action='store_true',
help='Warn about obsoleted fillers')
Expand Down Expand Up @@ -991,7 +996,7 @@ def main() -> Union[int, ComposingException]:
args_dict.get('output_dir') or
args_dict.get('source_dir')
),
use_all=args_dict.get('use_all', False),
no_use_all=args_dict.get('no_use_all', False),
obsolete_fillers=args_dict.get('obsolete_fillers', False),
palette_copies=args_dict.get('palette_copies', False),
palette=args_dict.get('palette', False),
Expand Down

0 comments on commit 414f526

Please sign in to comment.