aboutsummaryrefslogtreecommitdiff
path: root/src/api/professions.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2019-12-20 18:04:24 +0100
committerDaniel Schadt <kingdread@gmx.de>2019-12-20 18:04:24 +0100
commit9f4a4eaa06f3d0136de9088c0e60a0c077248c91 (patch)
tree4ab0e0c9f5910643ac6404c390e6aa6fad4ca470 /src/api/professions.rs
parent087580b3c269dbc5b2298ff6f4590f010279d339 (diff)
downloadkondou-9f4a4eaa06f3d0136de9088c0e60a0c077248c91.tar.gz
kondou-9f4a4eaa06f3d0136de9088c0e60a0c077248c91.tar.bz2
kondou-9f4a4eaa06f3d0136de9088c0e60a0c077248c91.zip
remove hard coded palette IDs
Now that the API actually returns the proper palette IDs, we can use those values instead of relying on the hard coded values. This also gets rid of the make_table script that was mostly hackish anyway, and the lazy static HashMap.
Diffstat (limited to 'src/api/professions.rs')
-rw-r--r--src/api/professions.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/api/professions.rs b/src/api/professions.rs
index 2716a1a..f3d1f94 100644
--- a/src/api/professions.rs
+++ b/src/api/professions.rs
@@ -4,7 +4,7 @@
//! * [Wiki](https://wiki.guildwars2.com/wiki/API:2/professions)
use super::HasId;
-use serde::{Deserialize, Serialize};
+use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Profession {
@@ -12,10 +12,32 @@ pub struct Profession {
pub id: String,
/// The name of the profession.
pub name: String,
+ /// The numeric code of the profession, e.g. for chat links.
+ pub code: u32,
/// List of specialization ids.
pub specializations: Vec<u32>,
/// List of skills.
pub skills: Vec<Skill>,
+ /// Conversion of palette ID to skill ID.
+ pub skills_by_palette: Vec<PaletteEntry>,
+}
+
+impl Profession {
+ /// Resolves a given palette ID to the corresponding skill ID.
+ pub fn palette_id_to_skill_id(&self, palette_id: u32) -> Option<u32> {
+ self.skills_by_palette
+ .iter()
+ .find(|entry| entry.palette_id == palette_id)
+ .map(|entry| entry.skill_id)
+ }
+
+ /// Resolves a given skill ID to the corresponding palette ID.
+ pub fn skill_id_to_palette_id(&self, skill_id: u32) -> Option<u32> {
+ self.skills_by_palette
+ .iter()
+ .find(|entry| entry.skill_id == skill_id)
+ .map(|entry| entry.palette_id)
+ }
}
impl HasId for Profession {
@@ -34,3 +56,30 @@ pub struct Skill {
#[serde(rename = "type")]
pub typ: String,
}
+
+#[derive(Debug, Clone)]
+pub struct PaletteEntry {
+ /// The palette ID, as used in the chat link.
+ ///
+ /// Note that the actual palette only allows 2 bytes for this number, i.e. an `u16`. To stay
+ /// consistent with other integers that are handled here however, this struct uses a `u32`.
+ pub palette_id: u32,
+ /// The skill ID, as used in the API.
+ pub skill_id: u32,
+}
+
+impl Serialize for PaletteEntry {
+ fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
+ (self.palette_id, self.skill_id).serialize(serializer)
+ }
+}
+
+impl<'de> Deserialize<'de> for PaletteEntry {
+ fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
+ let (palette_id, skill_id) = Deserialize::deserialize(deserializer)?;
+ Ok(PaletteEntry {
+ palette_id,
+ skill_id,
+ })
+ }
+}