Skip to content

Commit

Permalink
Codechange: generate buy menu sprites for dual-head vehicles, solely …
Browse files Browse the repository at this point in the history
…for reuse in docs (introduces unresolved bugs)
  • Loading branch information
andythenorth committed Feb 15, 2024
1 parent 62b41fb commit 417a1d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
64 changes: 33 additions & 31 deletions src/gestalt_graphics/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,37 +458,39 @@ def process_buy_menu_sprite(self, spritesheet):
source_vehicle_unit,
input_row_num,
) in row_data["source_vehicles_and_input_spriterow_nums"]:
# currently no cap on purchase menu sprite width
# consist has a buy_menu_width prop which caps to 64 which could be used (+1px overlap), but eh
unit_length_in_pixels = 4 * source_vehicle_unit.vehicle_length
input_spriterow_y_offset = (
input_row_num * graphics_constants.spriterow_height
)
crop_box_input = (
224,
10 + input_spriterow_y_offset,
224
+ unit_length_in_pixels
+ 1, # allow for 1px coupler / corrider overhang
26 + input_spriterow_y_offset,
)
crop_box_dest = (
360 + x_offset,
10
+ row_data["spriterow_num_dest"]
* graphics_constants.spriterow_height,
360
+ x_offset
+ unit_length_in_pixels
+ 1, # allow for 1px coupler / corrider overhang
26
+ row_data["spriterow_num_dest"]
* graphics_constants.spriterow_height,
)
custom_buy_menu_sprite = spritesheet.sprites.copy().crop(crop_box_input)
spritesheet.sprites.paste(custom_buy_menu_sprite, crop_box_dest)
# increment x offset for pasting in next vehicle
x_offset += unit_length_in_pixels
# the generated sprite for dual_headed case is intended for docs use only (OpenTTD already assembles the buy menu sprite in that case)
for input_sprite_x_offset in [224, 104] if self.consist.dual_headed else [224]:
# currently no cap on purchase menu sprite width
# consist has a buy_menu_width prop which caps to 64 which could be used (+1px overlap), but eh
unit_length_in_pixels = 4 * source_vehicle_unit.vehicle_length
input_spriterow_y_offset = (
input_row_num * graphics_constants.spriterow_height
)
crop_box_input = (
input_sprite_x_offset,
10 + input_spriterow_y_offset,
input_sprite_x_offset
+ unit_length_in_pixels
+ 1, # allow for 1px coupler / corrider overhang
26 + input_spriterow_y_offset,
)
crop_box_dest = (
360 + x_offset,
10
+ row_data["spriterow_num_dest"]
* graphics_constants.spriterow_height,
360
+ x_offset
+ unit_length_in_pixels
+ 1, # allow for 1px coupler / corrider overhang
26
+ row_data["spriterow_num_dest"]
* graphics_constants.spriterow_height,
)
custom_buy_menu_sprite = spritesheet.sprites.copy().crop(crop_box_input)
spritesheet.sprites.paste(custom_buy_menu_sprite, crop_box_dest)
# increment x offset for pasting in next vehicle
x_offset += unit_length_in_pixels

return spritesheet

Expand Down
6 changes: 6 additions & 0 deletions src/render_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def render_docs_images(consist, static_dir_dst, generated_graphics_path, doc_hel
# oof, super special handling of dual-headed vehicles, OpenTTD handles this automatically in the buy menu, but docs have to handle explicitly
# !! hard-coded values might fail in future, sort that out then if needed, they can be looked up in global constants
# !! this also won't work with engine additional_liveries currently
# !! this should be replaceable - the buy menu sprite generator _should_ now (early 2024) be extensible to handle the dual-head case, which can then be used for docs
source_vehicle_image_1 = vehicle_spritesheet.copy().crop(
box=(
224,
Expand Down Expand Up @@ -214,6 +215,11 @@ def render_docs_images(consist, static_dir_dst, generated_graphics_path, doc_hel
source_vehicle_image_tmp.crop(crop_box_dest), crop_box_dest
)

if "skeiron_middle_passenger" in consist.id:
print("skeiron_middle_passenger CABBAGE 2009")
print("y_offset", y_offset)
source_vehicle_image_tmp.show()

# add pantographs if needed
if consist.pantograph_type is not None:
# buy menu uses pans 'down', but in docs pans 'up' looks better, weird eh?
Expand Down
2 changes: 2 additions & 0 deletions src/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ def requires_custom_buy_menu_sprite(self):
return True
elif self.is_randomised_wagon_type or self.is_caboose:
return True
elif self.dual_headed:
return True
else:
return False

Expand Down

0 comments on commit 417a1d7

Please sign in to comment.