Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
🐛 Check the vehicle translation is not the key itself
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Jun 30, 2023
1 parent 6d407d0 commit 96cadee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
25 changes: 19 additions & 6 deletions src/tankopedia/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub struct BundleTankopedia {
/// Bundle the first vehicle from each nation (for testing and debugging).
#[clap(long)]
take_one: bool,

/// Skip saving the images, when only detail correction is needed.
/// At the moment, it does not skip reading the images (TODO).
#[clap(long)]
skip_images: bool,
}

impl BundleTankopedia {
Expand Down Expand Up @@ -88,9 +93,12 @@ impl BundleTankopedia {
writeln!(&mut module, "pub static TANKOPEDIA: Map<u16, Vehicle> = phf_map! {{")?;
for (xml_details, json_details, image) in vehicles {
info!(json_details.tank_id, json_details.user_string, "📦 Saving…");
let short_user_string_key = xml_details.short_user_string_key();
let name = translations
// Take the short name from the client.
.get(&xml_details.short_user_string())
.get(&short_user_string_key)
// Ehm… sometimes the translation is the key itself, which doesn't make any sense.
.filter(|translation| translation != &&short_user_string_key)
// Fall back to the long name from the API.
.unwrap_or(&json_details.user_string);

Expand All @@ -111,8 +119,11 @@ impl BundleTankopedia {
)?;
writeln!(&mut module, r#" }},"#)?;

let path = vendored_path.join(json_details.tank_id.to_string()).with_extension("webp");
spawn_blocking(move || image.save(path)).await??;
if !self.skip_images {
let path =
vendored_path.join(json_details.tank_id.to_string()).with_extension("webp");
spawn_blocking(move || image.save(path)).await??;
}
}
writeln!(&mut module, "}};")?;

Expand Down Expand Up @@ -282,7 +293,9 @@ struct VehicleJsonDetails {
#[serde(rename = "type_slug")]
type_: VehicleType,

/// This is a display name, not a translation key.
user_string: String,

image_url: String,
is_premium: bool,
is_collectible: bool,
Expand Down Expand Up @@ -338,14 +351,14 @@ struct ResourcesPath {
struct VehicleXmlDetails {
/// Example: `#ussr_vehicles:T-34`.
#[serde(rename = "userString")]
user_string: String,
user_string_key: String,
}

impl VehicleXmlDetails {
/// Get the translation key for the shortened vehicle name.
/// This name is what you see in the vehicle ribbon in the game client.
#[inline]
pub fn short_user_string(&self) -> String {
format!("{}_short", self.user_string)
pub fn short_user_string_key(&self) -> String {
format!("{}_short", self.user_string_key)
}
}
6 changes: 3 additions & 3 deletions src/tankopedia/vendored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ pub static TANKOPEDIA: Map<u16, Vehicle> = phf_map! {
},
4609_u16 => Vehicle {
tank_id: 4609,
name: "#ussr_vehicles:T-26_short",
name: "T-26",
tier: 1,
type_: Light,
availability: Researchable,
Expand Down Expand Up @@ -3295,7 +3295,7 @@ pub static TANKOPEDIA: Map<u16, Vehicle> = phf_map! {
},
19201_u16 => Vehicle {
tank_id: 19201,
name: "#ussr_vehicles:T-26_short",
name: "T-26",
tier: 1,
type_: Light,
availability: Researchable,
Expand Down Expand Up @@ -3335,7 +3335,7 @@ pub static TANKOPEDIA: Map<u16, Vehicle> = phf_map! {
},
19457_u16 => Vehicle {
tank_id: 19457,
name: "#ussr_vehicles:T-26_short",
name: "T-26",
tier: 1,
type_: Light,
availability: Researchable,
Expand Down

0 comments on commit 96cadee

Please sign in to comment.