skara-brae-server/crates/sb-core/src/items.rs
Jan-Peter von Hunnius 6410e0a86d Implement auth, persistence, typed responses, and injectable RNG
Auth: JWT tokens (sb-auth) with argon2 password hashing, login/register
endpoints, Bearer token middleware protecting all routes except auth.
Authorization checks ensure users can only access their own characters.

Persistence: SQLite via rusqlite (sb-db) with write-through on all
mutations. Optional via SB_DB_PATH env var; falls back to in-memory.

Typed responses: ~20 response DTOs in sb-shared replacing ad-hoc JSON.

Combat: Injectable RNG via &mut impl Rng for deterministic tests.

Clean Architecture: Combat types and response DTOs in sb-shared; domain
services in sb-core; auth in sb-auth; persistence in sb-db.
2026-08-09 16:51:52 +02:00

34 lines
970 B
Rust

use sb_shared::Item;
const WEAPONS_JSON: &str =
include_str!("../../../../skara-brae-common/data/items/weapons.json");
const ARMOR_JSON: &str =
include_str!("../../../../skara-brae-common/data/items/armor.json");
const ACCESSORIES_JSON: &str =
include_str!("../../../../skara-brae-common/data/items/accessories.json");
pub fn load_all_items() -> Vec<Item> {
let mut items = Vec::new();
let weapons: Vec<Item> =
serde_json::from_str(WEAPONS_JSON).expect("failed to parse weapons.json");
items.extend(weapons);
let armor: Vec<Item> =
serde_json::from_str(ARMOR_JSON).expect("failed to parse armor.json");
items.extend(armor);
let accessories: Vec<Item> =
serde_json::from_str(ACCESSORIES_JSON).expect("failed to parse accessories.json");
items.extend(accessories);
items
}
pub fn item_price(item: &Item) -> i32 {
item.value
}
pub fn item_sell_price(item: &Item) -> i32 {
item.value / 2
}