aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-23 20:16:59 +0200
committerDanilo M. <danix@danix.xyz>2026-10-23 20:16:59 +0200
commit2b934e4c6d83fafd418aa0f1940f31925ae63068 (patch)
tree7db2fb9c7ca7f896f40588a33fe1aaea7ffe895a
parent17680b87de53605a53805a7326f2c1f4f92cc99a (diff)
downloadquickshell-2b934e4c6d83fafd418aa0f1940f31925ae63068.tar.gz
quickshell-2b934e4c6d83fafd418aa0f1940f31925ae63068.zip
companion: artist and groove lines
Artist keys match as a case-insensitive substring of the MPRIS artist, so collaborations and feat. credits still hit; the cost is a short key over-matching, marked as a ponytail ceiling. appMap/appList take their defaults so the settings page can serve artists with the same helpers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--desktop/companion/Lines.js64
-rw-r--r--desktop/companion/test_lines.js18
2 files changed, 65 insertions, 17 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,
diff --git a/desktop/companion/test_lines.js b/desktop/companion/test_lines.js
index f70a9ff..72addf2 100644
--- a/desktop/companion/test_lines.js
+++ b/desktop/companion/test_lines.js
@@ -19,7 +19,7 @@ const assert = require("assert");
const src = fs.readFileSync(__dirname + "/Lines.js", "utf8")
.replace(/^\.pragma library$/m, "");
const L = new Function(src +
- "\nreturn { lines, apps, monologue, appMap, appList, pickApp, pick, toMap };")();
+ "\nreturn { lines, apps, artists, monologue, appMap, appList, pickApp, pickArtist, pick, toMap };")();
// The defaults are what she says until a set is saved.
assert.strictEqual(L.pickApp("firefox", null, 0), L.apps.firefox[0]);
@@ -60,4 +60,20 @@ assert.deepStrictEqual(L.toMap([
{ cls: "firefox", lines: ["last"] },
]), { firefox: ["last"] });
+// Artists: a case-insensitive substring of what MPRIS reports, first
+// matching key wins, empty phrases skipped.
+assert.strictEqual(L.pickArtist("Linkin Park", null, 0), L.artists["linkin park"][0]);
+assert.strictEqual(L.pickArtist("LINKIN PARK, Jay-Z", null, 0), L.artists["linkin park"][0]);
+assert.strictEqual(L.pickArtist("Nobody", null, 0), "");
+assert.strictEqual(L.pickArtist("", null, 0), "");
+assert.strictEqual(L.pickArtist("Air, Beck", { air: ["a"], beck: ["b"] }, 0), "a");
+assert.strictEqual(L.pickArtist("Airbourne", { air: ["", "a"] }, 0), "a");
+assert.strictEqual(L.pick("artist:Eminem", 0, null, null), L.artists.eminem[0]);
+assert.strictEqual(L.pick("artist:Eminem", 0, null, { eminem: ["mine"] }), "mine");
+assert.strictEqual(L.pick("groove", 0), L.lines.groove[0]);
+
+// The same list helpers serve the artist set.
+assert.strictEqual(L.appMap(null, L.artists), L.artists);
+assert.strictEqual(L.appList(null, L.artists).length, Object.keys(L.artists).length);
+assert.deepStrictEqual(L.toMap(L.appList(null, L.artists)), L.artists);
console.log("ok");