Skip to content

Commit b45e186

Browse files
committed
Fix: Use 2 dimensional array for minimum_bridge_height and bridge_pillars_flags so invert feature can be used for all tiles
1 parent 4678a57 commit b45e186

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

nml/actions/action0properties.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,27 @@ def station_tile_flags(value):
819819
]
820820

821821

822-
def array_for_station_properties(prop_num: int, list_type: str, prefered_size: int, invert_function: callable):
822+
def array_for_station_properties(prop_num: int, list_type: str, invert_function: callable):
823823
def generated_function(value):
824-
if isinstance(value, ConstantNumeric):
825-
value = Array([value, invert_function(value)] * prefered_size, value.pos)
826824
if not isinstance(value, Array):
827-
raise generic.ScriptError(f"{list_type} list must be an array", value.pos)
828-
if len(value.values) % 2 != 0:
829-
raise generic.ScriptError(f"{list_type} list does not have even length", value.pos)
830-
return [VariableByteListProp(prop_num, [[flags.reduce_constant().value for flags in value.values]], True)]
825+
raise generic.ScriptError(f"{list_type} list must be an array, not {type(value).__name__}", value.pos)
826+
new_value = Array([], value.pos)
827+
for element in value.values:
828+
if isinstance(element, ConstantNumeric):
829+
new_value.values.append(element)
830+
new_value.values.append(invert_function(element))
831+
elif isinstance(element, Array):
832+
if len(element.values) != 2:
833+
raise generic.ScriptError(
834+
f"{list_type} list can only contain int or two element array", element.pos
835+
)
836+
new_value.values.append(element.values[0])
837+
new_value.values.append(element.values[1])
838+
else:
839+
raise generic.ScriptError(f"{list_type} list can only contain int or two element array", element.pos)
840+
if len(new_value.values) % 2 != 0:
841+
raise generic.ScriptError(f"{list_type} list does not have even length", new_value.pos)
842+
return [VariableByteListProp(prop_num, [[flags.reduce_constant().value for flags in new_value.values]], True)]
831843

832844
return generated_function
833845

@@ -875,10 +887,10 @@ def invert_bridge_pillars_flags(value):
875887
"classname": {"size": 2, "num": (256, -1, 0x1D), "string": (256, 0xC4, 0xDC)},
876888
"tile_flags": {"custom_function": station_tile_flags}, # = prop 1E
877889
"minimum_bridge_height": {
878-
"custom_function": array_for_station_properties(0x20, "Bridge heights", 0xFFFF, lambda v : v)
890+
"custom_function": array_for_station_properties(0x20, "Bridge heights", lambda v : v)
879891
},
880892
"bridge_pillars_flags": {
881-
"custom_function": array_for_station_properties(0x21, "Flag", 0xFFFF, invert_bridge_pillars_flags)
893+
"custom_function": array_for_station_properties(0x21, "Flag", invert_bridge_pillars_flags)
882894
},
883895
}
884896
# fmt: on
@@ -1695,9 +1707,9 @@ def byte_sequence_list(value, prop_num, description, expected_count):
16951707
"general_flags": {"size": 4, "num": 0x12},
16961708
"cost_multipliers": {"custom_function": lambda x: byte_sequence_list(x, 0x15, "Cost multipliers", 2)},
16971709
"minimum_bridge_height": {
1698-
"custom_function": array_for_station_properties(0x13, "Bridge heights", 1, lambda v : v)
1710+
"custom_function": array_for_station_properties(0x13, "Bridge heights", lambda v : v)
16991711
},
17001712
"bridge_pillars_flags": {
1701-
"custom_function": array_for_station_properties(0x14, "Flag", 1, invert_bridge_pillars_flags)
1713+
"custom_function": array_for_station_properties(0x14, "Flag", invert_bridge_pillars_flags)
17021714
},
17031715
}

0 commit comments

Comments
 (0)