microversus_codex 0.1.8

Types and definitions for interfacing with the microversus system
Documentation
use crate::{ItemReward, Reward};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct InventoryLine {
    pub item: String,
    pub item_type: Option<String>,
    pub qty: u32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub weight: Option<f32>,
}

impl Eq for InventoryLine {}

impl From<&Reward> for InventoryLine {
    fn from(value: &Reward) -> Self {
        match value {
            Reward::Junk(item) => Self {
                item: item.name.clone(),
                item_type: value.get_item_type(),
                qty: 1u32,
                weight: None,
            },
            Reward::Treasure(ItemReward {
                name,
                qty,
                total_weight,
            })
            | Reward::TradeItem(ItemReward {
                name,
                qty,
                total_weight,
            }) => Self {
                item: name.clone(),
                item_type: value.get_item_type(),
                qty: *qty,
                weight: Some(*total_weight),
            },
        }
    }
}