LdrawRefsTree = tuple[Path, '_SubRefs']
-_SubRefs = dict[str, LdrawRefsTree]
+_SubRefs = tuple[tuple[str, LdrawRefsTree], ...]
_N_TOKS_PER_REFLINE = 15
class LdrawPathFailure(Exception):
'For when no proper .dat file found to filename.'
- pass
class LdrawDb:
continue
assert len(toks) == _N_TOKS_PER_REFLINE
referenced = toks.pop().replace('\\', '/')
- collected += [
- collect(lambda: self._walk_tree(referenced, collect, result),
- referenced,
- toks)
- ]
+ collected += collect(
+ lambda: self._walk_tree(referenced, collect, result),
+ referenced,
+ toks)
return result(path, collected)
def tree(
'Produce LdrawRefsTree for filename.'
return self._walk_tree(
filename,
- collect=lambda walk, ref, _: (ref, walk()),
- result=lambda path, coll: (path, {t[0]: t[1] for t in coll}))
+ collect=lambda walk, ref, _: [(ref, walk())],
+ result=lambda path, coll: (path, tuple((t[0], t[1])
+ for t in coll)))
def count_studs(
self,
walk: Callable[[], int],
ref: str,
toks: list[str]
- ) -> int:
+ ) -> tuple[int]:
matrix = tuple(tuple(toks[n:n+3]) for n in (5, 8, 11))
do_ignore = False
for row in [[float(x) for x in row] for row in matrix]:
if jdx != idx and row[jdx] != 0]:
do_ignore = True
break
- return int((not do_ignore) and ref in LDRAW_STUDS) or walk()
+ return (int((not do_ignore) and ref in LDRAW_STUDS) or walk(), )
return self._walk_tree(filename,
collect=count_studs,
indent = depth * 4 * ' '
path, subrefs = refstree
lines += [f'{indent}"{filename}": {path}']
- for refname, subrefstree in subrefs.items():
+ for refname, subrefstree in subrefs:
walk(lines, refname, subrefstree, depth+1)
if not item.ldraw:
return 'no LDRAW file associated'