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.js64
1 files changed, 48 insertions, 16 deletions
diff --git a/desktop/companion/Lines.js b/desktop/companion/Lines.js
index 5e1d2db..77e7a83 100644
--- a/desktop/companion/Lines.js
+++ b/desktop/companion/Lines.js
@@ -24,6 +24,7 @@ var lines = {
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."],
@@ -53,6 +54,17 @@ var apps = {
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.
var monologue = [
"Everything that lives is designed to end.",
@@ -62,15 +74,16 @@ 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.",
];
-// 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;
+// 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);
}
-// The app set as an ordered list of {cls, lines}, for the settings page.
-function appList(saved) {
- const m = appMap(saved);
+// 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++)
@@ -78,20 +91,39 @@ function appList(saved) {
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] || [];
+function nonEmpty(all) {
const l = [];
- for (let i = 0; i < all.length; i++)
+ 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))] : "";
+ 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:" prefix, for that class.
-function pick(kind, roll, saved) {
+// 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);
- const l = lines[kind] || [];
- return l.length ? l[Math.min(l.length - 1, Math.floor(roll * l.length))] : "";
+ 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,