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