Skip to content

Commit

Permalink
More robust fix for #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Sep 27, 2020
1 parent e5d7607 commit 3a6832c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/ttblit/tool/packer.py
Expand Up @@ -3,6 +3,7 @@
import yaml

from ..core.outputformat import CHeader, CSource, RawBinary
from ..core.palette import Palette
from ..core.tool import Tool


Expand Down Expand Up @@ -108,12 +109,8 @@ def run(self, args):
elif file_options is None:
file_options = {}

if 'palette' in file_options:
if not pathlib.Path(file_options['palette']).is_absolute():
file_options['palette'] = self.working_path / file_options['palette']

asset_sources.append(
AssetSource(input_files, builders=self.asset_builders, file_options=file_options)
AssetSource(input_files, builders=self.asset_builders, file_options=file_options, working_path=self.working_path)
)

self.assets.append(AssetTarget(
Expand All @@ -132,9 +129,10 @@ def run(self, args):
class AssetSource():
supported_options = ('name', 'type')

def __init__(self, input_files, builders, file_options):
def __init__(self, input_files, builders, file_options, working_path):
self.input_files = input_files
self.asset_builders = builders
self.working_path = working_path
self.builder_options = {}
self.type = None
self.name = None
Expand Down Expand Up @@ -166,6 +164,21 @@ def build(self, format, prefix=None, output_file=None):
builder, input_type = self.type.split('/')
builder = self.asset_builders[builder]

# Now we know our target builder, one last iteration through the options
# allows some pre-processing stages to remap paths or other idiosyncrasies
# of the yml config format.
for option_name, option_value in builder.options.items():
if option_name in self.builder_options:
option_type = builder.options[option_name]
if type(option_type) is tuple:
option_type, default_value = option_type

# Ensure Palette and pathlib.Path type options for this asset builder
# are prefixed with the working directory if they are not absolute paths
if option_type in (Palette, pathlib.Path):
if not pathlib.Path(self.builder_options[option_name]).is_absolute():
self.builder_options[option_name] = self.working_path / self.builder_options[option_name]

output = []

for file in self.input_files:
Expand Down

0 comments on commit 3a6832c

Please sign in to comment.