Ejemplo n.º 1
0
 def get_layers(self) -> Iterable[Tuple[str, Layer]]:
     all_layers = [(v.id, v) for v in self.tileset.layers]
     if not all_layers:
         raise DocoptExit('Could not find any layer definitions')
     duplicates = find_duplicates([k for k, v in all_layers])
     if duplicates:
         raise DocoptExit(f'Duplicate layer IDs found: {", ".join(duplicates)}')
     if not self.layer_ids:
         yield from all_layers
         return
     found_layers = set()
     skipped_layers = set()
     for layer_id, layer in all_layers:
         if (layer_id in self.layer_ids) != self.exclude_layers:
             found_layers.add(layer_id)
             yield layer_id, layer
         else:
             skipped_layers.add(layer_id)
     expected_result = skipped_layers if self.exclude_layers else found_layers
     if self.layer_ids != expected_result:
         unknown = sorted(self.layer_ids - expected_result)
         raise DocoptExit(
             f"Unable to find layer [{', '.join(unknown)}]. Available layers:\n" +
             '\n'.join(f"* {k}" + (
                 f"\n{v.description}" if v.description else ''
             ) for k, v in all_layers)
         )
Ejemplo n.º 2
0
 def set_layer_ids(self, layer_ids: List[str], exclude_layers=False):
     if exclude_layers and not layer_ids:
         raise ValueError("Cannot invert layer selection if no layer ids are given")
     if layer_ids:
         dups = find_duplicates(layer_ids)
         if dups:
             raise ValueError(f"Duplicate layer IDs: {', '.join(dups)}")
     self.layer_ids = set(layer_ids or [])
     self.exclude_layers = exclude_layers