From 4bc7c8cde1d7d068739f452f5413fc00179ceefb Mon Sep 17 00:00:00 2001 From: Danila Date: Tue, 20 Aug 2024 17:34:19 +0300 Subject: [PATCH] refactor(rendering): movie clip rendering is disabled by default now --- system/lib/config.py | 2 ++ system/lib/features/cut_sprites.py | 46 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/system/lib/config.py b/system/lib/config.py index 33fbf6b..eefee68 100644 --- a/system/lib/config.py +++ b/system/lib/config.py @@ -16,6 +16,7 @@ def __init__(self): "has_update", "last_update", "auto_update", + "should_render_movie_clips", ) self.initialized: bool = False @@ -24,6 +25,7 @@ def __init__(self): self.has_update: bool = False self.last_update: int = -1 self.auto_update: bool = False + self.should_render_movie_clips: bool = False self.load() diff --git a/system/lib/features/cut_sprites.py b/system/lib/features/cut_sprites.py index d18fc20..82829e4 100644 --- a/system/lib/features/cut_sprites.py +++ b/system/lib/features/cut_sprites.py @@ -1,6 +1,7 @@ import os from pathlib import Path +from system.lib.config import config from system.lib.console import Console from system.lib.matrices import Matrix2x3 from system.lib.objects.renderable.renderable_factory import ( @@ -53,25 +54,26 @@ def render_objects(swf: SupercellSWF, output_folder: Path): rendered_region = region.get_image() rendered_region.save(f"{output_folder}/shape_{shape.id}_{region_index}.png") - movie_clips_skipped = 0 - movie_clip_count = len(swf.movie_clips) - for movie_clip_index in range(movie_clip_count): - movie_clip = swf.movie_clips[movie_clip_index] - - rendered_movie_clip = create_renderable_from_plain(swf, movie_clip).render( - Matrix2x3() - ) - if sum(rendered_movie_clip.size) >= 2: - clip_name = movie_clip.export_name or movie_clip.id - rendered_movie_clip.save(f"{output_folder}/movie_clips/{clip_name}.png") - else: - # For debug: - # logger.warning(f'MovieClip {movie_clip.id} cannot be rendered.') - movie_clips_skipped += 1 - - Console.progress_bar( - "Rendering movie clips (%d/%d). Skipped count: %d" - % (movie_clip_index + 1, movie_clip_count, movie_clips_skipped), - movie_clip_index, - movie_clip_count, - ) + if config.should_render_movie_clips: + movie_clips_skipped = 0 + movie_clip_count = len(swf.movie_clips) + for movie_clip_index in range(movie_clip_count): + movie_clip = swf.movie_clips[movie_clip_index] + + rendered_movie_clip = create_renderable_from_plain(swf, movie_clip).render( + Matrix2x3() + ) + if sum(rendered_movie_clip.size) >= 2: + clip_name = movie_clip.export_name or movie_clip.id + rendered_movie_clip.save(f"{output_folder}/movie_clips/{clip_name}.png") + else: + # For debug: + # logger.warning(f'MovieClip {movie_clip.id} cannot be rendered.') + movie_clips_skipped += 1 + + Console.progress_bar( + "Rendering movie clips (%d/%d). Skipped count: %d" + % (movie_clip_index + 1, movie_clip_count, movie_clips_skipped), + movie_clip_index, + movie_clip_count, + )