aboutsummaryrefslogtreecommitdiff
path: root/src/gamedata.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-05-11 18:26:50 +0200
committerDaniel Schadt <kingdread@gmx.de>2020-05-11 18:26:50 +0200
commit84f9e577cf6bd537baa954684580a8c322724c23 (patch)
treee19671c1d9ba7898b5ded2a100975aab995a7f3b /src/gamedata.rs
parent02647a66181a6abc49c4dda57138e8752d9427d8 (diff)
downloadevtclib-84f9e577cf6bd537baa954684580a8c322724c23.tar.gz
evtclib-84f9e577cf6bd537baa954684580a8c322724c23.tar.bz2
evtclib-84f9e577cf6bd537baa954684580a8c322724c23.zip
add Display implementation for gamedata
This is something that a lot of applications will probably have to implement anyway, so we might as well provide it and do it within Rusts standard traits. This does not provide localization, but it uses the English names, which should be good enough for most cases. Since we provide FromStr for those classes as well, it makes double-sense to add Display. However, not all cases are currently reversible ("Cairn the Indomitable" vs "Cairn"), although the status quo seems fine for now (most people type Cairn, but when outputting we can use the full name).
Diffstat (limited to 'src/gamedata.rs')
-rw-r--r--src/gamedata.rs86
1 files changed, 85 insertions, 1 deletions
diff --git a/src/gamedata.rs b/src/gamedata.rs
index 4fe8fa6..30bbcf6 100644
--- a/src/gamedata.rs
+++ b/src/gamedata.rs
@@ -1,6 +1,9 @@
//! This module contains some low-level game data, such as different boss IDs.
use num_derive::FromPrimitive;
-use std::str::FromStr;
+use std::{
+ fmt::{self, Display, Formatter},
+ str::FromStr,
+};
use thiserror::Error;
/// Enum containing all bosses with their IDs.
@@ -154,6 +157,44 @@ impl FromStr for Boss {
}
}
+impl Display for Boss {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ let name = match *self {
+ Boss::ValeGuardian => "Vale Guardian",
+ Boss::Gorseval => "Gorseval",
+ Boss::Sabetha => "Sabetha",
+ Boss::Slothasor => "Slothasor",
+ Boss::Matthias => "Matthias Gabrel",
+ Boss::KeepConstruct => "Keep Construct",
+ Boss::Xera => "Xera",
+ Boss::Cairn => "Cairn the Indomitable",
+ Boss::MursaatOverseer => "Mursaat Overseer",
+ Boss::Samarog => "Samarog",
+ Boss::Deimos => "Deimos",
+ Boss::SoullessHorror => "Soulless Horror",
+ Boss::Dhuum => "Dhuum",
+ Boss::ConjuredAmalgamate => "Conjured Amalgamate",
+ Boss::LargosTwins => "Twin Largos",
+ Boss::Qadim => "Qadim",
+ Boss::CardinalAdina => "Cardinal Adina",
+ Boss::CardinalSabir => "Cardinal Sabir",
+ Boss::QadimThePeerless => "Qadim the Peerless",
+ Boss::Skorvald => "Skorvald the Shattered",
+ Boss::Artsariiv => "Artsariiv",
+ Boss::Arkk => "Arkk",
+ Boss::MAMA => "MAMA",
+ Boss::Siax => "Siax the Corrupted",
+ Boss::Ensolyss => "Ensolyss of the Endless Torment",
+ Boss::IcebroodConstruct => "Icebrood Construct",
+ Boss::VoiceOfTheFallen => "Super Kodan Brothers",
+ Boss::FraenirOfJormag => "Fraenir of Jormag",
+ Boss::Boneskinner => "Boneskinner",
+ Boss::WhisperOfJormag => "Whisper of Jormag",
+ };
+ write!(f, "{}", name)
+ }
+}
+
/// ID for Xera in the second phase.
///
/// The original Xera will despawn, and after the tower phase, a separate spawn
@@ -227,6 +268,23 @@ impl FromStr for Profession {
}
}
+impl Display for Profession {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ let name = match *self {
+ Profession::Guardian => "Guardian",
+ Profession::Warrior => "Warrior",
+ Profession::Engineer => "Engineer",
+ Profession::Ranger => "Ranger",
+ Profession::Thief => "Thief",
+ Profession::Elementalist => "Elementalist",
+ Profession::Mesmer => "Mesmer",
+ Profession::Necromancer => "Necromancer",
+ Profession::Revenant => "Revenant",
+ };
+ write!(f, "{}", name)
+ }
+}
+
/// Error for when converting a string to an elite specialization fails.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
#[error("Invalid elite specialization identifier: {0}")]
@@ -292,6 +350,32 @@ impl FromStr for EliteSpec {
}
}
+impl Display for EliteSpec {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ let name = match *self {
+ EliteSpec::Dragonhunter => "Dragonhunter",
+ EliteSpec::Berserker => "Berserker",
+ EliteSpec::Scrapper => "Scrapper",
+ EliteSpec::Druid => "Druid",
+ EliteSpec::Daredevil => "Daredevil",
+ EliteSpec::Tempest => "Tempest",
+ EliteSpec::Chronomancer => "Chronomancer",
+ EliteSpec::Reaper => "Reaper",
+ EliteSpec::Herald => "Herald",
+ EliteSpec::Firebrand => "Firebrand",
+ EliteSpec::Spellbreaker => "Spellbreaker",
+ EliteSpec::Holosmith => "Holosmith",
+ EliteSpec::Soulbeast => "Soulbeast",
+ EliteSpec::Deadeye => "Deadeye",
+ EliteSpec::Weaver => "Weaver",
+ EliteSpec::Mirage => "Mirage",
+ EliteSpec::Scourge => "Scourge",
+ EliteSpec::Renegade => "Renegade",
+ };
+ write!(f, "{}", name)
+ }
+}
+
impl EliteSpec {
/// Return the profession that this elite specialization belongs to.
///