an http based roguelike rpg about jelqing
Blame: src/game/lube.rs
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 1 | use axum::http::StatusCode; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 2 | use serde_json::json; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 3 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 4 | use super::Item; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 5 | use crate::problem::Problem; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 6 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 7 | pub const LUBRICANTS: [&str; 5] = [ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 8 | "application/baby-oil", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 9 | "application/coconut-oil", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 10 | "application/lotion", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 11 | "application/vaseline", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | "text/plain; charset=spit", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | ]; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 14 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 16 | pub enum Lube { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | BabyOil, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | CoconutOil, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 19 | Lotion, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | Vaseline, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | Spit, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 23 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 24 | impl Lube { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | pub fn from_content_type(content_type: Option<&str>) -> Result<Option<Self>, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 26 | let Some(raw) = content_type else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 27 | return Ok(None); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 28 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 29 | let lowered = raw.to_ascii_lowercase(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 30 | let mut parts = lowered.split(';').map(str::trim); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | let essence = parts.next().unwrap_or_default(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 32 | let spit = parts.any(|p| p.replace(' ', "") == "charset=spit"); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 33 | match essence { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 34 | "application/baby-oil" => Ok(Some(Self::BabyOil)), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 35 | "application/coconut-oil" => Ok(Some(Self::CoconutOil)), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 36 | "application/lotion" => Ok(Some(Self::Lotion)), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 37 | "application/vaseline" => Ok(Some(Self::Vaseline)), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 38 | "text/plain" if spit => Ok(Some(Self::Spit)), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 39 | e if e.starts_with("image/") || e.starts_with("video/") => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 41 | "no", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | "No.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 43 | )), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | _ => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 46 | "unsupported-lubricant", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | format!("{essence} is not a lubricant."), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | .with("lubricants", json!(LUBRICANTS))), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 52 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | pub fn modifier(self) -> i32 { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | match self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | Self::BabyOil => 1, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | Self::CoconutOil => 3, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | Self::Lotion => 0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | Self::Vaseline => 2, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | Self::Spit => -2, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 60 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 61 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 62 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 63 | /// The bottle this lube comes in. Spit has none and never runs out. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 64 | pub fn item(self) -> Option<Item> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 65 | match self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 66 | Self::Spit => None, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 67 | Self::BabyOil => Some(Item::BabyOil), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 68 | Self::CoconutOil => Some(Item::CoconutOil), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 69 | Self::Lotion => Some(Item::Lotion), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 70 | Self::Vaseline => Some(Item::Vaseline), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 71 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 72 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 73 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 74 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 75 | #[derive(Clone, Copy)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 76 | pub enum LubeRule { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 77 | Required, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 78 | Forbidden, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 79 | Optional, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 80 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 81 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 82 | impl LubeRule { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 83 | pub(super) fn name(self) -> &'static str { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 84 | match self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 85 | Self::Required => "required", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 86 | Self::Forbidden => "forbidden", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 87 | Self::Optional => "optional", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 88 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 89 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 90 | } |