Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use std::path::Path;
use log::{trace, warn};
use models::enchantment::SkyblockEnchantment;
use models::item::SkyblockItem;
use models::npc::SkyblockNpc;
use models::pet::SkyblockPet;
use models::shop::SkyblockShop;
use models::zone::SkyblockZone;
pub use models::{UpgradeCost, UpgradeType, enchantment, item, pet, recipe};
#[cfg(feature = "python")]
use pyo3::exceptions::PyValueError;
Expand Down Expand Up @@ -43,7 +46,10 @@ struct RepoStructure {
pub struct SkyblockRepo {
pub enchantments: FxHashMap<String, SkyblockEnchantment>,
pub items: FxHashMap<String, SkyblockItem>,
pub npcs: FxHashMap<String, SkyblockNpc>,
pub pets: FxHashMap<String, SkyblockPet>,
pub shops: FxHashMap<String, SkyblockShop>,
pub zones: FxHashMap<String, SkyblockZone>,
}

#[cfg(feature = "python")]
Expand All @@ -68,7 +74,10 @@ impl SkyblockRepo {
let mut repo = Self {
enchantments: FxHashMap::default(),
items: FxHashMap::default(),
npcs: FxHashMap::default(),
pets: FxHashMap::default(),
shops: FxHashMap::default(),
zones: FxHashMap::default(),
};

for path_name in structure.paths.values() {
Expand All @@ -91,11 +100,26 @@ impl SkyblockRepo {
.map_err(|e| PyErr::new::<PyValueError, _>(e.to_string()))?;
repo.items.insert(parsed.internal_id.clone(), parsed);
},
| "npcs" => {
let parsed: SkyblockNpc = serde_json::from_str(&content)
.map_err(|e| PyErr::new::<PyValueError, _>(e.to_string()))?;
repo.npcs.insert(parsed.internal_id.clone(), parsed);
},
| "pets" => {
let parsed: SkyblockPet = serde_json::from_str(&content)
.map_err(|e| PyErr::new::<PyValueError, _>(e.to_string()))?;
repo.pets.insert(parsed.internal_id.clone(), parsed);
},
| "shops" => {
let parsed: SkyblockShop = serde_json::from_str(&content)
.map_err(|e| PyErr::new::<PyValueError, _>(e.to_string()))?;
repo.shops.insert(parsed.internal_id.clone(), parsed);
},
| "zones" => {
let parsed: SkyblockZone = serde_json::from_str(&content)
.map_err(|e| PyErr::new::<PyValueError, _>(e.to_string()))?;
repo.zones.insert(parsed.internal_id.clone(), parsed);
},
| _ => continue,
}
}
Expand Down Expand Up @@ -124,6 +148,16 @@ impl SkyblockRepo {
self.items.get(&id.to_uppercase()).cloned()
}

/// Retrieves an npc by its `internalId`
#[must_use]
#[inline]
pub fn get_npc_by_id(
&self,
id: &str,
) -> Option<SkyblockNpc> {
self.npcs.get(&id.to_uppercase()).cloned()
}

/// Retrieves a pet by its `internalId`
#[must_use]
#[inline]
Expand All @@ -133,6 +167,26 @@ impl SkyblockRepo {
) -> Option<SkyblockPet> {
self.pets.get(&id.to_uppercase()).cloned()
}

/// Retrieves a shop by its `internalId`
#[must_use]
#[inline]
pub fn get_shop_by_id(
&self,
id: &str,
) -> Option<SkyblockShop> {
self.shops.get(&id.to_uppercase()).cloned()
}

/// Retrieves a zone by its `internalId`
#[must_use]
#[inline]
pub fn get_zone_by_id(
&self,
id: &str,
) -> Option<SkyblockZone> {
self.zones.get(&id.to_uppercase()).cloned()
}
}

#[cfg(not(feature = "python"))]
Expand All @@ -144,7 +198,10 @@ impl SkyblockRepo {
let mut repo = Self {
enchantments: FxHashMap::default(),
items: FxHashMap::default(),
npcs: FxHashMap::default(),
pets: FxHashMap::default(),
shops: FxHashMap::default(),
zones: FxHashMap::default(),
};

for path_name in structure.paths.values() {
Expand All @@ -167,10 +224,22 @@ impl SkyblockRepo {
let parsed: SkyblockItem = serde_json::from_str(&content)?;
repo.items.insert(parsed.internal_id.clone(), parsed);
},
| "npcs" => {
let parsed: SkyblockNpc = serde_json::from_str(&content)?;
repo.npcs.insert(parsed.internal_id.clone(), parsed);
},
| "pets" => {
let parsed: SkyblockPet = serde_json::from_str(&content)?;
repo.pets.insert(parsed.internal_id.clone(), parsed);
},
| "shops" => {
let parsed: SkyblockShop = serde_json::from_str(&content)?;
repo.shops.insert(parsed.internal_id.clone(), parsed);
},
| "zones" => {
let parsed: SkyblockZone = serde_json::from_str(&content)?;
repo.zones.insert(parsed.internal_id.clone(), parsed);
},
#[cfg_attr(not(feature = "log"), allow(unused_variables))]
| other => {
#[cfg(feature = "log")]
Expand Down Expand Up @@ -204,6 +273,16 @@ impl SkyblockRepo {
self.items.get(&id.to_uppercase()).cloned()
}

/// Retrieves an npc by its `internalId`
#[must_use]
#[inline]
pub fn get_npc_by_id(
&self,
id: &str,
) -> Option<SkyblockNpc> {
self.npcs.get(&id.to_uppercase()).cloned()
}

/// Retrieves a pet by its `internalId`
#[must_use]
#[inline]
Expand All @@ -213,4 +292,24 @@ impl SkyblockRepo {
) -> Option<SkyblockPet> {
self.pets.get(&id.to_uppercase()).cloned()
}

/// Retrieves a shop by its `internalId`
#[must_use]
#[inline]
pub fn get_shop_by_id(
&self,
id: &str,
) -> Option<SkyblockShop> {
self.shops.get(&id.to_uppercase()).cloned()
}

/// Retrieves a zone by its `internalId`
#[must_use]
#[inline]
pub fn get_zone_by_id(
&self,
id: &str,
) -> Option<SkyblockZone> {
self.zones.get(&id.to_uppercase()).cloned()
}
}
14 changes: 14 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ use serde::{Deserialize, Serialize};

pub mod enchantment;
pub mod item;
pub mod npc;
pub mod pet;
pub mod recipe;
pub mod shop;
pub mod zone;

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "python", pyclass)]
Expand All @@ -23,4 +26,15 @@ pub enum UpgradeType {
Item,
Essence,
Coins,
Pelts,
Motes,
JacobMedal,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "python", pyclass)]
pub struct Coordinates {
pub x: f64,
pub y: f64,
pub z: f64,
}
46 changes: 46 additions & 0 deletions src/models/npc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#[cfg(feature = "python")]
use pyo3::pyclass;
use serde::{Deserialize, Serialize};

use crate::models::Coordinates;

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyclass)]
pub struct SkyblockNpc {
#[serde(default)]
pub internal_id: String,
pub name: Option<String>,
pub flags: Option<NpcFlags>,
pub location: Option<NpcLocation>,
pub visitor: Option<NpcGardenVisitor>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "python", pyclass)]
pub struct NpcFlags {
pub merchant: bool,
pub abiphone: bool,
pub garden: bool,
pub shop: bool,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyclass)]
pub struct NpcLocation {
pub zone: Option<String>,
pub coordinates: Option<Coordinates>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyclass)]
pub struct NpcGardenVisitor {
pub rarity: String,
pub garden_level: u8,
pub desire: Option<String>,
pub bonus: Option<String>,
pub copper: Option<f64>,
pub farming_xp: Option<f64>,
}
31 changes: 31 additions & 0 deletions src/models/shop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::collections::BTreeMap;

#[cfg(feature = "python")]
use pyo3::pyclass;
use serde::{Deserialize, Serialize};

use crate::UpgradeCost;

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyclass)]
pub struct SkyblockShop {
#[serde(default)]
pub internal_id: String,
pub name: Option<String>,
pub source: Option<String>,
#[serde(default)]
pub slots: BTreeMap<String, InventorySlot>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "python", pyclass)]
pub struct InventorySlot {
pub material: Option<String>,
pub name: Option<String>,
pub lore: Option<String>,
#[serde(default)]
pub cost: Vec<UpgradeCost>,
#[serde(default)]
pub output: Vec<UpgradeCost>,
}
34 changes: 34 additions & 0 deletions src/models/zone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[cfg(feature = "python")]
use pyo3::pyclass;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::models::Coordinates;

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "python", pyclass)]
pub struct SkyblockZone {
#[serde(default)]
pub internal_id: String,
pub name: Option<String>,
pub source: Option<String>,
pub discovery_text: Option<String>,
#[serde(default)]
pub npcs: Vec<Value>,
#[serde(default)]
pub mobs: Vec<Value>,
#[serde(default)]
pub mob_drops: Vec<Value>,
#[serde(default)]
pub fairy_souls: Vec<FairySoul>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "python", pyclass)]
pub struct FairySoul {
pub location: Option<String>,
#[serde(default)]
pub number: i32,
pub coordinates: Option<Coordinates>,
}
Loading