Skip to content

Commit

Permalink
0.3.96 (#31)
Browse files Browse the repository at this point in the history
* Unfinished skill additions & added methods

- Add some functions for summon.
- Add a new enum type 'None' for WeaponTypes.

* Apply fixes and edits to summon, rearrange and prepare Cargo.toml to 0.3.96
  • Loading branch information
bibi-reden authored Mar 20, 2024
1 parent a154569 commit 0f3461b
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 13 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"] }
8 changes: 6 additions & 2 deletions examples/fetch_summons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ async fn main() -> anyhow::Result<()> {
// Let's iterate over all of them and print out some details...
summons.iter().for_each(|summon| {
println!(
"{} : {} : ammo cost : {}",
summon.id, summon.name, summon.ammo_cost
"{} : {} : Ammo Cost: {} : Weapon: {}, Armor: {}",
summon.id,
summon.name,
summon.ammo_cost,
summon.weapon_type(),
summon.armor()
)
});
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/guessing_game.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use blue_archive::{types::Student, Language};
use blue_archive::Language;
use rand::Rng;

fn read_line_to_buffer(buffer: &mut String) -> Result<usize, std::io::Error> {
Expand Down
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(())
}
5 changes: 5 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ pub enum Club {
* **SG** (Shotgun)
* **SMG** (Submachine Gun)
* **SR** (Sniper RIfle)
* **Cannon**
* **None**
In the case that a weapon type in the data is not present on the wrapper,
a [`WeaponType::Unknown(String)`] is returned to represent the unknown weapon type with its name in the `enum`.
Expand Down Expand Up @@ -383,6 +385,8 @@ pub enum WeaponType {
RG,
/// **`Cannon`**
Cannon,
/// **`None`**
None,
/// An **`unknown`** type that contains the inner value.
Unknown(String),
}
Expand All @@ -403,6 +407,7 @@ impl WeaponType {
Self::SMG => "Submachine Gun",
Self::SR => "Sniper Rifle",
Self::Cannon => "Cannon",
Self::None => "No Weapon",
Self::Unknown(string) => string,
}
.to_string()
Expand Down
15 changes: 15 additions & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,18 @@ pub enum CriticalCheck {
#[serde(other)]
Unknown,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub enum RadiusType {
Circle,
Bounce,
Fan,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Radius {
#[serde(alias = "Type")]
kind: RadiusType,
radius: u32,
}
1 change: 1 addition & 0 deletions src/types/students/student.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub struct Summon {
///
/// There is an issue where Gear in data is represented as `"gear": {}`, therefore this is a mitigation against that.
/// If you have a better implementation of handling this, as in allowing for me to represent the data as an `Option<Gear>`, please send a PR.
/// todo: Could use #[serde(skip_serializing_if = "...")]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum GearKind {
Expand Down
85 changes: 77 additions & 8 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};
use crate::{Armor, BulletType, WeaponType, IMAGE_DATA_URI};

use super::ID;
use super::{Effect, Radius, ID};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
Expand All @@ -19,12 +19,12 @@ pub struct Summon {
pub kind: String,
pub tactic_role: Option<String>,
pub star_bonus: Option<bool>,
pub bullet_type: String,
pub armor_type: String,
bullet_type: String,
armor_type: String,
pub street_battle_adaptation: Option<u8>,
pub outdoor_battle_adaptation: Option<u8>,
pub indoor_battle_adaptation: Option<u8>,
pub weapon_type: Option<String>,
weapon_type: Option<String>,
pub stability_point: u16,
pub stability_rate: Option<u16>,
pub attack_power_1: u16,
Expand All @@ -41,7 +41,7 @@ pub struct Summon {
pub accuracy_point: u16,
pub critical_point: u16,
pub critical_damage_rate: u32,
pub ammo_count: u8,
pub ammo_count: u32,
pub ammo_cost: u8,
pub range: u16,
pub move_speed: u16,
Expand All @@ -58,9 +58,78 @@ impl Summon {
pub fn armor(&self) -> Armor {
Armor::from_str(&self.armor_type).unwrap_or(Armor::Unknown(self.armor_type.clone()))
}

/// Gets the **[`WeaponType`] of the summon.
pub fn weapon_type(&self) -> WeaponType {
match &self.weapon_type {
Some(weapon_type) => WeaponType::from_str(weapon_type)
.unwrap_or(WeaponType::Unknown(weapon_type.clone())),
None => WeaponType::None,
}
}
}

/// **[`Summon`] specific Skills**.
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase", tag = "SkillType")]
pub enum Skill {
#[serde(alias = "autoattack")]
AutoAttack {
effects: Option<Vec<Effect>>,
radius: Option<Vec<Radius>>,
},
#[serde(alias = "normal")]
Normal(NormalSkill),
#[serde(alias = "passive")]
Passive(PassiveSkill),
}

/// **A [`Summon`] specific Skill**.
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct Skill {}
pub struct NormalSkill {
pub name: String,
desc: String,
parameters: Vec<Vec<String>>,
pub duration: Option<u32>,
pub range: Option<u32>,
pub radius: Option<Vec<Radius>>,
icon: String,
is_summon_skill: bool,
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 0f3461b

Please sign in to comment.