Skip to content

Commit

Permalink
Apply fixes and edits to summon, rearrange and prepare Cargo.toml to …
Browse files Browse the repository at this point in the history
…0.3.96
  • Loading branch information
bibi-reden committed Mar 20, 2024
1 parent b846462 commit 4d2ea11
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
17 changes: 17 additions & 0 deletions examples/temp_check_summon.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
2 changes: 2 additions & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
64 changes: 51 additions & 13 deletions src/types/summons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<Effect>,
radius: Vec<Radius>,
effects: Option<Vec<Effect>>,
radius: Option<Vec<Radius>>,
},
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<Vec<String>>,
duration: u32,
range: u32,
radius: Vec<Radius>,
pub duration: Option<u32>,
pub range: Option<u32>,
pub radius: Option<Vec<Radius>>,
icon: String,
is_summon_skill: bool,
effects: Vec<Effect>,
pub effects: Option<Vec<Effect>>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct PassiveSkill {
pub name: String,
desc: String,
parameters: Vec<Vec<String>>,
pub radius: Option<Vec<Radius>>,
icon: String,
pub is_summon_skill: bool,
pub effects: Option<Vec<Effect>>,
}

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)
}
}

0 comments on commit 4d2ea11

Please sign in to comment.