sb-api: label helpers wiring + gym/stat_value + policy constants (WI-2, issue #2)

This commit is contained in:
Jan-Peter von Hunnius 2026-10-03 12:08:21 +02:00
parent 5d5a594a7a
commit f0659421e7
7 changed files with 217 additions and 47 deletions

View file

@ -27,6 +27,18 @@ pub enum ItemType {
Material,
}
impl ItemType {
pub fn as_str(&self) -> &'static str {
match self {
ItemType::Weapon => "weapon",
ItemType::Armor => "armor",
ItemType::Accessory => "accessory",
ItemType::Consumable => "consumable",
ItemType::Material => "material",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum AttackType {
@ -44,3 +56,52 @@ pub enum Quality {
Epic,
Legendary,
}
impl Quality {
pub fn as_str(&self) -> &'static str {
match self {
Quality::Common => "common",
Quality::Uncommon => "uncommon",
Quality::Rare => "rare",
Quality::Epic => "epic",
Quality::Legendary => "legendary",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn item_type_as_str_matches_serde_wire() {
for variant in [
ItemType::Weapon,
ItemType::Armor,
ItemType::Accessory,
ItemType::Consumable,
ItemType::Material,
] {
assert_eq!(
serde_json::to_value(&variant).unwrap(),
serde_json::json!(variant.as_str())
);
}
}
#[test]
fn quality_as_str_matches_serde_wire() {
for variant in [
Quality::Common,
Quality::Uncommon,
Quality::Rare,
Quality::Epic,
Quality::Legendary,
] {
assert_eq!(
serde_json::to_value(&variant).unwrap(),
serde_json::json!(variant.as_str())
);
}
}
}