aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/companion/Lines.js
blob: 6609315c474011810078819ef5fcb3addd579bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

.pragma library

// What she says, in English, grouped by the reaction that says it.
// Companion.qml picks one at random per reaction and keeps to one line in
// 30 s, except for clicks and the self-destruct (Mood.canSpeak).

var lines = {
    shown: ["Glory to mankind.", "2B, reporting.", "...Back on duty."],
    bye: ["2B, signing off.", "Rest while you can.", "Duty complete."],
    bored: ["...Operator, I'm bored.", "Nothing to report.", "Awaiting orders."],
    wake: ["I'm awake.", "Systems online."],
    mock: ["Typo again?", "Delete, delete, delete.", "Were you aiming for that key?"],
    shoved: ["Hey.", "Rude.", "I was standing here."],
    ready: ["Answer's ready.", "Your reply came in."],
    click: ["...Yes?", "Can I help you?"],
    blush: ["S-stop that.", "...Operator."],
    wallpaper: ["...!", "W-what is this?", "I wasn't staring."],
    dodge: ["...Fine.", "I'll move."],
    destruct: ["Self-destruct sequence initiated."],
    aftermath: ["...That was unpleasant."],
};

// The lines for a program she recognizes, by lowercased window class: one is
// said at random when focus moves to it. The settings window's Companion
// phrases page edits them into Prefs.companionApps, which then replaces this
// whole set; a class with no entry says nothing.
var apps = {
    firefox: ["Researching again?", "Don't open too many tabs.", "The Bunker's network is faster."],
    kitty: ["A terminal. Serious work.", "Careful with that rm.", "I'll watch your commands."],
    discord: ["Talking to the Resistance?", "Don't tell them where we are."],
    signal: ["Encrypted. Good."],
    steam: ["Training simulation?", "Don't play all night."],
    gimp: ["Making art?"],
    "com.obsproject.studio": ["Are we recording?", "I'll stay out of frame."],
    "md.obsidian.obsidian": ["Writing a report?", "Taking notes. Good habit."],
    sublime_text: ["Writing code?", "Mind the typos."],
    qtmaildir: ["Any orders from Command?", "Mail. Anything urgent?"],
    "virt-manager": ["More machines?", "Androids running androids."],
    audacious: ["Music. I like this."],
    llamachat: ["Talking to Pod?"],
    qtpass: ["I'm not looking."],
};

// The game's opening, one sentence per bubble.
var monologue = [
    "Everything that lives is designed to end.",
    "We are perpetually trapped in a never-ending spiral of life and death.",
    "Is this a curse?",
    "Or some kind of punishment?",
    "I often think about the god who blessed us with this cryptic puzzle...and wonder if we'll ever get the chance to kill him.",
];

// The app set in effect: saved (Prefs.companionApps) when it is a plain
// object, these otherwise. A malformed saved value must not leave her mute.
function appMap(saved) {
    return saved && typeof saved === "object" && !Array.isArray(saved) ? saved : apps;
}

// The app set as an ordered list of {cls, lines}, for the settings page.
function appList(saved) {
    const m = appMap(saved);
    const keys = Object.keys(m);
    const out = [];
    for (let i = 0; i < keys.length; i++)
        out.push({ cls: keys[i], lines: (m[keys[i]] || []).slice() });
    return out;
}

// A line for an app class, empty strings skipped; "" when the class has none.
function pickApp(cls, saved, roll) {
    const all = appMap(saved)[cls] || [];
    const l = [];
    for (let i = 0; i < all.length; i++)
        if (typeof all[i] === "string" && all[i].trim() !== "") l.push(all[i]);
    return l.length ? l[Math.min(l.length - 1, Math.floor(roll * l.length))] : "";
}

// A line for a reaction kind, or, with an "app:" prefix, for that class.
function pick(kind, roll, saved) {
    if (kind.slice(0, 4) === "app:") return pickApp(kind.slice(4), saved, roll);
    const l = lines[kind] || [];
    return l.length ? l[Math.min(l.length - 1, Math.floor(roll * l.length))] : "";
}

// The page's list back to a map for Prefs: empty classes and phrases dropped,
// the class lowercased (Hyprland reports it that way), a repeated class
// keeping its last entry.
function toMap(list) {
    const m = {};
    for (let i = 0; i < list.length; i++) {
        const cls = String(list[i].cls || "").trim().toLowerCase();
        if (cls === "") continue;
        const src = list[i].lines || [];
        const ls = [];
        for (let j = 0; j < src.length; j++) {
            const s = String(src[j] || "").trim();
            if (s !== "") ls.push(s);
        }
        if (ls.length) m[cls] = ls;
    }
    return m;
}