atagen

jelq

public

an http based roguelike rpg about jelqing

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