aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/companion/Lines.js
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/companion/Lines.js')
-rw-r--r--desktop/companion/Lines.js85
1 files changed, 67 insertions, 18 deletions
diff --git a/desktop/companion/Lines.js b/desktop/companion/Lines.js
index d6450df..8ba5173 100644
--- a/desktop/companion/Lines.js
+++ b/desktop/companion/Lines.js
@@ -28,23 +28,27 @@ var lines = {
dodge: ["...Fine.", "I'll move."],
destruct: ["Self-destruct sequence initiated."],
aftermath: ["...That was unpleasant."],
+};
- // The focused window's class, lowercased, as "app:<class>". A class
- // with no entry says nothing.
- "app:firefox": ["Researching again?", "Don't open too many tabs.", "The Bunker's network is faster."],
- "app:kitty": ["A terminal. Serious work.", "Careful with that rm.", "I'll watch your commands."],
- "app:discord": ["Talking to the Resistance?", "Don't tell them where we are."],
- "app:signal": ["Encrypted. Good."],
- "app:steam": ["Training simulation?", "Don't play all night."],
- "app:gimp": ["Making art?"],
- "app:com.obsproject.studio": ["Are we recording?", "I'll stay out of frame."],
- "app:md.obsidian.obsidian": ["Writing a report?", "Taking notes. Good habit."],
- "app:sublime_text": ["Writing code?", "Mind the typos."],
- "app:qtmaildir": ["Any orders from Command?", "Mail. Anything urgent?"],
- "app:virt-manager": ["More machines?", "Androids running androids."],
- "app:audacious": ["Music. I like this."],
- "app:llamachat": ["Talking to Pod?"],
- "app:qtpass": ["I'm not looking."],
+// 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.
@@ -56,8 +60,53 @@ var monologue = [
"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.",
];
-// A line for kind; roll is Math.random(). "" for a kind with no lines.
-function pick(kind, roll) {
+// 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;
+}