|
27 | 27 |
|
28 | 28 | import sys, os |
29 | 29 |
|
30 | | -def preprocess_pnml(pnml_path, high_bitdepth = False, extra_zoom = False, exclude_name_suffix = False): |
| 30 | +def preprocess_pnml(pnml_path, newgrf_version, high_bitdepth = False, extra_zoom = False, exclude_name_suffix = False): |
31 | 31 | def get_name(): |
32 | 32 | """ |
33 | 33 | Set the name of the nml variant based on the options. |
@@ -67,6 +67,18 @@ def check_imports_change(): |
67 | 67 | return True |
68 | 68 | return False |
69 | 69 |
|
| 70 | + def check_version_line(line): |
| 71 | + """ |
| 72 | + Check if the line is a version line, and return the version if it is. |
| 73 | + """ |
| 74 | + # comment defining version |
| 75 | + comment_version = "#version" |
| 76 | + |
| 77 | + if line.strip() == comment_version: |
| 78 | + prefix = line.split(comment_version)[0] |
| 79 | + return prefix + "version: " + newgrf_version + ";" |
| 80 | + return line |
| 81 | + |
70 | 82 | def check_import_line(line): |
71 | 83 | """ |
72 | 84 | Check if the line is an import line, and return the path if it is. |
@@ -135,27 +147,33 @@ def handle_alternates(line): |
135 | 147 | with open(os.path.join(base_path, import_path), "r") as include: |
136 | 148 | include_lines = include.read().splitlines() |
137 | 149 | for include_line in include_lines: |
| 150 | + include_line = check_version_line(include_line) |
138 | 151 | include_line = handle_alternates(include_line) |
139 | 152 | nml.write(include_line + "\n") |
140 | 153 | except FileNotFoundError: |
141 | 154 | print("File not found:", os.path(base_path, import_path)) |
142 | 155 | else: |
143 | | - include_line = handle_alternates(line) |
| 156 | + include_line = check_version_line(line) |
| 157 | + include_line = handle_alternates(include_line) |
144 | 158 | nml.write(include_line + "\n") |
145 | 159 | except FileNotFoundError: |
146 | 160 | print("File not found:", sys.argv[1] + ".pnml") |
147 | 161 |
|
148 | 162 | if __name__ == "__main__": |
| 163 | + if len(sys.argv) < 3: |
| 164 | + print("Usage: baseset_generate_obg.py <pnml_path> <newgrf_version> [type_string] [exclude_name_suffix]") |
| 165 | + sys.exit(1) |
149 | 166 | pnml_path = sys.argv[1] |
| 167 | + newgrf_version = sys.argv[2] |
150 | 168 | high_bitdepth = False |
151 | 169 | extra_zoom = False |
152 | | - if len(sys.argv) > 2: |
153 | | - if "32" in sys.argv[2]: |
| 170 | + if len(sys.argv) > 3: |
| 171 | + if "32" in sys.argv[3]: |
154 | 172 | high_bitdepth = True |
155 | | - if "ez" in sys.argv[2]: |
| 173 | + if "ez" in sys.argv[3]: |
156 | 174 | extra_zoom = True |
157 | 175 | exclude_name_suffix = False |
158 | | - if len(sys.argv) > 3: |
159 | | - if sys.argv[3] == "exclude_name_suffix": |
| 176 | + if len(sys.argv) > 4: |
| 177 | + if sys.argv[4] == "exclude_name_suffix": |
160 | 178 | exclude_name_suffix = True |
161 | | - preprocess_pnml(pnml_path, high_bitdepth, extra_zoom, exclude_name_suffix) |
| 179 | + preprocess_pnml(pnml_path, newgrf_version, high_bitdepth, extra_zoom, exclude_name_suffix) |
0 commit comments