home · contact · privacy
Guard against double entries in table Design, Color, Piece table files. master
authorPlom Heller <plom@plomlompom.com>
Sun, 3 May 2026 18:42:04 +0000 (20:42 +0200)
committerPlom Heller <plom@plomlompom.com>
Sun, 3 May 2026 18:42:04 +0000 (20:42 +0200)
bricksplom.py

index 8239f1a16605c56ec18bb396bc8b541f3cfcb833..e3379eb2b21c807b269bbc09484ad041d310ac28 100755 (executable)
@@ -107,6 +107,7 @@ class Color(Textfiled):
             ) -> dict[str, Self]:
         collected = {}
         for id_, desc in [cls.tokify(line, 2) for line in cls.lines_of(path)]:
+            assert id_ not in collected
             assert len(desc) > 1
             assert desc[0] in {CHAR_COL_SOLID, CHAR_COL_TRANSPARENT}
             collected[id_] = cls(id_, desc[0] == CHAR_COL_SOLID, desc[1:])
@@ -142,6 +143,7 @@ class Design(Textfiled):
         alts: dict[str, set[str]] = {}
         for design_id, body in [cls.tokify(line, 2)
                                 for line in cls.lines_of(path)]:
+            assert design_id not in collected
             assert len(body) > 1
             char_type, body = body[0], body[1:]
             assert char_type in {CHAR_DESIGN_ALT, CHAR_DESIGN_DESC}
@@ -199,6 +201,7 @@ class Piece(Textfiled):
         collected = {}
         for toks in [cls.tokify(line, 3) for line in cls.lines_of(path)]:
             piece_id, design_id = toks[:2]
+            assert piece_id not in collected
             color_id, comment = (toks[-1].split(CHAR_SEP_TOKEN, maxsplit=1)
                                  + [''])[:2]
             collected[piece_id] = cls(piece_id, design_id, color_id, comment)