Skip to content

Commit

Permalink
Codechange: docs_sprite_width is better, as it's not buy menu in that…
Browse files Browse the repository at this point in the history
… consist; also docs_sprite_max_width and docs_sprite_height
  • Loading branch information
andythenorth committed Sep 11, 2023
1 parent b89626a commit 7c4d52b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 74 deletions.
12 changes: 6 additions & 6 deletions src/doc_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class DocHelper(object):
palette = utils.dos_palette_to_rgb()

# these only used in docs as of April 2018
buy_menu_sprite_max_width = 65 # up to 2 units eh
buy_menu_sprite_height = 16
docs_sprite_max_width = 65 # up to 2 units eh
docs_sprite_height = 16

def __init__(self, lang_strings):
self.lang_strings = lang_strings

def buy_menu_sprite_width(self, consist):
def docs_sprite_width(self, consist):
if not consist.dual_headed:
# +1 for the buffers etc
return min((consist.buy_menu_width + 1), self.buy_menu_sprite_max_width)
return min((consist.buy_menu_width + 1), self.docs_sprite_max_width)
# openttd automatically handles dual head, but we need to calculate double width explicitly for docs
if consist.dual_headed:
return min((2 * 4 * consist.length) + 1, self.buy_menu_sprite_max_width)
return min((2 * 4 * consist.length) + 1, self.docs_sprite_max_width)

def get_vehicles_by_subclass(self, consists, filter_subclasses_by_name=None):
# first find all the subclasses + their vehicles
Expand Down Expand Up @@ -287,7 +287,7 @@ def get_vehicle_images_json(self, roster):
for consist in vehicle_consists:
vehicle_data = [
consist.id,
str(self.buy_menu_sprite_width(consist)),
str(self.docs_sprite_width(consist)),
consist.base_numeric_id,
]
result["sorted_by_vehicle_type"][vehicle_type].append(vehicle_data)
Expand Down
6 changes: 3 additions & 3 deletions src/docs_templates/code_reference.pt
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
<tal:vehicles repeat="consist subclass['vehicles']">
<tr>
<td class="vehicle-image"
style="min-width:${2 * doc_helper.buy_menu_sprite_max_width}px;">
style="min-width:${2 * doc_helper.docs_sprite_max_width}px;">
<img src="static/img/${consist.id}_variant_0_red_white.png"
width="${2 * doc_helper.buy_menu_sprite_width(consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</td>
<tal:props repeat="prop_name props_to_print[subclass['name']]">
<td>${props_to_print[consist][prop_name]}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/docs_templates/main_template.pt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
document.write('<a href="trains.html#' + random_image[0] + '" style="display:inline; margin-bottom: 20px;"> \
<img src="static/img/'+ random_image[0] + '_variant_0_red_white.png" \
width="' + 4 * random_image[1] + '" \
height="${4 * doc_helper.buy_menu_sprite_height}"> \
height="${4 * doc_helper.docs_sprite_height}"> \
</a>')
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/docs_templates/tech_tree_table_body.pt
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@
${consist._name}
</span>
<img src="static/img/${consist.id}_variant_0_${vehicle_cc}.png"
width="${2 * doc_helper.buy_menu_sprite_width(consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
<span style="display:block; margin-top: 5px; line-height:1.3;" class="muted">
<small>
<tal:power repeat="power_string doc_helper.power_formatted_for_docs(consist)">
Expand Down
2 changes: 1 addition & 1 deletion src/docs_templates/train_whack.pt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
var sprite_size_factor = get_query_param('sprite_size_factor') ? get_query_param('sprite_size_factor') : 3;
return '<a href="trains.html#' + random_image[0] + '" style="display:inline-block; margin-top:' + 5 * sprite_size_factor + 'px; margin-bottom:' + 5 * sprite_size_factor + 'px; margin-right:-' + sprite_size_factor + 'px;"> \
<img src="static/img/'+ random_image[0] + '_variant_0_red_white.png" \
style="width:' + sprite_size_factor * random_image[1] + 'px; height:' + sprite_size_factor * ${doc_helper.buy_menu_sprite_height} + 'px; margin:0;"> \
style="width:' + sprite_size_factor * random_image[1] + 'px; height:' + sprite_size_factor * ${doc_helper.docs_sprite_height} + 'px; margin:0;"> \
</a>'; // -ve margin right used to overlap buffers etc
}

Expand Down
24 changes: 12 additions & 12 deletions src/docs_templates/trains.pt
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@
<tal:engine_consists repeat="consist doc_helper.get_engines_by_roster_and_base_track_type(roster, base_track_type_name[0])">
<tr id="${consist.id}">
<td class="vehicle-image"
style="width:${2 * doc_helper.buy_menu_sprite_max_width};">
style="width:${2 * doc_helper.docs_sprite_max_width};">
<img src="static/img/${consist.id}_variant_0_blue_blue.png"
width="${2 * doc_helper.buy_menu_sprite_width(consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</td>
<td class="vehicle-image"
style="width:${2 * doc_helper.buy_menu_sprite_max_width};">
style="width:${2 * doc_helper.docs_sprite_max_width};">
<img src="static/img/${consist.id}_variant_0_red_white.png"
width="${2 * doc_helper.buy_menu_sprite_width(consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</td>
<td>
<a class="table-link-dark" href="${consist.id}.html">${doc_helper.unpack_name_string(consist)}</a>
Expand Down Expand Up @@ -120,16 +120,16 @@
<tal:wagon_consists repeat="consist doc_helper.get_wagons_by_roster_and_base_track_type(roster, base_track_type_name[0])">
<tr id="${consist.id}">
<td class="vehicle-image"
style="width:${2 * doc_helper.buy_menu_sprite_max_width};">
style="width:${2 * doc_helper.docs_sprite_max_width};">
<img src="static/img/${consist.id}_variant_0_blue_blue.png"
width="${2 * doc_helper.buy_menu_sprite_width(consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</td>
<td class="vehicle-image"
style="width:${2 * doc_helper.buy_menu_sprite_max_width};">
style="width:${2 * doc_helper.docs_sprite_max_width};">
<img src="static/img/${consist.id}_variant_0_red_white.png"
width="${2 * doc_helper.buy_menu_sprite_width(consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</td>
<td>
<a class="table-link-dark" href="${consist.id}.html">${doc_helper.unpack_name_string(consist)}</a>
Expand Down
34 changes: 17 additions & 17 deletions src/docs_templates/vehicle_details_engine.pt
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
<div style="margin-top:30px; margin-bottom:50px;">
<tal:livery repeat="livery_variant doc_helper.get_docs_livery_variants(consist)">
<div class="vehicle-image"
style="width:${2 * doc_helper.buy_menu_sprite_max_width};
style="width:${2 * doc_helper.docs_sprite_max_width};
display:inline-block;">
<img src="static/img/${consist.id}_${livery_variant['livery_name']}.png"
width="${2 * doc_helper.buy_menu_sprite_width(consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</div>
</tal:livery>
<br />
<tal:livery repeat="livery_variant doc_helper.get_docs_livery_variants(consist)">
<div class="vehicle-image"
style="width:${4 * doc_helper.buy_menu_sprite_max_width};
style="width:${4 * doc_helper.docs_sprite_max_width};
display:inline-block;">
<img src="static/img/${consist.id}_${livery_variant['livery_name']}.png"
width="${4 * doc_helper.buy_menu_sprite_width(consist)}"
height="${4 * doc_helper.buy_menu_sprite_height}" />
width="${4 * doc_helper.docs_sprite_width(consist)}"
height="${4 * doc_helper.docs_sprite_height}" />
</div>
</tal:livery>
</div>
Expand Down Expand Up @@ -203,10 +203,10 @@
<tal:livery_examples repeat="livery_variant [livery_variant for livery_variant in doc_helper.get_docs_livery_variants(consist) if livery_variant['buyable_variant'] == buyable_variant]">
<div class="livery-example-container">
<div class="vehicle-image"
style="width:${3 * doc_helper.buy_menu_sprite_max_width}; vertical-align:top; margin-top:-8px; margin-bottom:10px;">
style="width:${3 * doc_helper.docs_sprite_max_width}; vertical-align:top; margin-top:-8px; margin-bottom:10px;">
<img src="static/img/${consist.id}_${livery_variant['livery_name']}.png"
width="${3 * doc_helper.buy_menu_sprite_width(consist)}"
height="${3 * doc_helper.buy_menu_sprite_height}" />
width="${3 * doc_helper.docs_sprite_width(consist)}"
height="${3 * doc_helper.docs_sprite_height}" />
</div>
<div style="display:block;">
<tal:colours repeat="company_colour livery_variant['docs_image_input_cc']">
Expand Down Expand Up @@ -249,8 +249,8 @@
<a href="${replaced_consist.id}.html">
<div class="vehicle-image">
<img src="static/img/${replaced_consist.id}_variant_0_red_white.png"
width="${2 * doc_helper.buy_menu_sprite_width(replaced_consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2 * doc_helper.docs_sprite_width(replaced_consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</div>
${doc_helper.get_replaced_by_name(replaced_consist.id, consists)}
</a>
Expand All @@ -265,8 +265,8 @@
<td style="text-align:center; vertical-align:middle;">
<div class="vehicle-image">
<img src="static/img/${consist.id}_variant_0_red_white.png"
width="${4 * doc_helper.buy_menu_sprite_width(consist)}"
height="${4 * doc_helper.buy_menu_sprite_height}" />
width="${4 * doc_helper.docs_sprite_width(consist)}"
height="${4 * doc_helper.docs_sprite_height}" />
</div>
${doc_helper.unpack_name_string(consist)}
<br />
Expand All @@ -279,8 +279,8 @@
<a href="${consist.replacement_consist.id}.html">
<div class="vehicle-image">
<img src="static/img/${consist.replacement_consist.id}_variant_0_red_white.png"
width="${2* doc_helper.buy_menu_sprite_width(consist.replacement_consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2* doc_helper.docs_sprite_width(consist.replacement_consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</div>
${doc_helper.get_replaced_by_name(consist.replacement_consist.id, consists)}
</a>
Expand All @@ -301,8 +301,8 @@
<a href="${similar_consist.id}.html">
<div class="vehicle-image">
<img src="static/img/${similar_consist.id}_variant_0_red_white.png"
width="${2* doc_helper.buy_menu_sprite_width(similar_consist)}"
height="${2 * doc_helper.buy_menu_sprite_height}" />
width="${2* doc_helper.docs_sprite_width(similar_consist)}"
height="${2 * doc_helper.docs_sprite_height}" />
</div>
${doc_helper.get_replaced_by_name(similar_consist.id, consists)}
</a>
Expand Down
Loading

0 comments on commit 7c4d52b

Please sign in to comment.