home · contact · privacy
Fix -f ldraw_tree to not ignore any beyond a first reference to same file.
authorPlom Heller <plom@plomlompom.com>
Sat, 8 Aug 2026 17:18:47 +0000 (19:18 +0200)
committerPlom Heller <plom@plomlompom.com>
Sat, 8 Aug 2026 17:18:47 +0000 (19:18 +0200)
src/bricksplom/ldraw.py
src/bricksplom/misc.py

index bb57901ed205ec09de114944fd17ac7a141c5533..8f294471cdc743b956f7266ad371a13f47632130 100644 (file)
@@ -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,
index 274b8f3eeb54108f98d900a166f97c25fb85da49..e24a3c8835b80e2b7b52b5e28bfbfa4f74be6044 100644 (file)
@@ -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'