Skip to content

Commit 5c15494

Browse files
committed
Codechange: Pass nml/newgrf versions from makefile
Passes automatically determined baseset version as newgrf version to the nml preprocessing Python script
1 parent 0d5e6d7 commit 5c15494

File tree

9 files changed

+36
-18
lines changed

9 files changed

+36
-18
lines changed

baseset/nml/extra/extra-header.pnml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ grf {
44
name: string(STR_GRF_NAME);
55
desc: string(STR_GRF_DESCRIPTION);
66
url: string(STR_GRF_URL);
7-
version: 8;
7+
#version
88
min_compatible_version: version_openttd(1, 3, 0);
99
param 1 {
1010
param_cursors_ {

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ baseset/%_8.grf: graphics_1 baseset/lang/*.lng FORCE
9393
$(eval PREF=$(word 1, $(subst _, ,$(basename $(notdir $@)))))
9494
$(eval NAME=$(word 2, $(subst _, ,$(basename $(notdir $@)))))
9595
$(eval ZOOM=$(word 3, $(subst _, ,$(basename $(notdir $@)))))
96-
python3 templates/nml_preprocessor.py baseset/$(PREF)_$(NAME).pnml $(ZOOM)
96+
python3 templates/nml_preprocessor.py baseset/$(PREF)_$(NAME).pnml $(BASESET_VERSION) $(ZOOM)
9797
cd baseset && nmlc -p DOS --quiet -c $(PREF)_$(NAME)_$(ZOOM).nml --md5 $(PREF)_$(NAME)_$(ZOOM).md5
9898

9999
baseset/%_32ez.grf: graphics_4 baseset/lang/*.lng FORCE
100100
$(eval PREF=$(word 1, $(subst _, ,$(basename $(notdir $@)))))
101101
$(eval NAME=$(word 2, $(subst _, ,$(basename $(notdir $@)))))
102102
$(eval ZOOM=$(word 3, $(subst _, ,$(basename $(notdir $@)))))
103103
echo $(PREF) $(NAME) $(ZOOM)
104-
python3 templates/nml_preprocessor.py baseset/$(PREF)_$(NAME).pnml $(ZOOM)
104+
python3 templates/nml_preprocessor.py baseset/$(PREF)_$(NAME).pnml $(BASESET_VERSION) $(ZOOM)
105105
cd baseset && nmlc -p DOS --quiet -c $(PREF)_$(NAME)_$(ZOOM).nml --md5 $(PREF)_$(NAME)_$(ZOOM).md5
106106

107107
# NewGRFs
@@ -117,7 +117,7 @@ newgrf/%.grf: graphics_4 FORCE
117117
$(eval PREF=$(word 1, $(subst _, ,$(basename $(notdir $@)))))
118118
$(eval NAME=$(word 2, $(subst _, ,$(basename $(notdir $@)))))
119119
echo $(PREF) $(NAME)
120-
python3 templates/nml_preprocessor.py newgrf/$(PREF)_$(NAME).pnml 32ez
120+
python3 templates/nml_preprocessor.py newgrf/$(PREF)_$(NAME).pnml $(BASESET_VERSION) 32ez
121121
mv newgrf/$(PREF)_$(NAME)_32ez.nml newgrf/$(PREF)_$(NAME).nml
122122
cd newgrf && nmlc -p DOS --quiet -c -l ../baseset/lang $(PREF)_$(NAME).nml
123123

newgrf/nml/landscape/landscape-header.pnml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ grf {
33
name: string(STR_GRF_LANDSCAPE_NAME);
44
desc: string(STR_GRF_LANDSCAPE_DESCRIPTION);
55
url: string(STR_GRF_URL);
6-
version: 8;
6+
#version
77
min_compatible_version: version_openttd(1, 3, 0);
88
param 2 {
99
param_gridlines {

newgrf/nml/objects/objects-header.pnml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ grf {
33
name: string(STR_GRF_OBJECTS_NAME);
44
desc: string(STR_GRF_OBJECTS_DESCRIPTION);
55
url: string(STR_GRF_URL);
6-
version: 8;
6+
#version
77
min_compatible_version: version_openttd(1, 3, 0);
88
}
99

newgrf/nml/settings/settings-header.pnml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ grf {
33
name: string(STR_GRF_SETTINGS_NAME);
44
desc: string(STR_GRF_SETTINGS_DESCRIPTION);
55
url: string(STR_GRF_URL);
6-
version: 8;
6+
#version
77
min_compatible_version: version_openttd(1, 3, 0);
88
param 1 {
99
param_cursors_ {

newgrf/nml/stations/stations-header.pnml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ grf {
33
name: string(STR_GRF_STATIONS_NAME);
44
desc: string(STR_GRF_STATIONS_DESCRIPTION);
55
url: string(STR_GRF_URL);
6-
version: 8;
6+
#version
77
min_compatible_version: version_openttd(1, 3, 0);
88
}
99

newgrf/nml/trams/trams-header.pnml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ grf {
33
name: string(STR_GRF_TRAMS_NAME);
44
desc: string(STR_GRF_TRAMS_DESCRIPTION);
55
url: string(STR_GRF_URL);
6-
version: 8;
6+
#version
77
min_compatible_version: version_openttd(1, 3, 0);
88
}
99

newgrf/nml/trees/trees-header.pnml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ grf {
33
name: string(STR_GRF_TREES_NAME);
44
desc: string(STR_GRF_TREES_DESCRIPTION);
55
url: string(STR_GRF_URL);
6-
version: 8;
6+
#version
77
min_compatible_version: version_openttd(1, 3, 0);
88
param 12 {
99
param_trees_temperate {

templates/nml_preprocessor.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import sys, os
2929

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):
3131
def get_name():
3232
"""
3333
Set the name of the nml variant based on the options.
@@ -67,6 +67,18 @@ def check_imports_change():
6767
return True
6868
return False
6969

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+
7082
def check_import_line(line):
7183
"""
7284
Check if the line is an import line, and return the path if it is.
@@ -135,27 +147,33 @@ def handle_alternates(line):
135147
with open(os.path.join(base_path, import_path), "r") as include:
136148
include_lines = include.read().splitlines()
137149
for include_line in include_lines:
150+
include_line = check_version_line(include_line)
138151
include_line = handle_alternates(include_line)
139152
nml.write(include_line + "\n")
140153
except FileNotFoundError:
141154
print("File not found:", os.path(base_path, import_path))
142155
else:
143-
include_line = handle_alternates(line)
156+
include_line = check_version_line(line)
157+
include_line = handle_alternates(include_line)
144158
nml.write(include_line + "\n")
145159
except FileNotFoundError:
146160
print("File not found:", sys.argv[1] + ".pnml")
147161

148162
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)
149166
pnml_path = sys.argv[1]
167+
newgrf_version = sys.argv[2]
150168
high_bitdepth = False
151169
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]:
154172
high_bitdepth = True
155-
if "ez" in sys.argv[2]:
173+
if "ez" in sys.argv[3]:
156174
extra_zoom = True
157175
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":
160178
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

Comments
 (0)