2021-10-04 03:17:09 +00:00
|
|
|
pub mod auto_translate;
|
|
|
|
pub mod duties;
|
|
|
|
pub mod jobs;
|
|
|
|
pub mod roulettes;
|
|
|
|
pub mod territory_names;
|
2021-10-07 04:14:17 +00:00
|
|
|
pub mod treasure_maps;
|
2021-10-04 03:17:09 +00:00
|
|
|
pub mod worlds;
|
|
|
|
|
|
|
|
pub use self::{
|
|
|
|
auto_translate::AUTO_TRANSLATE,
|
|
|
|
duties::DUTIES,
|
|
|
|
jobs::JOBS,
|
|
|
|
roulettes::ROULETTES,
|
|
|
|
territory_names::TERRITORY_NAMES,
|
2021-10-07 04:14:17 +00:00
|
|
|
treasure_maps::TREASURE_MAPS,
|
2021-10-04 03:17:09 +00:00
|
|
|
worlds::WORLDS,
|
|
|
|
};
|
2021-10-10 15:39:45 +00:00
|
|
|
|
|
|
|
use std::{
|
|
|
|
cmp::Ordering,
|
|
|
|
str::FromStr,
|
|
|
|
};
|
|
|
|
|
2021-10-10 17:29:55 +00:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub enum Language {
|
|
|
|
English,
|
|
|
|
Japanese,
|
|
|
|
German,
|
|
|
|
French,
|
2021-10-10 15:39:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 17:29:55 +00:00
|
|
|
impl Language {
|
2021-10-10 17:42:33 +00:00
|
|
|
pub fn code(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Self::English => "en",
|
|
|
|
Self::Japanese => "ja",
|
|
|
|
Self::German => "de",
|
|
|
|
Self::French => "fr",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-10 17:29:55 +00:00
|
|
|
pub fn from_codes(val: Option<&str>) -> Self {
|
|
|
|
let val = match val {
|
|
|
|
Some(v) => v,
|
|
|
|
None => return Self::English,
|
|
|
|
};
|
|
|
|
|
2021-10-10 15:39:45 +00:00
|
|
|
let mut parts: Vec<(&str, f32)> = val.split(',')
|
|
|
|
.map(|part| {
|
|
|
|
let sub_parts: Vec<&str> = part.split(';').collect();
|
|
|
|
if sub_parts.len() == 1 {
|
|
|
|
(sub_parts[0], 1.0)
|
|
|
|
} else if let Ok(val) = f32::from_str(sub_parts[0]) {
|
|
|
|
(sub_parts[0], val)
|
|
|
|
} else {
|
|
|
|
(sub_parts[0], 0.0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
parts.sort_unstable_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(Ordering::Less));
|
|
|
|
if parts.len() == 0 {
|
2021-10-10 17:29:55 +00:00
|
|
|
return Self::English;
|
2021-10-10 15:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (lang, _) in parts {
|
|
|
|
let first = lang.split('-').next().unwrap();
|
|
|
|
match first {
|
2021-10-10 17:29:55 +00:00
|
|
|
"en" => return Self::English,
|
|
|
|
"ja" => return Self::Japanese,
|
|
|
|
"de" => return Self::German,
|
|
|
|
"fr" => return Self::French,
|
2021-10-10 15:39:45 +00:00
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-10 17:29:55 +00:00
|
|
|
Self::English
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct LocalisedText {
|
|
|
|
pub en: &'static str,
|
|
|
|
pub ja: &'static str,
|
|
|
|
pub de: &'static str,
|
|
|
|
pub fr: &'static str,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LocalisedText {
|
|
|
|
pub fn text(&self, lang: &Language) -> &'static str {
|
|
|
|
match lang {
|
|
|
|
Language::English => self.en,
|
|
|
|
Language::Japanese => self.ja,
|
|
|
|
Language::German => self.de,
|
|
|
|
Language::French => self.fr,
|
|
|
|
}
|
2021-10-10 15:39:45 +00:00
|
|
|
}
|
|
|
|
}
|