aboutsummaryrefslogtreecommitdiff
path: root/src/api/professions.rs
diff options
context:
space:
mode:
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,
+ })
+ }
+}