Skip to content

Commit

Permalink
refactor(main): Group render queue by template PSD to prevent unneces…
Browse files Browse the repository at this point in the history
…sary document cycling and improve batch render time
  • Loading branch information
Investigamer committed Oct 1, 2023
1 parent 840c2eb commit 403fe1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def render_all(self, files: Optional[list[str]] = None) -> None:
layouts: dict = {}
for c in cards:
layouts.setdefault(
'failed' if isinstance(c, str) else c.card_class, []
'failed' if isinstance(c, str) else temps[c.card_class]['template_path'], []
).append(c)

# Did any cards fail to find?
Expand All @@ -408,13 +408,11 @@ def render_all(self, files: Optional[list[str]] = None) -> None:
console.update()

# Render each card type as a different batch
for card_type, cards in layouts.items():
# The template we'll use for this type
template = temps[card_type].copy()
template['loaded_class'] = get_template_class(template)
for card in cards:
# Start render thread
if not self.start_render(template, card):
for _, cards in layouts.items():
for c in cards:
# Initialize the template module if needed, start a render thread
temps[c.card_class].setdefault('loaded_class', get_template_class(temps[c.card_class]))
if not self.start_render(temps[c.card_class], c):
return
# Card complete
self.reset()
Expand Down Expand Up @@ -484,7 +482,7 @@ def test_all(self, deep: bool = False) -> None:
console.update(layout)
return
# Grab the template class and start the render thread
layout.filename = osp.join(con.cwd, "src/img/test.png")
layout.filename = osp.join(con.path_img, "test.jpg")
template['loaded_class'] = get_template_class(template)
if not self.start_render(template, layout):
failures.append(card[0])
Expand Down
2 changes: 1 addition & 1 deletion src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_templates() -> dict[str, list[TemplateDetails]]:
"class_name": template['class'],
"type": con.card_type_map_raw.get(card_type, 'Normal'),
"config_path": osp.join(con.path_configs, f"{template['class']}.json"),
"preview_path": osp.join(con.path_img, f"{template['class']}.jpg"),
"preview_path": osp.join(con.path_img, f"previews/{template['class']}.jpg"),
"template_path": osp.join(con.path_templates, template['file']),
"plugin_name": None,
"plugin_path": None,
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def load_artwork(self) -> None:
"""
# Check for fullart test image
if cfg.test_mode and self.is_fullart:
self.layout.filename = osp.join(con.path_img, "test-fa.png")
self.layout.filename = osp.join(con.path_img, "test-fa.jpg")

# Paste the file into the art
self.active_layer = self.art_layer
Expand Down

0 comments on commit 403fe1b

Please sign in to comment.