From: Plom Heller Date: Sat, 8 Aug 2026 17:18:47 +0000 (+0200) Subject: Fix -f ldraw_tree to not ignore any beyond a first reference to same file. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/foo.html?a=commitdiff_plain;h=57277de7632988ce6d630844281e3483ffa5df32;p=bricksplom Fix -f ldraw_tree to not ignore any beyond a first reference to same file. --- diff --git a/src/bricksplom/ldraw.py b/src/bricksplom/ldraw.py index bb57901..8f29447 100644 --- a/src/bricksplom/ldraw.py +++ b/src/bricksplom/ldraw.py @@ -21,13 +21,12 @@ LDRAW_STUDS = { 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: @@ -64,11 +63,10 @@ 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( @@ -78,8 +76,9 @@ class LdrawDb: '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, @@ -90,7 +89,7 @@ class LdrawDb: 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]: @@ -104,7 +103,7 @@ class LdrawDb: 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, diff --git a/src/bricksplom/misc.py b/src/bricksplom/misc.py index 274b8f3..e24a3c8 100644 --- a/src/bricksplom/misc.py +++ b/src/bricksplom/misc.py @@ -321,7 +321,7 @@ class BrickDesign(Textfiled, WithDb, Lookupable): 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'