Skip to content

Commit 7fc5cdd

Browse files
committed
implement review comments
1 parent 76c0a51 commit 7fc5cdd

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

Controller/RUL0/7000_Road_NWM/7A00_NWM/7B50_Transitions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ CheckType = c - road: 0x00000200, 0x0000ff00 check
24452445
ConsLayout =.......
24462446
ConsLayout =.......
24472447
ConsLayout =...|..<
2448-
ConsLayout =...|..<
2448+
ConsLayout =...|...
24492449
ConsLayout =.......
24502450
ConsLayout =...^...
24512451

src/scripts/syntax-check-rul0.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#
33
# This script checks all the RUL0 files for errors such as sinkhole bugs..
44
# If any are found, they are printed to stdout and the script exits with a non-zero return code.
5+
#
6+
# Minimum requirement: Python 3.12+
7+
# Further info: https://www.wiki.sc4devotion.com/index.php?title=RUL0
58

69
import sys
710
import os
@@ -21,9 +24,13 @@ def drop_comments(lines):
2124

2225
# create mapping of (x,y)-cell to char
2326
def parse_layout(lines):
24-
layout = [line[(line.index("=")+1):].strip() for line in drop_comments(lines)]
25-
origin_x = ([l.index("^") for l in layout if "^" in l] or [0])[0]
26-
origin_y = ([i for i, l in enumerate(layout) if "<" in l] or [0])[0]
27+
layout = [line[(line.index("=")+1):].strip() for line in drop_comments(l for _, l in lines)]
28+
markers_x = [line.index("^") for line in layout if "^" in line]
29+
markers_y = [i for i, line in enumerate(layout) if "<" in line]
30+
if len(markers_x) != 1 or len(markers_y) != 1:
31+
raise Exception(f"Missing or incorrect origin markers '^'/'<' in layout starting at line {lines[0][0]}")
32+
origin_x = markers_x[0]
33+
origin_y = markers_y[0]
2734
cells = {(j-origin_x, i-origin_y): char
2835
for i, row in enumerate(layout)
2936
for j, char in enumerate(row)
@@ -33,13 +40,13 @@ def parse_layout(lines):
3340

3441

3542
def check_cons_layout(cell_lines, cons_lines):
36-
cell_layout = parse_layout(l for _, l in cell_lines)
37-
cons_layout = parse_layout(l for _, l in cons_lines)
43+
cell_layout = parse_layout(cell_lines)
44+
cons_layout = parse_layout(cons_lines)
3845
bad_cells = [xy for xy in cons_layout.keys() if xy not in cell_layout]
3946
if bad_cells:
4047
cell_layout_str = "".join(f" {line_no}: {line}" for line_no, line in cell_lines)
4148
cons_layout_str = "".join(f" {line_no}: {line}" for line_no, line in cons_lines)
42-
raise Exception(f"Potential sinkhole bug in ConsLayout at cells {" ".join(map(str, bad_cells))}:\n{cell_layout_str} ---\n{cons_layout_str}")
49+
raise Exception(f"Potential sinkhole bug in ConsLayout at cells {' '.join(map(str, bad_cells))}:\n{cell_layout_str} ---\n{cons_layout_str}")
4350

4451

4552
def scan_rul0_file(lines):

0 commit comments

Comments
 (0)