atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
4f54028cba69da7f639027da5dd3ef6190edb2cc
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/http/links.rsRust76 lines2.5 KB
1
use super::{run::RunResource, runs};
2
use crate::{
3
    game::{Branch, Run, SHOP},
4
    link::Link,
5
};
6
7
pub fn header(run: &Run) -> String {
8
    let reach = run.reach();
9
    let mut links = Vec::new();
10
    let resources: [(&str, &RunResource, bool); 15] = [
11
        ("", &runs::RUN, true),
12
        ("floor", &runs::FLOOR, true),
13
        ("length", &runs::LENGTH, true),
14
        ("foreskin", &runs::FORESKIN, reach.foreskin),
15
        ("inventory", &runs::INVENTORY, true),
16
        ("techniques", &runs::TECHNIQUES, true),
17
        ("drawer", &runs::DRAWER, reach.drawer),
18
        ("kitchen", &runs::KITCHEN, reach.kitchen),
19
        ("thread", &runs::THREAD, reach.thread),
20
        ("grip", &runs::GRIP, true),
21
        ("shop", &runs::SHOP, reach.shop),
22
        ("portal", &runs::PORTAL, reach.portal),
23
        ("elder", &runs::ELDER, reach.elder),
24
        ("footage", &runs::FOOTAGE, reach.footage),
25
        ("diagnosis", &runs::DIAGNOSIS, reach.diagnosis),
26
    ];
27
    for (rel, target, _) in resources.iter().filter(|(_, _, relevant)| *relevant) {
28
        let href = if rel.is_empty() {
29
            run.path("")
30
        } else {
31
            run.path(&format!("/{rel}"))
32
        };
33
        let rel = if rel.is_empty() { "run" } else { rel };
34
        links.push(
35
            Link::jelq(&href, rel)
36
                .allow(&target.resource.allow(run))
37
                .to_string(),
38
        );
39
    }
40
    if reach.branch_pending {
41
        for branch in Branch::ALL {
42
            links.push(
43
                Link::jelq(&run.branch_path(branch), "branch")
44
                    .title(branch.title())
45
                    .allow("POST")
46
                    .to_string(),
47
            );
48
        }
49
    }
50
    let run_path = run.path("");
51
    for technique in run.techniques_now() {
52
        let name = technique.name();
53
        links.push(
54
            Link::jelq(&format!("{run_path}?technique={name}"), "technique")
55
                .title(name)
56
                .allow("JELQ")
57
                .lubricant(technique.lubricant())
58
                .intensity(technique.intensity())
59
                .to_string(),
60
        );
61
    }
62
    if reach.shopping {
63
        for item in SHOP {
64
            let Some(price) = run.price(item) else {
65
                continue;
66
            };
67
            links.push(
68
                Link::jelq(&run.shop_path(item), "shop-item")
69
                    .title(&format!("{} for {price}", item.slug()))
70
                    .allow("POST")
71
                    .to_string(),
72
            );
73
        }
74
    }
75
    links.join(", ")
76
}