From 4d2ea112688c392c9dad435d8ab42f66694e31c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merryweather=20=CE=BC?= Date: Wed, 20 Mar 2024 11:27:13 -0500 Subject: [PATCH] Apply fixes and edits to summon, rearrange and prepare Cargo.toml to 0.3.96 --- Cargo.toml | 6 ++-- examples/temp_check_summon.rs | 17 ++++++++++ src/types/mod.rs | 2 ++ src/types/summons.rs | 64 ++++++++++++++++++++++++++++------- 4 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 examples/temp_check_summon.rs diff --git a/Cargo.toml b/Cargo.toml index e4e7094..2532f84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,12 @@ tokio = { version = "1", features = [ "parking_lot", "rt-multi-thread", ] } -reqwest = { version = "0.11", features = ["json"] } + +reqwest = { version = "0.12", features = ["json"] } serde = { version = "1", features = ["derive"] } +serde-aux = { version = "4.4.0", default-features = false } + html-escape = "0.2" rand = "0.8" @@ -27,7 +30,6 @@ thiserror = "1.0" strum = "0.26" strum_macros = "0.26" -serde-aux = { version = "4.4.0", default-features = false } # futures = "0.3" # chrono = { version = "0.4", features = ["serde"] } diff --git a/examples/temp_check_summon.rs b/examples/temp_check_summon.rs new file mode 100644 index 0000000..ac9f82a --- /dev/null +++ b/examples/temp_check_summon.rs @@ -0,0 +1,17 @@ +use blue_archive::{types::summons::Skill, Language}; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + for summon in blue_archive::fetch_all_summons(Language::English).await? { + println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + println!("Passive Skills for {}", summon.id); + + for skill in summon.skills { + if let Skill::Passive(passive_skill) = skill { + println!("{:#?}", passive_skill.icon()) + } + } + } + + Ok(()) +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 8346b90..26a2c7f 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -287,9 +287,11 @@ pub enum CriticalCheck { pub enum RadiusType { Circle, Bounce, + Fan, } #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] +#[serde(rename_all = "PascalCase")] pub struct Radius { #[serde(alias = "Type")] kind: RadiusType, diff --git a/src/types/summons.rs b/src/types/summons.rs index 1701007..b16acc5 100644 --- a/src/types/summons.rs +++ b/src/types/summons.rs @@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize}; use std::str::FromStr; -use crate::{Armor, BulletType, WeaponType}; +use crate::{Armor, BulletType, WeaponType, IMAGE_DATA_URI}; -use super::{Effect, Radius, SkillKind, ID}; +use super::{Effect, Radius, ID}; #[derive(Debug, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "PascalCase")] @@ -71,27 +71,65 @@ impl Summon { /// **[`Summon`] specific Skills**. #[derive(Debug, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "snake_case", tag = "SkillType")] +#[serde(rename_all = "PascalCase", tag = "SkillType")] pub enum Skill { #[serde(alias = "autoattack")] AutoAttack { - effects: Vec, - radius: Vec, + effects: Option>, + radius: Option>, }, - Normal(CommonSkillDefinition), - Passive(CommonSkillDefinition), + #[serde(alias = "normal")] + Normal(NormalSkill), + #[serde(alias = "passive")] + Passive(PassiveSkill), } #[derive(Debug, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "PascalCase")] -pub struct CommonSkillDefinition { - name: String, +pub struct NormalSkill { + pub name: String, desc: String, parameters: Vec>, - duration: u32, - range: u32, - radius: Vec, + pub duration: Option, + pub range: Option, + pub radius: Option>, icon: String, is_summon_skill: bool, - effects: Vec, + pub effects: Option>, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "PascalCase")] +pub struct PassiveSkill { + pub name: String, + desc: String, + parameters: Vec>, + pub radius: Option>, + icon: String, + pub is_summon_skill: bool, + pub effects: Option>, +} + +impl NormalSkill { + /** The description of a normal skill. */ + pub fn description(&self) -> String { + html_escape::decode_html_entities(&self.desc).into() + } + + /** Gets the icon of this skill represented in a `URI`. */ + pub fn icon(&self) -> String { + format!("{IMAGE_DATA_URI}/skill/{}.webp", self.icon) + } +} + +impl PassiveSkill { + /** The description of a passive skill. */ + pub fn description(&self) -> String { + html_escape::decode_html_entities(&self.desc).into() + } + + /** Gets the icon of this skill represented in a `URI`. */ + pub fn icon(&self) -> String { + format!("{IMAGE_DATA_URI}/skill/{}.webp", self.icon) + } }