Let a bot take any colour

A bot's identity was one of seven hues, and the hue picked both its colour
and its stone shape. Now its colour is free and its stone is its own:

- `bots.color` holds any `#rrggbb`, `bots.stone` the flat-cut shape it's
  drawn on. `bots.hue` stays as the palette column they replaced, read only
  as a fallback; `src/scripts/move-bot-colour-to-owners.ts` backfills an
  install from it (safe to rerun).
- `src/utils/bot-color.ts` is the only place a colour is validated or
  resolved (`resolveBotColor`/`resolveBotStone` carry the old hue forward,
  `botColorNeedsPaperFace` flips the eyes to paper on a very dark body), and
  `src/utils/bot-stone-props.ts` gives every row its props, so a row saved
  before this still renders as it did.
- `BotStone` takes the colour as the body's SVG `fill`, the one documented
  exception to the token rule: an arbitrary hex has no token to point at.
  `UnreadDot` follows it.
- The picker keeps the palette tiles (still shape and colour together) and
  adds a native swatch and a hex field, so a custom colour keeps its stone.
  Same place as before: the header avatar's modal and Settings > Bots, for
  crew managers. The coordinator stays hue-less.
- A recolour reaches other open tabs through `pushBotUpdated`.
This commit is contained in:
2026-10-22 11:55:36 +01:00
parent 2eccfe9e13
commit 1a6249afd3
59 changed files with 877 additions and 237 deletions
+61
View File
@@ -0,0 +1,61 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_BOTS } from "@/db/types/db";
import { paletteColor } from "@/src/utils/bot-color";
/**
* One-off: bots used to carry a palette `hue`, which decided both their
* colour and their stone shape. They now store a free `color` (`#rrggbb`)
* and their own `stone`, so a bot keeps the shape it always had while the
* user can pick any colour. This fills both from the old hue.
*
* Safe to run more than once: a bot that already has a colour and a stone
* is left alone. Run it with
* `bun src/scripts/move-bot-colour-to-owners.ts`, then it can be deleted
* along with the `hue` column.
*/
async function moveBotColourToOwners() {
const res = await BunSQLite.sql<BUN_SQLITE_COBBLE_BOTS>({
sql: `SELECT id, kind, hue, color, stone FROM bots`,
});
const bots = res.payload || [];
let moved = 0;
for (const bot of bots) {
if (!bot.id) continue;
/** The coordinator stays hue-less, whatever it carried. */
if (bot.kind == "coordinator") {
if (bot.color || bot.stone || bot.hue) {
await BunSQLite.sql({
sql: `UPDATE bots SET color = NULL, stone = 'ember', hue = NULL, updated_at = ? WHERE id = ?`,
values: [Date.now(), bot.id],
});
}
continue;
}
/**
* A bot with a colour has been through this already. A bot without
* one hasn't, so its `stone` is only the column's default and its
* hue is the truth: both come from there.
*/
if (bot.color) continue;
const color = paletteColor({ hue: bot.hue }) || paletteColor({ hue: "ember" })!;
const stone = bot.hue || "ember";
await BunSQLite.sql({
sql: `UPDATE bots SET color = ?, stone = ?, updated_at = ? WHERE id = ?`,
values: [color, stone, Date.now(), bot.id],
});
moved++;
}
console.log(`Done: ${moved} bot(s) given a colour and a stone, ${bots.length} checked.`);
}
await moveBotColourToOwners();
process.exit(0);
+7 -1
View File
@@ -13,6 +13,7 @@ import type {
BotMessageAuthor,
BotTaskStepState,
} from "@/src/dict/bot-dict";
import { paletteColor } from "@/src/utils/bot-color";
import setBotFace from "@/src/functions/backend/db/bots/set-bot-face";
import ensureCoordinatorBot from "@/src/functions/backend/db/bots/ensure-coordinator-bot";
import ensureBotSession from "@/src/functions/backend/db/bot-sessions/ensure-bot-session";
@@ -49,6 +50,10 @@ type SeedTask = {
type SeedBot = {
name: string;
/**
* The palette entry it's drawn with, which gives it both its colour and
* its stone. Null for the coordinator.
*/
hue: BotHue | null;
role: string | null;
face: BotFace;
@@ -221,7 +226,8 @@ async function insertBot({
user_id,
name: bot.name,
kind: bot.hue ? "worker" : "coordinator",
hue: bot.hue || undefined,
color: paletteColor({ hue: bot.hue }) || undefined,
stone: bot.hue || undefined,
role: bot.role || undefined,
},
],