From 0aff6273e7f3a108d1ff7152f274eeafd19a11bb Mon Sep 17 00:00:00 2001 From: Taka Date: Sun, 18 Apr 2021 23:47:20 +1000 Subject: [PATCH] Tightened up how CG ruleid's are extracted from the index. --- asl_rulebook2/extract/data/index-fixups.json | 18 +++++++----------- asl_rulebook2/extract/index.py | 20 ++++++++++++++++++-- bin/add_pdf_dests.py | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/asl_rulebook2/extract/data/index-fixups.json b/asl_rulebook2/extract/data/index-fixups.json index a601932..83bf26e 100644 --- a/asl_rulebook2/extract/data/index-fixups.json +++ b/asl_rulebook2/extract/data/index-fixups.json @@ -66,10 +66,7 @@ "End of Scenario": { "replace": [ - [ "[in ABtF: R9.4 CG4]", "[in ABtF: R9.4, CG4]" ], - [ "[in KGP: P8.4 CG23]", "[in KGP: P8.4, CG23]" ], - [ "[in PB: Q9.4 CG19 (-1 drm for any Night Scenario and +1 drm for Day II scenario: Turn Record Track)]", "[in PB (-1 drm for any Night Scenario and +1 drm for Day II scenario: Turn Record Track): Q9.4, CG19]" ], - [ "[in RB: O11.4 CG4]", "[in RB: O11.4, CG4]" ] + [ "[in PB: Q9.4 CG19 (-1 drm for any Night Scenario and +1 drm for Day II scenario: Turn Record Track)]", "[in PB (-1 drm for any Night Scenario and +1 drm for Day II scenario: Turn Record Track): Q9.4 CG19]" ] ] }, @@ -196,13 +193,6 @@ ] }, -"Radio": { - "replace": [ - [ "[in KGP: P8.4 CG15]", "[in KGP: P8.4, CG15]" ], - [ "[in RB: O11.4 CG6]", "[in RB: O11.4, CG6]" ] - ] -}, - "Range": { "replace": [ [ "see Firing Within Hex", "A7.21" ] @@ -215,6 +205,12 @@ ] }, +"Reinforcements": { + "replace": [ + [ "P8.4, CG7", "P8.4 CG7" ] + ] +}, + "Rubble": { "replace": [ [ "; Stone Blaze:", "] [RePh, Stone Blaze:" ] diff --git a/asl_rulebook2/extract/index.py b/asl_rulebook2/extract/index.py index eb626b9..d301a2e 100755 --- a/asl_rulebook2/extract/index.py +++ b/asl_rulebook2/extract/index.py @@ -198,6 +198,22 @@ class ExtractIndex( ExtractBase ): def _process_content( self ): """Extract information out of the index entries into a structured form.""" + def fixup_ruleid( ruleid ): + # FUDGE! The index often refers to the same rule as e.g. "O11.4 CG3" and "OCG3" :-/ + # We translate the former into the latter. + if ruleid.startswith( "O11.4 CG" ): + return "O" + ruleid[6:] # nb: Red Barricades + elif ruleid.startswith( "P8.4 CG" ): + return "P" + ruleid[5:] # nb: Kampfgruppe Peiper + elif ruleid.startswith( "Q9.4 CG" ): + return "Q" + ruleid[5:] # nb: Pegasus Bridge + elif ruleid.startswith( "R9.4 CG" ): + return "R" + ruleid[5:] # nb: A Bridge Too Far + elif ruleid.startswith( "T15.4 CG" ): + return "T" + ruleid[6:] # nb: Blood Reef Tarawa + else: + return ruleid + for index_entry in self.index_entries: # initialize @@ -244,7 +260,7 @@ class ExtractIndex( ExtractBase ): else: break if ruleids: - index_entry[ "ruleids" ] = ruleids + index_entry[ "ruleids" ] = [ fixup_ruleid( r ) for r in ruleids ] # extract any ruleref's rulerefs = [] @@ -256,7 +272,7 @@ class ExtractIndex( ExtractBase ): pos = val.rfind( ":" ) if pos > 0: vals = re.split( "[;,]", val[pos+1:] ) - ruleids = [ v.strip() for v in vals ] + ruleids = [ fixup_ruleid( v.strip() ) for v in vals ] val = val[:pos].strip() else: ruleids = None diff --git a/bin/add_pdf_dests.py b/bin/add_pdf_dests.py index c8cd192..2bcb8f8 100755 --- a/bin/add_pdf_dests.py +++ b/bin/add_pdf_dests.py @@ -45,7 +45,7 @@ def main( pdf_file, title, targets_fname, yoffset, output_fname, gs_path ): if isinstance( ypos, int ): ypos += yoffset if " " in ruleid: - # NOTE: We are supposed to be able to quote things using parenthese (e.g. "(foo bar)" + # NOTE: We are supposed to be able to quote things using parentheses (e.g. "(foo bar)" # but it doesn't seem to work here :-( raise RuntimeError( "PDF destinations cannot have spaces." ) print( "[ /Dest /{} /Page {} /View [/XYZ {} {}] /DEST pdfmark".format(