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.js123
1 files changed, 103 insertions, 20 deletions
diff --git a/desktop/companion/Lines.js b/desktop/companion/Lines.js
index d6450df..77e7a83 100644
--- a/desktop/companion/Lines.js
+++ b/desktop/companion/Lines.js
@@ -17,34 +17,52 @@
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."],
+ headphones: ["...Good song.", "Music. Finally.", "I'll allow this one.", "Louder."],
+ groove: ["This one's good.", "...Don't tell 9S.", "Again. Play it again."],
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 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 an artist she knows, keyed by a lowercased name matched as
+// a substring of the reported artist, so "daft punk" also catches
+// collaborations. The Companion artists page edits them into
+// Prefs.companionArtists, which then replaces this whole set.
+var artists = {
+ "linkin park": ["In the end, it doesn't even matter.", "Crawling in my skin... I know this one."],
+ "evanescence": ["Wake me up inside. ...Operator, don't laugh."],
+ "gigi d'agostino": ["L'amour toujours. I'll fly with you.", "...My feet are moving on their own."],
+ "eminem": ["Lose yourself. Understood.", "He talks faster than Pod."],
};
// The game's opening, one sentence per bubble.
@@ -56,8 +74,73 @@ 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) {
- const l = lines[kind] || [];
- return l.length ? l[Math.min(l.length - 1, Math.floor(roll * l.length))] : "";
+// A set in effect: saved when it is a plain object, the defaults (apps
+// unless given) otherwise. A malformed saved value must not leave her mute.
+function appMap(saved, defaults) {
+ return saved && typeof saved === "object" && !Array.isArray(saved) ? saved : (defaults || apps);
+}
+
+// A set as an ordered list of {cls, lines}, for the settings pages; cls is
+// the key, a window class or an artist.
+function appList(saved, defaults) {
+ const m = appMap(saved, defaults);
+ 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;
+}
+
+function nonEmpty(all) {
+ const l = [];
+ for (let i = 0; i < (all || []).length; i++)
+ if (typeof all[i] === "string" && all[i].trim() !== "") l.push(all[i]);
+ return l;
+}
+
+function at(l, roll) { return l.length ? l[Math.min(l.length - 1, Math.floor(roll * l.length))] : ""; }
+
+// A line for an app class, empty strings skipped; "" when the class has none.
+function pickApp(cls, saved, roll) { return at(nonEmpty(appMap(saved)[cls]), roll); }
+
+// A line for the playing artist: the first key that is a case-insensitive
+// substring of it and has a non-empty line. ponytail: substring, so a
+// short key like "air" also matches "Airbourne"; whole words if that bites.
+function pickArtist(artist, saved, roll) {
+ const a = String(artist || "").toLowerCase();
+ if (a === "") return "";
+ const m = appMap(saved, artists);
+ const keys = Object.keys(m);
+ for (let i = 0; i < keys.length; i++) {
+ const l = nonEmpty(m[keys[i]]);
+ if (keys[i] !== "" && l.length && a.indexOf(keys[i].toLowerCase()) !== -1) return at(l, roll);
+ }
+ return "";
+}
+
+// A line for a reaction kind, or, with an "app:" or "artist:" prefix, for
+// that class or artist.
+function pick(kind, roll, saved, savedArtists) {
+ if (kind.slice(0, 4) === "app:") return pickApp(kind.slice(4), saved, roll);
+ if (kind.slice(0, 7) === "artist:") return pickArtist(kind.slice(7), savedArtists, roll);
+ return at(lines[kind] || [], roll);
+}
+
+// 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;
}