@celljs/ta-town 4.11.0 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web/index.js CHANGED
@@ -67,7 +67,7 @@ var PLAY_EN = {
67
67
  togetherAsks: "Asking to join",
68
68
  togetherAccept: "Let in",
69
69
  togetherRefuse: "Refuse",
70
- togetherFriend: "Ta friend",
70
+ togetherFriend: "Friend",
71
71
  togetherRemove: "Take out",
72
72
  togetherMembers: "Members",
73
73
  togetherShare: "Share",
@@ -146,7 +146,7 @@ var PLAY_ZH = {
146
146
  togetherAsks: "申请加入",
147
147
  togetherAccept: "同意",
148
148
  togetherRefuse: "拒绝",
149
- togetherFriend: "Ta 好友",
149
+ togetherFriend: "好友",
150
150
  togetherRemove: "移出",
151
151
  togetherMembers: "成员",
152
152
  togetherShare: "分享",
@@ -166,6 +166,18 @@ var EN = {
166
166
  workshop: "Workshop",
167
167
  park: "Park",
168
168
  meeting: "In #{channel}",
169
+ inRoom: "In the room {room}",
170
+ roomOnline: "{count} online",
171
+ roomOf: "{name}'s room",
172
+ ownRoom: "Your room",
173
+ roomGuest: "Web guest",
174
+ openRoom: "Open room",
175
+ playRoom: "Play together",
176
+ roomQuiet: "Nothing said yet",
177
+ sayInRoom: "Say something in {room}",
178
+ roomDouble: "{name}'s double",
179
+ roomMyDouble: "Your double",
180
+ askDouble: "Ask their double",
169
181
  workingHome: "Working at its desk",
170
182
  workingTask: "Working on {task}",
171
183
  news: "Has something new for you",
@@ -218,7 +230,7 @@ var EN = {
218
230
  hush: "Stop reading",
219
231
  mention: "Mention a member",
220
232
  help: "Town guide",
221
- tipsTouch: "Drag the map, pinch to zoom; the map button (or pinching out all the way) shows the whole town with its mountains, forest, farm and sea, and a tap goes back in there|The gamepad button (or Possess on a card) walks the town in 3D, in the first person, as the one you picked|Tap a resident to see what it does; tap twice to open its conversation|In its card, talk as in a conversation: hold the box (or tap the microphone, then hold) and say it; the answer is read aloud|Eggs are hidden about: try the fountain, the trees, the pond, the cat, the little dinosaur, the mountains, the campfire, the boat, the lighthouse…",
233
+ tipsTouch: "Drag the map, pinch to zoom; the map button (or pinching out all the way) shows the whole town with its mountains, forest, farm and sea, and a tap goes back in there|The gamepad button (or Possess on a card) walks the town in 3D, in the first person, as the one you picked|Tap a resident to see what it does; tap twice to open its conversation|In its card, talk as in a conversation: hold the box (or tap the microphone, then hold) and say it; the answer is read aloud|Your rooms shared with other Ta are the blue-roofed lounges: whoever is online there sits at the table; tap one to read what is said and say something, @ the double of someone to ask it|Eggs are hidden about: try the fountain, the trees, the pond, the cat, the little dinosaur, the mountains, the campfire, the boat, the lighthouse…",
222
234
  tipsKeys: "Arrows or WASD move, + and − zoom, M the whole map|H finds the double, N and P go through the residents, Enter opens, Esc lets go|And they say there is a code…",
223
235
  greetings: "Hi~|Morning!|Busy?|\uD83D\uDC4B|Lunch later?|Nice weather",
224
236
  wishes: "May the specs hold still|May CI stay green|Zero bugs today|Home on time this Friday|Approved at first review|May the coffee stay warm|Merged without conflicts",
@@ -410,6 +422,18 @@ var ZH = {
410
422
  workshop: "任务工坊",
411
423
  park: "公园",
412
424
  meeting: "在 #{channel} 开会",
425
+ inRoom: "在房间「{room}」",
426
+ roomOnline: "{count} 人在线",
427
+ roomOf: "{name}的房间",
428
+ ownRoom: "我建的房间",
429
+ roomGuest: "网页访客",
430
+ openRoom: "打开房间",
431
+ playRoom: "一起玩",
432
+ roomQuiet: "还没有人说话",
433
+ sayInRoom: "在「{room}」说点什么",
434
+ roomDouble: "{name}的分身",
435
+ roomMyDouble: "我的分身",
436
+ askDouble: "问 TA 的分身",
413
437
  workingHome: "在自己桌前干活",
414
438
  workingTask: "在做「{task}」",
415
439
  news: "有新消息等你看",
@@ -462,7 +486,7 @@ var ZH = {
462
486
  hush: "停止朗读",
463
487
  mention: "提及成员",
464
488
  help: "小镇指南",
465
- tipsTouch: "拖动地图,双指缩放;点地图按钮(或双指一直缩小)看全景:雪山、森林、农场和大海一览无余,点哪里就放大到哪里|点手柄按钮(或卡片上的“附身”)附身到选中的居民,以第一人称走进 3D 小镇|点居民看它在做什么,连点两下直接打开对话|卡片里的输入框和对话里的一样:按住输入框(或点麦克风后按住)说话,松开就发出,回答会读给你听|小镇里藏着彩蛋:喷泉、树、池塘、小猫、小恐龙、雪山、篝火、小船、灯塔……都可以点点看",
489
+ tipsTouch: "拖动地图,双指缩放;点地图按钮(或双指一直缩小)看全景:雪山、森林、农场和大海一览无余,点哪里就放大到哪里|点手柄按钮(或卡片上的“附身”)附身到选中的居民,以第一人称走进 3D 小镇|点居民看它在做什么,连点两下直接打开对话|卡片里的输入框和对话里的一样:按住输入框(或点麦克风后按住)说话,松开就发出,回答会读给你听|蓝顶的会客厅是你和别人共用的房间:在线的人坐在桌旁,你的智能体或分身在房间里回答时也会过去;点一下看大家在聊什么、直接说话,@ 某人的分身就是问 TA 的分身|小镇里藏着彩蛋:喷泉、树、池塘、小猫、小恐龙、雪山、篝火、小船、灯塔……都可以点点看",
466
490
  tipsKeys: "方向键或 WASD 移动,+ − 缩放,M 看全景地图|H 找到分身,N / P 切换居民,Enter 打开对话,Esc 取消选择|据说还有一串秘籍……",
467
491
  greetings: "嗨~|早!|在忙啥?|\uD83D\uDC4B|一会儿一起吃饭?|今天天气不错",
468
492
  wishes: "愿需求不再改|愿 CI 常绿|愿今天零 bug|愿周五准时下班|愿代码一次过审|愿咖啡永远热|愿合并没有冲突",
@@ -660,7 +684,8 @@ var EMOJI = {
660
684
  party: "\uD83C\uDF89",
661
685
  beach: "\uD83C\uDFD6️",
662
686
  camp: "\uD83D\uDD25",
663
- listening: "\uD83D\uDC42"
687
+ listening: "\uD83D\uDC42",
688
+ room: "\uD83C\uDF10"
664
689
  };
665
690
  var IDLE = ["☕", "\uD83C\uDF33", "\uD83C\uDFB5", "\uD83D\uDCD6", "\uD83D\uDEB6"];
666
691
  var TownWords;
@@ -692,6 +717,8 @@ var TownWords;
692
717
  switch (resident.activity) {
693
718
  case "meeting":
694
719
  return format(words.meeting, { channel: resident.about ?? "" });
720
+ case "room":
721
+ return format(words.inRoom, { room: resident.about ?? "" });
695
722
  case "working":
696
723
  return resident.about ? format(words.workingTask, { task: resident.about }) : words.workingHome;
697
724
  case "news":
@@ -1027,6 +1054,7 @@ var TownModel;
1027
1054
  TownModel.homeOf = (agentId) => `home:${agentId}`;
1028
1055
  TownModel.roomOf = (channelId) => `room:${channelId}`;
1029
1056
  TownModel.benchOf = (taskKey) => `bench:${taskKey}`;
1057
+ TownModel.sharedOf = (roomId) => `shared:${roomId}`;
1030
1058
  function benchTasks(tasks, needsLook) {
1031
1059
  const open = tasks.filter((task) => task.status === "running" || task.status === "waiting" || needsLook(task));
1032
1060
  const ended = tasks.filter((task) => !open.includes(task)).sort((a, b) => (b.endedAt ?? b.startedAt) - (a.endedAt ?? a.startedAt)).slice(0, Math.max(0, MAX_BENCHES - open.length));
@@ -1064,6 +1092,15 @@ var TownModel;
1064
1092
  return next;
1065
1093
  };
1066
1094
  const residents = [];
1095
+ const shared = input.rooms ?? [];
1096
+ const inRoom = new Map;
1097
+ for (const room of shared) {
1098
+ for (const id of room.busy) {
1099
+ if (!inRoom.has(id)) {
1100
+ inRoom.set(id, room);
1101
+ }
1102
+ }
1103
+ }
1067
1104
  for (const agent of team.agents) {
1068
1105
  const helper = helperBench.get(agent.id);
1069
1106
  if (!standingIds.has(agent.id) && !helper) {
@@ -1090,6 +1127,10 @@ var TownModel;
1090
1127
  residents.push({ ...base, activity: task?.status === "waiting" ? "waiting" : "idle", place: helper, seat: seat(helper), about: task?.title });
1091
1128
  } else if (input.answering.has(agent.id)) {
1092
1129
  residents.push({ ...base, activity: "working", place: TownModel.homeOf(agent.id), seat: 0 });
1130
+ } else if (inRoom.has(agent.id)) {
1131
+ const room = inRoom.get(agent.id);
1132
+ const place = TownModel.sharedOf(room.id);
1133
+ residents.push({ ...base, activity: "room", place, seat: seat(place), about: room.title });
1093
1134
  } else if (marks[agent.id]) {
1094
1135
  residents.push({ ...base, activity: "news", place: TownModel.homeOf(agent.id), seat: 1 });
1095
1136
  } else {
@@ -1098,6 +1139,24 @@ var TownModel;
1098
1139
  }
1099
1140
  const running = benches.filter((task) => task.status === "running").map((task) => TownModel.benchOf(task.key));
1100
1141
  const attention = !!marks[DOUBLE_ID] || benches.some((task) => task.status === "waiting" || input.needsLook(task));
1142
+ const doubleRoom = input.double.busy ? undefined : inRoom.get(DOUBLE_ID);
1143
+ for (const room of shared) {
1144
+ const place = TownModel.sharedOf(room.id);
1145
+ for (const visitor of room.visitors) {
1146
+ residents.push({
1147
+ id: visitor.id,
1148
+ name: visitor.name,
1149
+ kind: "visitor",
1150
+ face: visitor.face,
1151
+ activity: "room",
1152
+ place,
1153
+ seat: seat(place),
1154
+ about: room.title,
1155
+ line: visitor.line?.text,
1156
+ lineAt: visitor.line?.at
1157
+ });
1158
+ }
1159
+ }
1101
1160
  const double = {
1102
1161
  id: DOUBLE_ID,
1103
1162
  name: input.double.name,
@@ -1109,6 +1168,10 @@ var TownModel;
1109
1168
  line: input.double.line?.text,
1110
1169
  lineAt: input.double.line?.at
1111
1170
  };
1171
+ if (doubleRoom && !attention) {
1172
+ const place = TownModel.sharedOf(doubleRoom.id);
1173
+ Object.assign(double, { activity: "room", place, seat: seat(place), rounds: undefined, about: doubleRoom.title });
1174
+ }
1112
1175
  const leisure = input.now ? leisureAt(input.now) : undefined;
1113
1176
  for (const resident of [double, ...residents]) {
1114
1177
  const free = resident.activity === "idle" && resident.kind !== "helper";
@@ -1131,7 +1194,7 @@ var TownModel;
1131
1194
  });
1132
1195
  }
1133
1196
  }
1134
- const busyAt = (place) => residents.some((each) => each.place === place && (each.activity === "working" || each.activity === "meeting"));
1197
+ const busyAt = (place) => [double, ...residents].some((each) => each.place === place && (each.activity === "working" || each.activity === "meeting" || each.activity === "room" && each.kind !== "visitor"));
1135
1198
  const places = [
1136
1199
  { id: OFFICE_ID, kind: "office", name: input.double.name, state: input.double.busy ? "busy" : attention ? "look" : "quiet" },
1137
1200
  ...ChannelOrder.rooms(rooms).map((channel) => ({
@@ -1140,6 +1203,13 @@ var TownModel;
1140
1203
  name: channel.name,
1141
1204
  state: (working[channel.id]?.length ?? 0) > 0 ? "busy" : "quiet"
1142
1205
  })),
1206
+ ...shared.map((room) => ({
1207
+ id: TownModel.sharedOf(room.id),
1208
+ kind: "room",
1209
+ name: room.title,
1210
+ owner: room.id,
1211
+ state: room.look ? "look" : room.lively || busyAt(TownModel.sharedOf(room.id)) ? "busy" : "quiet"
1212
+ })),
1143
1213
  ...members.map((agent) => ({
1144
1214
  id: TownModel.homeOf(agent.id),
1145
1215
  kind: "home",
@@ -1202,7 +1272,7 @@ var ChannelOrder;
1202
1272
  })(ChannelOrder ||= {});
1203
1273
 
1204
1274
  // web-src/town-data.ts
1205
- var EMPTY = { team: { agents: [], channels: [] }, working: {}, messages: {}, marks: {}, saved: [] };
1275
+ var EMPTY = { team: { agents: [], channels: [] }, working: {}, messages: {}, answered: {}, saved: [] };
1206
1276
  var EVERY_MS = 2500;
1207
1277
  var SAVED_EVERY = 6;
1208
1278
  function useSeen(root) {
@@ -1226,6 +1296,8 @@ function useSeen(root) {
1226
1296
  function useTownData(pi, root) {
1227
1297
  const [data, setData] = React.useState(EMPTY);
1228
1298
  const seen = useSeen(root);
1299
+ const listed = pi.ui.useSavedSessions?.();
1300
+ const follows = !!listed;
1229
1301
  const kept = React.useRef({ json: "", data: EMPTY, round: 0 });
1230
1302
  React.useEffect(() => {
1231
1303
  if (!seen) {
@@ -1238,26 +1310,29 @@ function useTownData(pi, root) {
1238
1310
  });
1239
1311
  const read = async () => {
1240
1312
  const round = kept.current.round++;
1241
- const [team, working, marks, seenTasks] = await Promise.all([
1313
+ const [team, working, answered, seenTasks, agentsSeen] = await Promise.all([
1242
1314
  get("team"),
1243
1315
  get("working"),
1244
- get("ui.agentsToLook"),
1245
- get("ui.seenTasks")
1316
+ get("answered"),
1317
+ get("ui.seenTasks"),
1318
+ get("ui.agentsSeen")
1246
1319
  ]);
1247
1320
  const before = kept.current.data;
1248
1321
  const channels = team?.channels ?? [];
1249
1322
  const messages = {};
1250
1323
  await Promise.all(channels.map(async (channel) => {
1251
- const again = round % SAVED_EVERY === 0 || (working?.[channel.id]?.length ?? 0) > 0 || (before.working[channel.id]?.length ?? 0) > 0 || !before.messages[channel.id];
1252
- messages[channel.id] = again ? await get(`messages/${channel.id}`) ?? [] : before.messages[channel.id];
1324
+ const again2 = round % SAVED_EVERY === 0 || (working?.[channel.id]?.length ?? 0) > 0 || (before.working[channel.id]?.length ?? 0) > 0 || !before.messages[channel.id];
1325
+ messages[channel.id] = again2 ? await get(`messages/${channel.id}`) ?? [] : before.messages[channel.id];
1253
1326
  }));
1254
- const saved = round % SAVED_EVERY === 0 ? await pi.server.listSavedSessions().catch(() => before.saved) : before.saved;
1255
- const next = { team: team ?? EMPTY.team, working: working ?? {}, messages, marks: marks ?? {}, seen: seenTasks, saved };
1327
+ const again = follows ? round === 0 : round % SAVED_EVERY === 0;
1328
+ const saved = again ? await pi.server.listSavedSessions().catch(() => before.saved) : before.saved;
1329
+ const next = { team: team ?? EMPTY.team, working: working ?? {}, messages, answered: answered ?? {}, seen: seenTasks, agentsSeen, saved };
1256
1330
  const json = JSON.stringify([
1257
1331
  next.team,
1258
1332
  next.working,
1259
- next.marks,
1333
+ next.answered,
1260
1334
  next.seen,
1335
+ next.agentsSeen,
1261
1336
  Object.values(messages).map((list) => list.at(-1)?.id),
1262
1337
  saved.length,
1263
1338
  saved[0]?.updatedAt
@@ -1280,9 +1355,41 @@ function useTownData(pi, root) {
1280
1355
  live = false;
1281
1356
  clearTimeout(timer);
1282
1357
  };
1283
- }, [pi, seen]);
1284
- return data;
1358
+ }, [pi, seen, follows]);
1359
+ return React.useMemo(() => listed?.length ? { ...data, saved: [...data.saved, ...listed] } : data, [data, listed]);
1285
1360
  }
1361
+ var TownLook;
1362
+ ((TownLook) => {
1363
+ function marks(agents, sessions, data, busy, double) {
1364
+ const seen = data.agentsSeen;
1365
+ const marks2 = {};
1366
+ if (!seen || !(seen.since > 0)) {
1367
+ return marks2;
1368
+ }
1369
+ const mark = (id, latest, inChannel = 0) => {
1370
+ if (latest !== undefined && latest > Math.max(seen.at[id] ?? seen.since, inChannel)) {
1371
+ marks2[id] = latest;
1372
+ }
1373
+ };
1374
+ for (const agent of agents) {
1375
+ if (!agent.sessionFile || busy.has(agent.id)) {
1376
+ continue;
1377
+ }
1378
+ let latest;
1379
+ for (const session of sessions) {
1380
+ if (session.sessionFile === agent.sessionFile && (session.updatedAt ?? 0) > (latest ?? 0)) {
1381
+ latest = session.updatedAt;
1382
+ }
1383
+ }
1384
+ mark(agent.id, latest, data.answered[agent.id]);
1385
+ }
1386
+ if (!double.busy) {
1387
+ mark(DOUBLE_ID, double.at);
1388
+ }
1389
+ return marks2;
1390
+ }
1391
+ TownLook.marks = marks;
1392
+ })(TownLook ||= {});
1286
1393
  function needsLook(task, seen) {
1287
1394
  if (task.status === "waiting") {
1288
1395
  return true;
@@ -1917,7 +2024,7 @@ class TownMap {
1917
2024
  pond = { x: 0, y: 0, w: 0, h: 0 };
1918
2025
  wilds;
1919
2026
  constructor(places) {
1920
- const rooms = places.filter((place) => place.kind === "meeting");
2027
+ const rooms = places.filter((place) => place.kind === "meeting" || place.kind === "room");
1921
2028
  const homes = places.filter((place) => place.kind === "home");
1922
2029
  const benches = places.filter((place) => place.kind === "bench");
1923
2030
  const office = places.find((place) => place.kind === "office");
@@ -2122,6 +2229,8 @@ class TownMap {
2122
2229
  this.makeOffice(item.id, rect);
2123
2230
  } else if (item.kind === "meeting") {
2124
2231
  this.makeRoom(item.id, rect);
2232
+ } else if (item.kind === "room") {
2233
+ this.makeLounge(item.id, rect);
2125
2234
  } else {
2126
2235
  this.makeHome(item.id, rect);
2127
2236
  }
@@ -2185,6 +2294,27 @@ class TownMap {
2185
2294
  }
2186
2295
  this.spotOf(id, "meeting", rect, seats, [{ x: (i.x + 2) * TILE + 5 * TILE / 2 - 5, y: (i.y + 1) * TILE + 13 }]);
2187
2296
  }
2297
+ makeLounge(id, rect) {
2298
+ const i = this.building(id, "room", rect, Tile.WOOD, "bottom", rect.x + Math.floor(rect.w / 2));
2299
+ this.put({ kind: "rug", x: i.x + 2, y: i.y, w: 5, h: 4, block: false });
2300
+ this.put({ kind: "board", x: rect.x + 3, y: rect.y + 1, w: 5, h: 1, block: false });
2301
+ this.put({ kind: "table", x: i.x + 3, y: i.y + 1, w: 3, h: 2, block: true, place: id });
2302
+ this.put({ kind: "sofa", x: i.x, y: i.y, w: 2, h: 1, block: true });
2303
+ this.put({ kind: "tv", x: i.x + i.w - 1, y: i.y, w: 1, h: 1, block: true });
2304
+ this.put({ kind: "coffee", x: i.x + i.w - 1, y: i.y + 2, w: 1, h: 1, block: true });
2305
+ this.put({ kind: "floorlamp", x: i.x, y: i.y + 2, w: 1, h: 1, block: true });
2306
+ this.put({ kind: "plant", x: i.x, y: i.y + i.h - 1, w: 1, h: 1, block: true });
2307
+ this.put({ kind: "plant", x: i.x + i.w - 1, y: i.y + i.h - 1, w: 1, h: 1, block: true });
2308
+ const seats = [];
2309
+ for (let column = 0;column < 3; column++) {
2310
+ seats.push({ x: i.x + 3 + column, y: i.y, facing: "down", sit: true }, { x: i.x + 3 + column, y: i.y + 3, facing: "up", sit: true });
2311
+ }
2312
+ seats.push({ x: i.x + 2, y: i.y + 1, facing: "right", sit: true }, { x: i.x + 6, y: i.y + 2, facing: "left", sit: true }, { x: i.x + 2, y: i.y + 2, facing: "right", sit: true }, { x: i.x + 6, y: i.y + 1, facing: "left", sit: true });
2313
+ for (const seat of seats) {
2314
+ this.put({ kind: "chair", x: seat.x, y: seat.y, w: 1, h: 1, block: false });
2315
+ }
2316
+ this.spotOf(id, "room", rect, seats, [{ x: (i.x + 3) * TILE + 3 * TILE / 2 - 5, y: (i.y + 1) * TILE + 13 }]);
2317
+ }
2188
2318
  makeHome(id, rect) {
2189
2319
  const i = this.building(id, "home", rect, Tile.WOOD, "bottom", rect.x + Math.floor(rect.w / 2));
2190
2320
  const owner = id;
@@ -2671,7 +2801,8 @@ var RETRIES = 6;
2671
2801
  var TogetherUtil;
2672
2802
  ((TogetherUtil) => {
2673
2803
  function mapOf(model) {
2674
- return { v: 1, places: model.places.map((place, index) => ({ id: place.kind === "office" ? "office" : `${place.kind}:${index}`, kind: place.kind })) };
2804
+ const places = model.places.filter((place) => place.kind !== "room");
2805
+ return { v: 1, places: places.map((place, index) => ({ id: place.kind === "office" ? "office" : `${place.kind}:${index}`, kind: place.kind })) };
2675
2806
  }
2676
2807
  TogetherUtil.mapOf = mapOf;
2677
2808
  function isMap(value) {
@@ -2889,621 +3020,135 @@ class TownTogether {
2889
3020
  }
2890
3021
  }
2891
3022
 
2892
- // web-src/town-camera.ts
2893
- var ZOOMS = [0.5, 1, 1.5, 2, 2.5, 3, 4];
2894
- var SLOP = 6;
2895
- var ACROSS = 28 * 16;
2896
- var ZOOM_MS = 200;
2897
- var FLY_MS = 520;
2898
- var OVERVIEW_ROOM = 0.94;
2899
- var KEY_SPEED = 420;
2900
-
2901
- class Glide {
2902
- static WINDOW_MS = 100;
2903
- static DECAY = 2;
2904
- static STOP = 12;
2905
- static FLICK = 120;
2906
- static MAX = 6000;
2907
- samples = [];
2908
- vx = 0;
2909
- vy = 0;
2910
- get moving() {
2911
- return this.vx !== 0 || this.vy !== 0;
2912
- }
2913
- track(at, x, y) {
2914
- this.samples.push({ at, x, y });
2915
- while (this.samples.length > 2 && at - this.samples[0].at > Glide.WINDOW_MS) {
2916
- this.samples.shift();
2917
- }
2918
- }
2919
- release(at) {
2920
- const first = this.samples[0];
2921
- const last = this.samples[this.samples.length - 1];
2922
- this.samples = [];
2923
- this.stop();
2924
- if (!first || !last || last === first || at - last.at > Glide.WINDOW_MS / 2) {
2925
- return;
2926
- }
2927
- const seconds = Math.max(0.008, (last.at - first.at) / 1000);
2928
- const vx = (last.x - first.x) / seconds;
2929
- const vy = (last.y - first.y) / seconds;
2930
- const speed = Math.hypot(vx, vy);
2931
- if (speed < Glide.FLICK) {
2932
- return;
2933
- }
2934
- const scale = Math.min(1, Glide.MAX / speed);
2935
- this.vx = vx * scale;
2936
- this.vy = vy * scale;
2937
- }
2938
- stop() {
2939
- this.vx = 0;
2940
- this.vy = 0;
2941
- }
2942
- step(seconds) {
2943
- if (!this.moving) {
2944
- return { dx: 0, dy: 0 };
2945
- }
2946
- const keep = Math.exp(-Glide.DECAY * seconds);
2947
- const travel = (1 - keep) / Glide.DECAY;
2948
- const move = { dx: this.vx * travel, dy: this.vy * travel };
2949
- this.vx *= keep;
2950
- this.vy *= keep;
2951
- if (Math.hypot(this.vx, this.vy) < Glide.STOP) {
2952
- this.stop();
2953
- }
2954
- return move;
2955
- }
2956
- reset() {
2957
- this.samples = [];
2958
- this.stop();
2959
- }
3023
+ // web-src/wild-art.ts
3024
+ function rect(g, color, x, y, w = 1, h = 1) {
3025
+ g.fillStyle = color;
3026
+ g.fillRect(x, y, w, h);
2960
3027
  }
2961
- var StageSize;
2962
- ((StageSize) => {
2963
- function next(measured, full, typing) {
2964
- if (!typing) {
2965
- return { size: measured, full: measured };
2966
- }
2967
- if (full && full.width === measured.width) {
2968
- return { size: { width: measured.width, height: Math.max(measured.height, full.height) }, full };
2969
- }
2970
- return { size: measured, full };
2971
- }
2972
- StageSize.next = next;
2973
- })(StageSize ||= {});
2974
-
2975
- class TownCamera {
2976
- scene;
2977
- ratio;
2978
- host;
2979
- following;
2980
- index = 2;
2981
- press;
2982
- pinch;
2983
- glide = new Glide;
2984
- zooming;
2985
- resolution = 0;
2986
- clear;
2987
- before;
2988
- smoothed = false;
2989
- keys;
2990
- constructor(scene, ratio, host) {
2991
- this.scene = scene;
2992
- this.ratio = ratio;
2993
- this.host = host;
3028
+ function disc(g, color, cx, cy, r) {
3029
+ g.fillStyle = color;
3030
+ for (let y = -r;y <= r; y++) {
3031
+ const half = Math.round(Math.sqrt(r * r - y * y));
3032
+ g.fillRect(cx - half, cy + y, half * 2 + 1, 1);
2994
3033
  }
2995
- get camera() {
2996
- return this.scene.cameras.main;
3034
+ }
3035
+ function tri(g, color, cx, top, half, h) {
3036
+ g.fillStyle = color;
3037
+ for (let row = 0;row < h; row++) {
3038
+ const wide = Math.max(1, Math.round((row + 1) / h * half));
3039
+ g.fillRect(cx - wide, top + row, wide * 2, 1);
2997
3040
  }
2998
- listen() {
2999
- const { scene } = this;
3000
- scene.input.addPointer(1);
3001
- scene.scale.on("resize", () => {
3002
- if (this.before) {
3003
- this.fly(this.fitAll(), this.mapMiddle(this.fitAll()), 0);
3004
- } else {
3005
- this.zoomAt(this.camera.zoom, this.scene.scale.width / 2, this.middleY());
3006
- }
3007
- });
3008
- scene.input.on("pointerdown", (pointer) => this.down(pointer));
3009
- scene.input.on("pointermove", (pointer) => this.move(pointer));
3010
- scene.input.on("pointerup", (pointer) => this.up(pointer));
3011
- scene.input.on("wheel", (pointer, _objects, dx, dy) => {
3012
- const event = pointer.event;
3013
- if (event?.ctrlKey || event?.metaKey) {
3014
- this.zoomBy(dy < 0 ? 1 : -1, pointer);
3015
- return;
3041
+ }
3042
+ function shadow(g, x, y, w, h = 3) {
3043
+ g.globalAlpha = 0.18;
3044
+ rect(g, "#000000", x, y, w, h);
3045
+ g.globalAlpha = 1;
3046
+ }
3047
+ function hash(a, b) {
3048
+ let x = Math.imul(a, 374761393) + Math.imul(b, 668265263);
3049
+ x = Math.imul(x ^ x >>> 13, 1274126177);
3050
+ return ((x ^ x >>> 16) >>> 0) / 4294967296;
3051
+ }
3052
+ var PINES = [
3053
+ ["#2f6f4a", "#3f8a5a", "#5aa86e"],
3054
+ ["#2b6646", "#3a7f53", "#53a065"],
3055
+ ["#386e3f", "#4b8c4c", "#6aab5e"]
3056
+ ];
3057
+ var STRIPES = ["#e46b5d", "#4f8fd6", "#f2c14e"];
3058
+ var WildArt;
3059
+ ((WildArt) => {
3060
+ WildArt.FLAT = ["log", "mushroom", "reeds", "towel"];
3061
+ function paint(g, kind, x, y, w, h, v) {
3062
+ switch (kind) {
3063
+ case "pine": {
3064
+ const [dark, mid, light] = PINES[v % PINES.length];
3065
+ shadow(g, x + 7, y + 28, 18);
3066
+ rect(g, "#6b4a32", x + 14, y + 23, 4, 7);
3067
+ for (const [top, half, rows] of [
3068
+ [y + 10, 14, 15],
3069
+ [y + 2, 11, 13],
3070
+ [y - 6, 8, 11]
3071
+ ]) {
3072
+ tri(g, dark, x + 16, top, half, rows);
3073
+ tri(g, mid, x + 15, top + 2, half - 4, rows - 3);
3074
+ rect(g, light, x + 11, top + rows - 5, 3, 1);
3075
+ }
3076
+ return true;
3016
3077
  }
3017
- this.following = undefined;
3018
- this.glide.stop();
3019
- this.camera.scrollX += dx / this.camera.zoom;
3020
- this.camera.scrollY += dy / this.camera.zoom;
3021
- });
3022
- const keyboard = scene.input.keyboard;
3023
- if (keyboard) {
3024
- this.keys = keyboard.addKeys({ up: "UP", down: "DOWN", left: "LEFT", right: "RIGHT", w: "W", a: "A", s: "S", d: "D" }, false);
3025
- keyboard.on("keydown", (event) => {
3026
- if (event.key === "+" || event.key === "=") {
3027
- this.zoomBy(1);
3028
- } else if (event.key === "-" || event.key === "_") {
3029
- this.zoomBy(-1);
3030
- } else if (event.key.toLowerCase() === "m") {
3031
- this.toggleOverview();
3078
+ case "peak": {
3079
+ const far = w >= 8 * 16;
3080
+ const lit = far ? "#c7ccd6" : "#c2bcb0";
3081
+ const dim = far ? "#a7adba" : "#9c968b";
3082
+ const edge = far ? "#959cab" : "#857f74";
3083
+ const cx = x + w / 2;
3084
+ const rows = h - 2;
3085
+ const snow = Math.round(rows * 0.3);
3086
+ for (let row = 0;row < rows; row++) {
3087
+ const jag = Math.round((hash(row, v + 3) - 0.5) * 2);
3088
+ const half = Math.max(1, Math.round((row + 1) / rows * (w / 2 + 4)) + jag);
3089
+ const top = y + 2 + row;
3090
+ const white = row < snow || row < snow + 4 && hash(row, v) < 0.5;
3091
+ rect(g, white ? "#f7f9fc" : lit, cx - half, top, half, 1);
3092
+ rect(g, white ? "#dde4ec" : dim, cx, top, half, 1);
3093
+ rect(g, edge, cx, top, 1, 1);
3032
3094
  }
3033
- });
3034
- }
3035
- }
3036
- step(seconds) {
3037
- const keys = this.keys;
3038
- if (keys) {
3039
- const dx2 = (keys.right.isDown || keys.d.isDown ? 1 : 0) - (keys.left.isDown || keys.a.isDown ? 1 : 0);
3040
- const dy2 = (keys.down.isDown || keys.s.isDown ? 1 : 0) - (keys.up.isDown || keys.w.isDown ? 1 : 0);
3041
- if (dx2 || dy2) {
3042
- const { camera: camera2 } = this;
3043
- const speed = KEY_SPEED * this.ratio * seconds / camera2.zoom;
3044
- this.following = undefined;
3045
- this.glide.stop();
3046
- camera2.scrollX = camera2.clampX(camera2.scrollX + dx2 * speed);
3047
- camera2.scrollY = camera2.clampY(camera2.scrollY + dy2 * speed);
3095
+ for (let index = 0;index < 5; index++) {
3096
+ const sx = Math.round(cx + (hash(index, v + 7) - 0.5) * w * 0.6);
3097
+ const sy = y + 2 + snow + Math.round(hash(index, v + 9) * (rows - snow - 8));
3098
+ rect(g, sx < cx ? dim : edge, sx, sy, 1, 5);
3099
+ }
3100
+ return true;
3048
3101
  }
3049
- }
3050
- if (!this.glide.moving) {
3051
- return;
3052
- }
3053
- const { camera } = this;
3054
- const { dx, dy } = this.glide.step(seconds);
3055
- const before = { x: camera.scrollX, y: camera.scrollY };
3056
- camera.scrollX = camera.clampX(camera.scrollX - dx / camera.zoom);
3057
- camera.scrollY = camera.clampY(camera.scrollY - dy / camera.zoom);
3058
- if (camera.scrollX === before.x) {
3059
- this.glide.vx = 0;
3060
- }
3061
- if (camera.scrollY === before.y) {
3062
- this.glide.vy = 0;
3063
- }
3064
- }
3065
- fit() {
3066
- const width = this.scene.scale.width / this.ratio;
3067
- this.index = TownCamera.nearest(Math.max(1.5, Math.min(3, width / ACROSS)));
3068
- this.zoomAt(this.whole(ZOOMS[this.index]), this.scene.scale.width / 2, this.scene.scale.height / 2);
3069
- }
3070
- zoomBy(change, about) {
3071
- if (this.before) {
3072
- if (change > 0) {
3073
- this.leaveOverview(about && this.camera.getWorldPoint(about.x, about.y));
3102
+ case "falls": {
3103
+ rect(g, "#857f74", x + 4, y, w - 8, 3);
3104
+ rect(g, "#9ad6f0", x + 6, y + 2, w - 12, h - 4);
3105
+ for (let column = 0;column < 5; column++) {
3106
+ rect(g, "#e6f6fd", x + 9 + column * 7, y + 3 + column * 5 % 9, 1, h - 12);
3107
+ }
3108
+ rect(g, "#ffffff", x + 4, y + h - 5, w - 8, 3);
3109
+ rect(g, "#e6f6fd", x + 2, y + h - 3, w - 4, 2);
3110
+ return true;
3074
3111
  }
3075
- return;
3076
- }
3077
- if (change < 0 && this.index === 0) {
3078
- this.toggleOverview();
3079
- return;
3080
- }
3081
- this.index = Math.max(0, Math.min(ZOOMS.length - 1, this.index + change));
3082
- this.settle(this.whole(ZOOMS[this.index]), about?.x ?? this.scene.scale.width / 2, about?.y ?? this.middleY());
3083
- }
3084
- get overviewing() {
3085
- return !!this.before;
3086
- }
3087
- setClear(clear) {
3088
- this.clear = clear;
3089
- if (this.before && !this.zooming) {
3090
- const zoom = this.fitAll();
3091
- this.fly(zoom, this.mapMiddle(zoom), this.host.reduceMotion() ? 0 : ZOOM_MS);
3092
- this.host.overview?.(true, zoom);
3093
- }
3094
- }
3095
- inClear(point) {
3096
- const { camera } = this;
3097
- const y = (point.y - camera.worldView.y) * camera.zoom;
3098
- const x = (point.x - camera.worldView.x) * camera.zoom;
3099
- const { top, bottom } = this.clearView();
3100
- return x >= 0 && x <= this.scene.scale.width && y >= top && y <= bottom;
3101
- }
3102
- toggleOverview() {
3103
- if (this.before) {
3104
- this.leaveOverview();
3105
- return;
3106
- }
3107
- const { camera } = this;
3108
- const mid = camera.midPoint;
3109
- this.before = { zoom: camera.zoom, index: this.index, x: mid.x, y: mid.y - this.below() };
3110
- this.following = undefined;
3111
- this.glide.reset();
3112
- this.zooming?.stop();
3113
- camera.useBounds = false;
3114
- const zoom = this.fitAll();
3115
- this.fly(zoom, this.mapMiddle(zoom), this.host.reduceMotion() ? 0 : FLY_MS);
3116
- this.host.overview?.(true, zoom);
3117
- }
3118
- leaveOverview(point) {
3119
- const before = this.before;
3120
- if (!before) {
3121
- return;
3122
- }
3123
- const zoom = before.zoom;
3124
- const target = point ?? { x: before.x, y: before.y };
3125
- this.endOverview();
3126
- this.index = before.index;
3127
- this.fly(zoom, this.within({ x: target.x, y: target.y + this.offsetAt(zoom) }, zoom), this.host.reduceMotion() ? 0 : FLY_MS, () => {
3128
- this.camera.useBounds = true;
3129
- });
3130
- }
3131
- endOverview() {
3132
- this.before = undefined;
3133
- this.host.overview?.(false, this.camera.zoom);
3134
- }
3135
- within(center2, zoom) {
3136
- const bounds = this.camera.getBounds();
3137
- const half = { x: this.scene.scale.width / zoom / 2, y: this.scene.scale.height / zoom / 2 };
3138
- const clamp = (value, low, high) => low > high ? (low + high) / 2 : Math.max(low, Math.min(high, value));
3139
- return {
3140
- x: clamp(center2.x, bounds.x + half.x, bounds.right - half.x),
3141
- y: clamp(center2.y, bounds.y + half.y, bounds.bottom - half.y)
3142
- };
3143
- }
3144
- fitAll() {
3145
- const { width, height } = this.host.world();
3146
- const { top, bottom } = this.clearView();
3147
- return Math.max(0.05, Math.min(this.scene.scale.width / width, (bottom - top) / height) * OVERVIEW_ROOM);
3148
- }
3149
- mapMiddle(zoom) {
3150
- const { width, height } = this.host.world();
3151
- return { x: width / 2, y: height / 2 + (this.scene.scale.height / 2 - this.middleY()) / zoom };
3152
- }
3153
- fly(zoom, center2, duration, done) {
3154
- const { camera } = this;
3155
- this.zooming?.stop();
3156
- this.zooming = undefined;
3157
- const from = { zoom: camera.zoom, x: camera.midPoint.x, y: camera.midPoint.y };
3158
- const at = (t) => {
3159
- const z = from.zoom * (zoom / from.zoom) ** t;
3160
- const k = from.zoom === zoom ? t : (1 / from.zoom - 1 / z) / (1 / from.zoom - 1 / zoom);
3161
- this.setZoom(z);
3162
- camera.centerOn(from.x + (center2.x - from.x) * k, from.y + (center2.y - from.y) * k);
3163
- };
3164
- if (duration <= 0) {
3165
- at(1);
3166
- done?.();
3167
- return;
3168
- }
3169
- this.zooming = this.scene.tweens.addCounter({
3170
- from: 0,
3171
- to: 1,
3172
- duration,
3173
- ease: "Cubic.easeInOut",
3174
- onUpdate: (tween) => at(tween.getValue() ?? 1),
3175
- onComplete: () => {
3176
- at(1);
3177
- this.zooming = undefined;
3178
- done?.();
3112
+ case "boulder": {
3113
+ shadow(g, x + 2, y + 13, 13);
3114
+ disc(g, "#9d978c", x + 8, y + 9, 6);
3115
+ disc(g, "#b7b1a6", x + 6, y + 7, 3);
3116
+ rect(g, "#857f74", x + 4, y + 14, 9, 1);
3117
+ return true;
3179
3118
  }
3180
- });
3181
- }
3182
- setZoom(zoom) {
3183
- this.camera.setZoom(zoom);
3184
- const smooth = zoom < 1;
3185
- if (smooth !== this.smoothed) {
3186
- this.smoothed = smooth;
3187
- this.host.smooth?.(smooth);
3188
- }
3189
- if (Number.isInteger(zoom) && zoom !== this.resolution) {
3190
- this.resolution = zoom;
3191
- for (const text of this.host.texts()) {
3192
- text.setResolution(zoom);
3119
+ case "tent": {
3120
+ shadow(g, x + 3, y + 28, 42);
3121
+ tri(g, "#e98a4f", x + 24, y + 2, 22, 27);
3122
+ g.save();
3123
+ g.beginPath();
3124
+ g.rect(x + 24, y, 24, 32);
3125
+ g.clip();
3126
+ tri(g, "#c96f3a", x + 24, y + 2, 22, 27);
3127
+ g.restore();
3128
+ tri(g, "#5a3a2a", x + 24, y + 13, 6, 16);
3129
+ rect(g, "#f2c14e", x + 24, y - 2, 1, 5);
3130
+ rect(g, "#e46b5d", x + 25, y - 2, 4, 2);
3131
+ rect(g, "#8a6a48", x, y + 29, 3, 1);
3132
+ rect(g, "#8a6a48", x + 45, y + 29, 3, 1);
3133
+ return true;
3193
3134
  }
3194
- }
3195
- }
3196
- clearView() {
3197
- const height = this.scene.scale.height;
3198
- const clear = this.clear;
3199
- return clear && clear.bottom - clear.top > 40 ? { top: Math.max(0, clear.top), bottom: Math.min(height, clear.bottom) } : { top: 0, bottom: height };
3200
- }
3201
- middleY() {
3202
- const { top, bottom } = this.clearView();
3203
- return (top + bottom) / 2;
3204
- }
3205
- panTo(point, follow) {
3206
- this.following = follow;
3207
- this.glide.stop();
3208
- if (this.before) {
3209
- this.leaveOverview(point);
3210
- this.following = follow;
3211
- return;
3212
- }
3213
- this.camera.pan(point.x, point.y + this.below(), this.host.reduceMotion() ? 0 : 450, "Sine.easeInOut");
3214
- }
3215
- keepOn(point, seconds) {
3216
- const { camera } = this;
3217
- const mid = camera.midPoint;
3218
- const pull = Math.min(1, seconds * 4);
3219
- camera.centerOn(mid.x + (point.x - mid.x) * pull, mid.y + (point.y + this.below() - mid.y) * pull);
3220
- }
3221
- whole(zoom) {
3222
- return Math.max(1, Math.floor(zoom * this.ratio + 0.25));
3223
- }
3224
- zoomAt(zoom, x, y) {
3225
- const { camera } = this;
3226
- const width = camera.width;
3227
- const height = camera.height;
3228
- const worldX = camera.scrollX + width / 2 + (x - width / 2) / camera.zoom;
3229
- const worldY = camera.scrollY + height / 2 + (y - height / 2) / camera.zoom;
3230
- this.setZoom(zoom);
3231
- camera.scrollX = camera.clampX(worldX - width / 2 - (x - width / 2) / zoom);
3232
- camera.scrollY = camera.clampY(worldY - height / 2 - (y - height / 2) / zoom);
3233
- }
3234
- settle(zoom, x, y) {
3235
- this.zooming?.stop();
3236
- this.zooming = undefined;
3237
- const from = this.camera.zoom;
3238
- if (from === zoom || this.host.reduceMotion()) {
3239
- this.zoomAt(zoom, x, y);
3240
- return;
3241
- }
3242
- this.zooming = this.scene.tweens.addCounter({
3243
- from,
3244
- to: zoom,
3245
- duration: ZOOM_MS,
3246
- ease: "Cubic.easeOut",
3247
- onUpdate: (tween) => this.zoomAt(tween.getValue() ?? zoom, x, y),
3248
- onComplete: () => {
3249
- this.zoomAt(zoom, x, y);
3250
- this.zooming = undefined;
3251
- }
3252
- });
3253
- }
3254
- below() {
3255
- return this.offsetAt(this.camera.zoom);
3256
- }
3257
- offsetAt(zoom) {
3258
- const { top, bottom } = this.clearView();
3259
- return (this.scene.scale.height / 2 - (top + (bottom - top) * 0.45)) / zoom;
3260
- }
3261
- touches() {
3262
- return this.scene.input.manager.pointers.filter((each) => each.isDown);
3263
- }
3264
- startPinch(a, b) {
3265
- this.zooming?.stop();
3266
- this.zooming = undefined;
3267
- if (this.before) {
3268
- this.endOverview();
3269
- this.camera.useBounds = true;
3270
- }
3271
- this.pinch = { distance: Math.max(1, Math.hypot(a.x - b.x, a.y - b.y)), zoom: this.camera.zoom, x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
3272
- this.press = undefined;
3273
- this.following = undefined;
3274
- this.glide.reset();
3275
- }
3276
- startPress(pointer, moved, caught) {
3277
- const { camera } = this;
3278
- this.press = { x: pointer.x, y: pointer.y, sx: camera.scrollX, sy: camera.scrollY, moved, caught };
3279
- this.glide.reset();
3280
- this.glide.track(performance.now(), pointer.x, pointer.y);
3281
- }
3282
- down(pointer) {
3283
- const touches = this.touches();
3284
- if (touches.length >= 2) {
3285
- this.startPinch(touches[0], touches[1]);
3286
- return;
3287
- }
3288
- const caught = this.glide.moving || !!this.zooming;
3289
- this.camera.panEffect.reset();
3290
- this.startPress(pointer, false, caught);
3291
- }
3292
- move(pointer) {
3293
- const { camera } = this;
3294
- if (this.pinch) {
3295
- const touches = this.touches();
3296
- if (touches.length >= 2) {
3297
- const [a, b] = touches;
3298
- const { pinch } = this;
3299
- const zoom = Math.max(Math.min(this.whole(ZOOMS[0]), this.fitAll()), Math.min(this.whole(ZOOMS[ZOOMS.length - 1]), pinch.zoom * Math.hypot(a.x - b.x, a.y - b.y) / pinch.distance));
3300
- const x = (a.x + b.x) / 2;
3301
- const y = (a.y + b.y) / 2;
3302
- this.zoomAt(zoom, pinch.x, pinch.y);
3303
- camera.scrollX = camera.clampX(camera.scrollX - (x - pinch.x) / zoom);
3304
- camera.scrollY = camera.clampY(camera.scrollY - (y - pinch.y) / zoom);
3305
- pinch.x = x;
3306
- pinch.y = y;
3307
- }
3308
- return;
3309
- }
3310
- const { press } = this;
3311
- if (press && pointer.isDown) {
3312
- this.glide.track(performance.now(), pointer.x, pointer.y);
3313
- if (!press.moved) {
3314
- if (Math.hypot(pointer.x - press.x, pointer.y - press.y) <= SLOP * this.ratio) {
3315
- return;
3316
- }
3317
- press.moved = true;
3318
- press.x = pointer.x;
3319
- press.y = pointer.y;
3320
- press.sx = camera.scrollX;
3321
- press.sy = camera.scrollY;
3322
- this.following = undefined;
3323
- return;
3324
- }
3325
- camera.scrollX = press.sx - (pointer.x - press.x) / camera.zoom;
3326
- camera.scrollY = press.sy - (pointer.y - press.y) / camera.zoom;
3327
- return;
3328
- }
3329
- if (!pointer.wasTouch) {
3330
- this.scene.input.setDefaultCursor(this.host.hit(camera.getWorldPoint(pointer.x, pointer.y)) ? "pointer" : "default");
3331
- }
3332
- }
3333
- up(pointer) {
3334
- if (this.pinch) {
3335
- const { pinch } = this;
3336
- const left = this.touches();
3337
- this.pinch = undefined;
3338
- if (this.camera.zoom < this.whole(ZOOMS[0]) * 0.8 && left.length === 0) {
3339
- this.index = 0;
3340
- this.toggleOverview();
3341
- if (this.before) {
3342
- this.before = { ...this.before, zoom: this.whole(ZOOMS[0]), index: 0 };
3343
- }
3344
- return;
3345
- }
3346
- this.index = TownCamera.nearest(this.camera.zoom / this.ratio);
3347
- this.settle(this.whole(ZOOMS[this.index]), pinch.x, pinch.y);
3348
- if (left.length === 1) {
3349
- this.startPress(left[0], true, true);
3350
- }
3351
- return;
3352
- }
3353
- const { press } = this;
3354
- this.press = undefined;
3355
- if (!press) {
3356
- return;
3357
- }
3358
- if (press.moved) {
3359
- this.glide.release(performance.now());
3360
- return;
3361
- }
3362
- this.glide.reset();
3363
- if (!press.caught) {
3364
- this.host.tap(this.camera.getWorldPoint(pointer.x, pointer.y));
3365
- }
3366
- }
3367
- static nearest(zoom) {
3368
- let best = 0;
3369
- ZOOMS.forEach((each, index) => {
3370
- if (Math.abs(each - zoom) < Math.abs(ZOOMS[best] - zoom)) {
3371
- best = index;
3372
- }
3373
- });
3374
- return best;
3375
- }
3376
- }
3377
-
3378
- // web-src/wild-art.ts
3379
- function rect(g, color, x, y, w = 1, h = 1) {
3380
- g.fillStyle = color;
3381
- g.fillRect(x, y, w, h);
3382
- }
3383
- function disc(g, color, cx, cy, r) {
3384
- g.fillStyle = color;
3385
- for (let y = -r;y <= r; y++) {
3386
- const half = Math.round(Math.sqrt(r * r - y * y));
3387
- g.fillRect(cx - half, cy + y, half * 2 + 1, 1);
3388
- }
3389
- }
3390
- function tri(g, color, cx, top, half, h) {
3391
- g.fillStyle = color;
3392
- for (let row = 0;row < h; row++) {
3393
- const wide = Math.max(1, Math.round((row + 1) / h * half));
3394
- g.fillRect(cx - wide, top + row, wide * 2, 1);
3395
- }
3396
- }
3397
- function shadow(g, x, y, w, h = 3) {
3398
- g.globalAlpha = 0.18;
3399
- rect(g, "#000000", x, y, w, h);
3400
- g.globalAlpha = 1;
3401
- }
3402
- function hash(a, b) {
3403
- let x = Math.imul(a, 374761393) + Math.imul(b, 668265263);
3404
- x = Math.imul(x ^ x >>> 13, 1274126177);
3405
- return ((x ^ x >>> 16) >>> 0) / 4294967296;
3406
- }
3407
- var PINES = [
3408
- ["#2f6f4a", "#3f8a5a", "#5aa86e"],
3409
- ["#2b6646", "#3a7f53", "#53a065"],
3410
- ["#386e3f", "#4b8c4c", "#6aab5e"]
3411
- ];
3412
- var STRIPES = ["#e46b5d", "#4f8fd6", "#f2c14e"];
3413
- var WildArt;
3414
- ((WildArt) => {
3415
- WildArt.FLAT = ["log", "mushroom", "reeds", "towel"];
3416
- function paint(g, kind, x, y, w, h, v) {
3417
- switch (kind) {
3418
- case "pine": {
3419
- const [dark, mid, light] = PINES[v % PINES.length];
3420
- shadow(g, x + 7, y + 28, 18);
3421
- rect(g, "#6b4a32", x + 14, y + 23, 4, 7);
3422
- for (const [top, half, rows] of [
3423
- [y + 10, 14, 15],
3424
- [y + 2, 11, 13],
3425
- [y - 6, 8, 11]
3426
- ]) {
3427
- tri(g, dark, x + 16, top, half, rows);
3428
- tri(g, mid, x + 15, top + 2, half - 4, rows - 3);
3429
- rect(g, light, x + 11, top + rows - 5, 3, 1);
3430
- }
3431
- return true;
3432
- }
3433
- case "peak": {
3434
- const far = w >= 8 * 16;
3435
- const lit = far ? "#c7ccd6" : "#c2bcb0";
3436
- const dim = far ? "#a7adba" : "#9c968b";
3437
- const edge = far ? "#959cab" : "#857f74";
3438
- const cx = x + w / 2;
3439
- const rows = h - 2;
3440
- const snow = Math.round(rows * 0.3);
3441
- for (let row = 0;row < rows; row++) {
3442
- const jag = Math.round((hash(row, v + 3) - 0.5) * 2);
3443
- const half = Math.max(1, Math.round((row + 1) / rows * (w / 2 + 4)) + jag);
3444
- const top = y + 2 + row;
3445
- const white = row < snow || row < snow + 4 && hash(row, v) < 0.5;
3446
- rect(g, white ? "#f7f9fc" : lit, cx - half, top, half, 1);
3447
- rect(g, white ? "#dde4ec" : dim, cx, top, half, 1);
3448
- rect(g, edge, cx, top, 1, 1);
3449
- }
3450
- for (let index = 0;index < 5; index++) {
3451
- const sx = Math.round(cx + (hash(index, v + 7) - 0.5) * w * 0.6);
3452
- const sy = y + 2 + snow + Math.round(hash(index, v + 9) * (rows - snow - 8));
3453
- rect(g, sx < cx ? dim : edge, sx, sy, 1, 5);
3454
- }
3455
- return true;
3456
- }
3457
- case "falls": {
3458
- rect(g, "#857f74", x + 4, y, w - 8, 3);
3459
- rect(g, "#9ad6f0", x + 6, y + 2, w - 12, h - 4);
3460
- for (let column = 0;column < 5; column++) {
3461
- rect(g, "#e6f6fd", x + 9 + column * 7, y + 3 + column * 5 % 9, 1, h - 12);
3462
- }
3463
- rect(g, "#ffffff", x + 4, y + h - 5, w - 8, 3);
3464
- rect(g, "#e6f6fd", x + 2, y + h - 3, w - 4, 2);
3465
- return true;
3466
- }
3467
- case "boulder": {
3468
- shadow(g, x + 2, y + 13, 13);
3469
- disc(g, "#9d978c", x + 8, y + 9, 6);
3470
- disc(g, "#b7b1a6", x + 6, y + 7, 3);
3471
- rect(g, "#857f74", x + 4, y + 14, 9, 1);
3472
- return true;
3473
- }
3474
- case "tent": {
3475
- shadow(g, x + 3, y + 28, 42);
3476
- tri(g, "#e98a4f", x + 24, y + 2, 22, 27);
3477
- g.save();
3478
- g.beginPath();
3479
- g.rect(x + 24, y, 24, 32);
3480
- g.clip();
3481
- tri(g, "#c96f3a", x + 24, y + 2, 22, 27);
3482
- g.restore();
3483
- tri(g, "#5a3a2a", x + 24, y + 13, 6, 16);
3484
- rect(g, "#f2c14e", x + 24, y - 2, 1, 5);
3485
- rect(g, "#e46b5d", x + 25, y - 2, 4, 2);
3486
- rect(g, "#8a6a48", x, y + 29, 3, 1);
3487
- rect(g, "#8a6a48", x + 45, y + 29, 3, 1);
3488
- return true;
3489
- }
3490
- case "campfire": {
3491
- for (const [sx, sy] of [
3492
- [2, 9],
3493
- [5, 12],
3494
- [10, 12],
3495
- [13, 9],
3496
- [4, 6],
3497
- [11, 6]
3498
- ]) {
3499
- rect(g, "#8f897f", x + sx, y + sy, 3, 2);
3500
- rect(g, "#aaa498", x + sx, y + sy, 2, 1);
3501
- }
3502
- rect(g, "#7d5a3c", x + 4, y + 9, 8, 2);
3503
- rect(g, "#6b4a32", x + 7, y + 6, 2, 6);
3504
- rect(g, "#e46b5d", x + 6, y + 8, 4, 2);
3505
- rect(g, "#f2c14e", x + 7, y + 8, 2, 1);
3506
- return true;
3135
+ case "campfire": {
3136
+ for (const [sx, sy] of [
3137
+ [2, 9],
3138
+ [5, 12],
3139
+ [10, 12],
3140
+ [13, 9],
3141
+ [4, 6],
3142
+ [11, 6]
3143
+ ]) {
3144
+ rect(g, "#8f897f", x + sx, y + sy, 3, 2);
3145
+ rect(g, "#aaa498", x + sx, y + sy, 2, 1);
3146
+ }
3147
+ rect(g, "#7d5a3c", x + 4, y + 9, 8, 2);
3148
+ rect(g, "#6b4a32", x + 7, y + 6, 2, 6);
3149
+ rect(g, "#e46b5d", x + 6, y + 8, 4, 2);
3150
+ rect(g, "#f2c14e", x + 7, y + 8, 2, 1);
3151
+ return true;
3507
3152
  }
3508
3153
  case "log": {
3509
3154
  rect(g, "#8a5f3c", x + 2, y + 9, 12, 5);
@@ -3667,768 +3312,1741 @@ var WildArt;
3667
3312
  rect(g, "#f4ece0", x + 29 + step, y + 37 + step, 2, 1);
3668
3313
  rect(g, "#f4ece0", x + 50 - step, y + 37 + step, 2, 1);
3669
3314
  }
3670
- rect(g, "#f2c14e", x + 36, y + 14, 8, 7);
3671
- rect(g, "#5a3a2a", x + 39, y + 14, 2, 7);
3672
- return true;
3315
+ rect(g, "#f2c14e", x + 36, y + 14, 8, 7);
3316
+ rect(g, "#5a3a2a", x + 39, y + 14, 2, 7);
3317
+ return true;
3318
+ }
3319
+ case "scarecrow": {
3320
+ shadow(g, x + 4, y + 30, 8, 2);
3321
+ rect(g, "#8a6a48", x + 7, y + 10, 2, 21);
3322
+ rect(g, "#8a6a48", x + 1, y + 14, 14, 2);
3323
+ rect(g, "#4f8fd6", x + 4, y + 12, 8, 10);
3324
+ rect(g, "#3f78b8", x + 4, y + 18, 8, 1);
3325
+ rect(g, "#ead26a", x, y + 14, 2, 3);
3326
+ rect(g, "#ead26a", x + 14, y + 14, 2, 3);
3327
+ disc(g, "#f2d59a", x + 8, y + 8, 3);
3328
+ rect(g, "#2c2830", x + 6, y + 7, 1, 1);
3329
+ rect(g, "#2c2830", x + 9, y + 7, 1, 1);
3330
+ rect(g, "#8a5f3c", x + 3, y + 4, 11, 1);
3331
+ rect(g, "#8a5f3c", x + 5, y + 1, 7, 3);
3332
+ return true;
3333
+ }
3334
+ case "hay": {
3335
+ shadow(g, x + 2, y + 13, 13);
3336
+ disc(g, "#e2c15a", x + 8, y + 9, 6);
3337
+ disc(g, "#f0d77a", x + 7, y + 7, 3);
3338
+ rect(g, "#c9a646", x + 3, y + 10, 10, 1);
3339
+ rect(g, "#c9a646", x + 4, y + 12, 8, 1);
3340
+ return true;
3341
+ }
3342
+ case "scope": {
3343
+ rect(g, "#4b4b52", x + 7, y + 7, 2, 8);
3344
+ rect(g, "#4b4b52", x + 4, y + 13, 2, 2);
3345
+ rect(g, "#4b4b52", x + 10, y + 13, 2, 2);
3346
+ for (let step = 0;step < 9; step++) {
3347
+ rect(g, "#8d97a6", x + 3 + step, y + 6 - Math.floor(step / 2), 2, 3);
3348
+ }
3349
+ rect(g, "#bfe3f5", x + 12, y + 2, 2, 2);
3350
+ return true;
3351
+ }
3352
+ default:
3353
+ return false;
3354
+ }
3355
+ }
3356
+ WildArt.paint = paint;
3357
+ })(WildArt ||= {});
3358
+
3359
+ // web-src/pixel-art.ts
3360
+ var SHIRTS = [
3361
+ "#5cc27f",
3362
+ "#4285f4",
3363
+ "#ea4335",
3364
+ "#f1dfc0",
3365
+ "#34a853",
3366
+ "#5c6bc0",
3367
+ "#fbbc05",
3368
+ "#8c5cf0",
3369
+ "#dce3f0",
3370
+ "#45b5e8",
3371
+ "#ee7b3b",
3372
+ "#ffffff",
3373
+ "#26b0a9",
3374
+ "#f27ba6",
3375
+ "#b49cf5",
3376
+ "#fbbc05"
3377
+ ];
3378
+ var SKINS = ["#f6d3b3", "#eebd94", "#d39a6c", "#a86f4c", "#7d4f35"];
3379
+ var HAIRS = ["#2e2a2b", "#5a3a28", "#8d5634", "#d8a650", "#9a9aa6", "#b5452f", "#3a3f6b"];
3380
+ var PANTS = ["#3e4a6b", "#4b4b52", "#6b4f3a", "#2f5d50", "#5b4570"];
3381
+ var OUTLINE = "#2c2830";
3382
+ var TA_GREEN = "#10b981";
3383
+ var SPRITE = { w: 12, h: 16 };
3384
+ var DINO = { w: 16, h: 17 };
3385
+ var DIRECTIONS = ["down", "up", "left"];
3386
+ var STEPS2 = 3;
3387
+ function rect2(g, color, x, y, w = 1, h = 1) {
3388
+ g.fillStyle = color;
3389
+ g.fillRect(x, y, w, h);
3390
+ }
3391
+ function disc2(g, color, cx, cy, r) {
3392
+ g.fillStyle = color;
3393
+ for (let y = -r;y <= r; y++) {
3394
+ const half = Math.round(Math.sqrt(r * r - y * y));
3395
+ g.fillRect(cx - half, cy + y, half * 2 + 1, 1);
3396
+ }
3397
+ }
3398
+ function noise(a, b, c = 0) {
3399
+ let x = Math.imul(a, 374761393) + Math.imul(b, 668265263) + Math.imul(c, 2147483647);
3400
+ x = Math.imul(x ^ x >>> 13, 1274126177);
3401
+ return ((x ^ x >>> 16) >>> 0) / 4294967296;
3402
+ }
3403
+ function hashText(text) {
3404
+ let value = 2166136261;
3405
+ for (let index = 0;index < text.length; index++) {
3406
+ value = Math.imul(value ^ text.charCodeAt(index), 16777619);
3407
+ }
3408
+ return value >>> 0;
3409
+ }
3410
+ function shade(hex, amount) {
3411
+ const value = Number.parseInt(hex.slice(1), 16);
3412
+ const channel = (shift) => Math.max(0, Math.min(255, Math.round((value >> shift & 255) * (1 - amount))));
3413
+ return `#${(channel(16) << 16 | channel(8) << 8 | channel(0)).toString(16).padStart(6, "0")}`;
3414
+ }
3415
+ var FURNITURE_PAD = 8;
3416
+ var FLAT = new Set(["rug", "flowers", "chair", ...WildArt.FLAT]);
3417
+ var LOOKS = { tree: 4, pine: 3, boulder: 3, parasol: 3, towel: 3, peak: 3, reeds: 3 };
3418
+ var FurnitureArt;
3419
+ ((FurnitureArt) => {
3420
+ function flat(item) {
3421
+ return FLAT.has(item.kind);
3422
+ }
3423
+ FurnitureArt.flat = flat;
3424
+ function variant(item) {
3425
+ if (item.kind === "flowers" || item.kind === "shelf") {
3426
+ return (item.x + item.y) % 3;
3427
+ }
3428
+ const looks = LOOKS[item.kind];
3429
+ return looks ? Math.floor(noise(item.x, item.y, 77) * looks) : 0;
3430
+ }
3431
+ FurnitureArt.variant = variant;
3432
+ function key(item, faces) {
3433
+ const variant2 = FurnitureArt.variant(item);
3434
+ const face = item.kind === "bed" ? faces.get(item.place ?? "") ?? 0 : "";
3435
+ return `furniture:${item.kind}:${item.w}x${item.h}:${variant2}:${face}`;
3436
+ }
3437
+ FurnitureArt.key = key;
3438
+ function size(item) {
3439
+ return { width: item.w * TILE + 2 * FURNITURE_PAD, height: item.h * TILE + 2 * FURNITURE_PAD };
3440
+ }
3441
+ FurnitureArt.size = size;
3442
+ function paint(g, item, faces) {
3443
+ g.imageSmoothingEnabled = false;
3444
+ const variant2 = FurnitureArt.variant(item);
3445
+ const shown = { ...item, x: variant2, y: 0 };
3446
+ g.save();
3447
+ g.translate(FURNITURE_PAD - shown.x * TILE, FURNITURE_PAD);
3448
+ paintFurniture(g, shown, faces);
3449
+ g.restore();
3450
+ }
3451
+ FurnitureArt.paint = paint;
3452
+ })(FurnitureArt ||= {});
3453
+ function paintFurniture(g, item, faces) {
3454
+ const x = item.x * TILE;
3455
+ const y = item.y * TILE;
3456
+ const w = item.w * TILE;
3457
+ const h = item.h * TILE;
3458
+ if (WildArt.paint(g, item.kind, x, y, w, h, item.x)) {
3459
+ return;
3460
+ }
3461
+ switch (item.kind) {
3462
+ case "tree": {
3463
+ const [dark, mid, light] = [
3464
+ ["#3f8a45", "#58a957", "#79c46a"],
3465
+ ["#2f7a43", "#479a4f", "#66b15f"],
3466
+ ["#4c9a48", "#6bbb5c", "#8fd174"],
3467
+ ["#c46a2e", "#e08d3c", "#f2b553"]
3468
+ ][item.x % 4];
3469
+ g.globalAlpha = 0.18;
3470
+ rect2(g, "#000000", x + 5, y + 27, 22, 4);
3471
+ g.globalAlpha = 1;
3472
+ rect2(g, "#7d5a3c", x + 14, y + 20, 4, 9);
3473
+ disc2(g, dark, x + 16, y + 13, 13);
3474
+ disc2(g, mid, x + 15, y + 11, 11);
3475
+ disc2(g, light, x + 12, y + 8, 5);
3476
+ disc2(g, light, x + 20, y + 13, 3);
3477
+ break;
3478
+ }
3479
+ case "flowers": {
3480
+ for (let index = 0;index < 8; index++) {
3481
+ const fx = x + 2 + Math.floor(noise(item.x, item.y, index) * (w - 4));
3482
+ const fy = y + 3 + Math.floor(noise(item.y, item.x, index) * (h - 6));
3483
+ rect2(g, "#5e9f4c", fx, fy + 1, 1, 2);
3484
+ rect2(g, ["#f28fb0", "#ffd166", "#ffffff", "#c39bf0"][index % 4], fx - 1, fy - 1, 3, 2);
3485
+ }
3486
+ break;
3487
+ }
3488
+ case "bench": {
3489
+ rect2(g, "#6b4a33", x + 2, y + 10, 2, 5);
3490
+ rect2(g, "#6b4a33", x + w - 4, y + 10, 2, 5);
3491
+ rect2(g, "#b07c4f", x + 1, y + 3, w - 2, 3);
3492
+ rect2(g, "#c28d5d", x + 1, y + 8, w - 2, 3);
3493
+ rect2(g, "#8f6240", x + 1, y + 11, w - 2, 1);
3494
+ break;
3495
+ }
3496
+ case "lamp": {
3497
+ rect2(g, "#4b4b57", x + 7, y + 3, 2, 12);
3498
+ rect2(g, "#4b4b57", x + 5, y + 14, 6, 2);
3499
+ rect2(g, "#4b4b57", x + 5, y - 2, 6, 2);
3500
+ rect2(g, "#ffe8a3", x + 6, y, 4, 3);
3501
+ break;
3502
+ }
3503
+ case "bed": {
3504
+ const shirt = SHIRTS[faces.get(item.place ?? "") ?? 0];
3505
+ rect2(g, "#8f6240", x + 1, y, w - 2, h - 1);
3506
+ rect2(g, "#a9774c", x + 1, y, w - 2, 5);
3507
+ rect2(g, "#ffffff", x + 4, y + 6, w - 8, 7);
3508
+ rect2(g, "#e5e7ec", x + 4, y + 12, w - 8, 1);
3509
+ rect2(g, shirt, x + 2, y + 15, w - 4, h - 18);
3510
+ rect2(g, shade(shirt, -0.25), x + 2, y + 15, w - 4, 3);
3511
+ rect2(g, shade(shirt, 0.18), x + 2, y + h - 5, w - 4, 2);
3512
+ break;
3513
+ }
3514
+ case "desk":
3515
+ case "workbench": {
3516
+ const top = item.kind === "desk" ? "#b98552" : "#a3abb5";
3517
+ const front = item.kind === "desk" ? "#94653d" : "#7c858f";
3518
+ rect2(g, top, x, y + 5, w, 7);
3519
+ rect2(g, front, x, y + 12, w, 3);
3520
+ rect2(g, front, x + 1, y + 15, 2, 1);
3521
+ rect2(g, front, x + w - 3, y + 15, 2, 1);
3522
+ for (let index = 0;index < item.w; index++) {
3523
+ const mx = x + index * TILE + 2;
3524
+ rect2(g, OUTLINE, mx, y - 3, 12, 9);
3525
+ rect2(g, "#2b3342", mx + 1, y - 2, 10, 7);
3526
+ rect2(g, OUTLINE, mx + 5, y + 6, 2, 2);
3527
+ rect2(g, "#e9e6e0", mx + 2, y + 9, 8, 2);
3528
+ }
3529
+ break;
3530
+ }
3531
+ case "shelf": {
3532
+ rect2(g, "#8d633f", x, y - 6, w, h + 4);
3533
+ rect2(g, "#6f4b2e", x, y + h - 3, w, 1);
3534
+ const colors = ["#e46b5d", "#4f8fd6", "#f2c14e", "#62b87a", "#a678d6", "#ef9a62"];
3535
+ for (let shelf = 0;shelf < 2; shelf++) {
3536
+ const sy = y - 4 + shelf * 9;
3537
+ for (let bx = x + 1;bx < x + w - 2; bx += 3) {
3538
+ rect2(g, colors[(bx + shelf * 3 + item.y) % colors.length], bx, sy, 2, 7);
3539
+ }
3540
+ rect2(g, "#6f4b2e", x, sy + 7, w, 1);
3541
+ }
3542
+ break;
3543
+ }
3544
+ case "plant": {
3545
+ rect2(g, "#c2774f", x + 4, y + 9, 8, 6);
3546
+ rect2(g, "#a5603c", x + 4, y + 9, 8, 1);
3547
+ disc2(g, "#4f9a4a", x + 8, y + 5, 5);
3548
+ disc2(g, "#6cbb5f", x + 7, y + 4, 3);
3549
+ break;
3550
+ }
3551
+ case "rug": {
3552
+ rect2(g, "#d9968a", x + 1, y + 2, w - 2, h - 4);
3553
+ rect2(g, "#efb9a8", x + 3, y + 4, w - 6, h - 8);
3554
+ for (let rx = x + 5;rx < x + w - 5; rx += 4) {
3555
+ rect2(g, "#d9968a", rx, y + h / 2 - 1, 2, 2);
3556
+ }
3557
+ break;
3558
+ }
3559
+ case "table": {
3560
+ rect2(g, "#c69560", x, y + 2, w, h - 5);
3561
+ rect2(g, "#a77845", x, y + h - 3, w, 3);
3562
+ for (let index = 0;index < item.w; index += 2) {
3563
+ rect2(g, "#ffffff", x + index * TILE + 5, y + 7 + index % 4 * 3, 7, 9);
3564
+ rect2(g, "#c9ced8", x + index * TILE + 6, y + 9 + index % 4 * 3, 5, 1);
3565
+ }
3566
+ rect2(g, "#3a3f4b", x + w / 2 - 6, y + 12, 12, 7);
3567
+ rect2(g, "#7fb0e0", x + w / 2 - 5, y + 13, 10, 4);
3568
+ break;
3569
+ }
3570
+ case "chair": {
3571
+ rect2(g, "#7c5b44", x + 3, y + 6, 10, 8);
3572
+ rect2(g, "#9a7559", x + 4, y + 7, 8, 5);
3573
+ break;
3574
+ }
3575
+ case "whiteboard": {
3576
+ rect2(g, "#aab1bd", x + 2, y + 1, w - 4, 12);
3577
+ rect2(g, "#ffffff", x + 3, y + 2, w - 6, 10);
3578
+ rect2(g, "#e46b5d", x + 6, y + 4, 14, 1);
3579
+ rect2(g, "#4f8fd6", x + 6, y + 7, 22, 1);
3580
+ rect2(g, "#62b87a", x + 30, y + 4, 12, 5);
3581
+ rect2(g, "#4f8fd6", x + w - 26, y + 9, 16, 1);
3582
+ break;
3583
+ }
3584
+ case "board": {
3585
+ rect2(g, "#a8784a", x + 2, y + 1, w - 4, 12);
3586
+ rect2(g, "#c99d6b", x + 3, y + 2, w - 6, 10);
3587
+ const notes = ["#ffe17a", "#9ad7f5", "#f7a8c4", "#b9e6a0"];
3588
+ for (let index = 0;index < 7; index++) {
3589
+ rect2(g, notes[index % notes.length], x + 6 + index * 10, y + 3 + index % 2 * 3, 6, 5);
3590
+ }
3591
+ break;
3592
+ }
3593
+ case "sofa": {
3594
+ rect2(g, "#5f8eac", x, y + 1, w, h - 2);
3595
+ rect2(g, "#7aa6c2", x + 3, y + 4, w - 6, 7);
3596
+ for (let sx = x + 3 + 14;sx < x + w - 3; sx += 14) {
3597
+ rect2(g, "#5f8eac", sx, y + 4, 1, 7);
3598
+ }
3599
+ break;
3600
+ }
3601
+ case "crate": {
3602
+ rect2(g, "#c08f5a", x + 1, y + 2, 14, 13);
3603
+ rect2(g, "#9a6e40", x + 1, y + 2, 14, 1);
3604
+ rect2(g, "#9a6e40", x + 1, y + 8, 14, 1);
3605
+ rect2(g, "#9a6e40", x + 7, y + 2, 1, 13);
3606
+ break;
3607
+ }
3608
+ case "bush":
3609
+ disc2(g, "#58a957", x + 8, y + 9, 6);
3610
+ break;
3611
+ case "coffee": {
3612
+ rect2(g, "#8d633f", x + 2, y + 8, 12, 7);
3613
+ rect2(g, "#3a3f4b", x + 3, y - 3, 10, 12);
3614
+ rect2(g, "#555c6b", x + 4, y - 2, 8, 3);
3615
+ rect2(g, "#e46b5d", x + 10, y - 1, 1, 1);
3616
+ rect2(g, "#1f232b", x + 6, y + 3, 4, 3);
3617
+ rect2(g, "#ffffff", x + 6, y + 5, 4, 3);
3618
+ break;
3619
+ }
3620
+ case "cooler": {
3621
+ rect2(g, "#d9dde4", x + 4, y + 4, 8, 11);
3622
+ rect2(g, "#b9bfc9", x + 4, y + 13, 8, 2);
3623
+ rect2(g, "#7fc6ea", x + 5, y - 4, 6, 8);
3624
+ rect2(g, "#b1e0f6", x + 6, y - 3, 2, 5);
3625
+ rect2(g, "#4f8fd6", x + 7, y + 7, 2, 1);
3626
+ break;
3627
+ }
3628
+ case "floorlamp": {
3629
+ rect2(g, "#4b4b57", x + 7, y - 2, 2, 15);
3630
+ rect2(g, "#4b4b57", x + 5, y + 13, 6, 2);
3631
+ rect2(g, "#f6d58a", x + 3, y - 7, 10, 6);
3632
+ rect2(g, "#e8c06a", x + 3, y - 2, 10, 1);
3633
+ break;
3634
+ }
3635
+ case "tv": {
3636
+ rect2(g, "#8d633f", x + 1, y + 9, 14, 6);
3637
+ rect2(g, OUTLINE, x + 1, y - 2, 14, 10);
3638
+ rect2(g, "#3d5a80", x + 2, y - 1, 12, 8);
3639
+ rect2(g, "#5c7fa8", x + 3, y, 5, 2);
3640
+ break;
3641
+ }
3642
+ case "kiosk": {
3643
+ rect2(g, "#b07c4f", x + 2, y + 10, w - 4, h - 12);
3644
+ rect2(g, "#c99d6b", x + 2, y + 10, w - 4, 3);
3645
+ for (let index = 0;index < 8; index++) {
3646
+ rect2(g, index % 2 === 0 ? "#e46b5d" : "#fff6e8", x + index * (w / 8), y - 4, w / 8, 8);
3647
+ }
3648
+ rect2(g, "#9a5132", x, y + 4, w, 2);
3649
+ rect2(g, "#4b4b57", x + 3, y + 4, 2, 8);
3650
+ rect2(g, "#4b4b57", x + w - 5, y + 4, 2, 8);
3651
+ for (let cup = 0;cup < 3; cup++) {
3652
+ rect2(g, "#ffffff", x + 14 + cup * 9, y + 7, 4, 4);
3653
+ rect2(g, "#7a4a2a", x + 15 + cup * 9, y + 7, 2, 1);
3654
+ }
3655
+ rect2(g, "#2f3a33", x + w - 18, y + 14, 12, 9);
3656
+ rect2(g, "#f2e8cf", x + w - 16, y + 16, 8, 1);
3657
+ rect2(g, "#f2e8cf", x + w - 16, y + 19, 6, 1);
3658
+ break;
3659
+ }
3660
+ case "umbrella": {
3661
+ rect2(g, "#c69560", x + 6, y + 14, 20, 12);
3662
+ rect2(g, "#a77845", x + 6, y + 24, 20, 2);
3663
+ const stripes = ["#62b87a", "#fff6e8"];
3664
+ for (let ring = 0;ring < 8; ring++) {
3665
+ disc2(g, stripes[ring % 2], x + 16, y + 10, 13 - ring * 1.6);
3666
+ }
3667
+ rect2(g, "#4b4b57", x + 15, y + 9, 2, 2);
3668
+ break;
3669
+ }
3670
+ case "toolwall": {
3671
+ rect2(g, "#a8784a", x + 1, y + 1, w - 2, 12);
3672
+ rect2(g, "#c99d6b", x + 2, y + 2, w - 4, 10);
3673
+ const tools = ["#7c858f", "#e46b5d", "#4f8fd6", "#f2c14e", "#62b87a"];
3674
+ for (let index = 0;index < 6; index++) {
3675
+ const tx = x + 5 + index * 7;
3676
+ rect2(g, "#6f4b2e", tx, y + 3, 1, 1);
3677
+ rect2(g, tools[index % tools.length], tx - 1, y + 4, 3, 2);
3678
+ rect2(g, "#4b4b57", tx, y + 6, 1, 5);
3679
+ }
3680
+ break;
3681
+ }
3682
+ }
3683
+ }
3684
+ function lookOf(id, face) {
3685
+ const hash2 = hashText(id);
3686
+ return {
3687
+ skin: SKINS[hash2 % SKINS.length],
3688
+ hair: HAIRS[(hash2 >>> 4) % HAIRS.length],
3689
+ shirt: SHIRTS[face ?? hash2 % SHIRTS.length],
3690
+ pants: PANTS[(hash2 >>> 9) % PANTS.length]
3691
+ };
3692
+ }
3693
+ var BODY = {
3694
+ down: [
3695
+ "...kkkkkk...",
3696
+ "..khhhhhhk..",
3697
+ ".khhhhhhhhk.",
3698
+ ".khhhhhhhhk.",
3699
+ ".khsssssshk.",
3700
+ ".ksessssesk.",
3701
+ ".ksrssssrsk.",
3702
+ "..kssssssk..",
3703
+ ".kcccccccck.",
3704
+ "kscccccccsk.",
3705
+ "kscccccccsk.",
3706
+ ".kddddddddk.",
3707
+ ".kppppppppk."
3708
+ ],
3709
+ up: [
3710
+ "...kkkkkk...",
3711
+ "..khhhhhhk..",
3712
+ ".khhhhhhhhk.",
3713
+ ".khhhhhhhhk.",
3714
+ ".khhhhhhhhk.",
3715
+ ".khhhhhhhhk.",
3716
+ ".khhhhhhhhk.",
3717
+ "..khhhhhhk..",
3718
+ ".kcccccccck.",
3719
+ "kscccccccsk.",
3720
+ "kscccccccsk.",
3721
+ ".kddddddddk.",
3722
+ ".kppppppppk."
3723
+ ],
3724
+ left: [
3725
+ "...kkkkkk...",
3726
+ "..khhhhhhk..",
3727
+ ".khhhhhhhhk.",
3728
+ ".khhhhhhhhk.",
3729
+ ".ksshhhhhhk.",
3730
+ ".kesshhhhhk.",
3731
+ ".krsshhhhhk.",
3732
+ "..ksssshhk..",
3733
+ "..kcccccck..",
3734
+ "..kcscccck..",
3735
+ "..kcscccck..",
3736
+ "..kddddddk..",
3737
+ "..kppppppk.."
3738
+ ]
3739
+ };
3740
+ var LEGS = {
3741
+ down: [
3742
+ ["..kppkkppk..", "..kbbkkbbk..", "...kk..kk..."],
3743
+ ["..kppkkppk..", "..kbbkkbbk..", "...kk......."],
3744
+ ["..kppkkppk..", "..kbbkkbbk..", ".......kk..."]
3745
+ ],
3746
+ up: [
3747
+ ["..kppkkppk..", "..kbbkkbbk..", "...kk..kk..."],
3748
+ ["..kppkkppk..", "..kbbkkbbk..", "...kk......."],
3749
+ ["..kppkkppk..", "..kbbkkbbk..", ".......kk..."]
3750
+ ],
3751
+ left: [
3752
+ ["...kppppk...", "..kbbbbbk...", "..kkkkkk...."],
3753
+ ["..kppkppk...", ".kbbk.kbbk..", ".kkk...kkk.."],
3754
+ ["...kppppk...", "..kbbbbbk...", "..kkkkkk...."]
3755
+ ]
3756
+ };
3757
+ function frameRows(direction, step) {
3758
+ return [...BODY[direction], ...LEGS[direction][step]];
3759
+ }
3760
+ function paintResident(g, look) {
3761
+ const colors = {
3762
+ k: OUTLINE,
3763
+ h: look.hair,
3764
+ s: look.skin,
3765
+ e: OUTLINE,
3766
+ r: "#f19a96",
3767
+ c: look.shirt,
3768
+ d: shade(look.shirt, 0.22),
3769
+ p: look.pants,
3770
+ b: "#3b3330"
3771
+ };
3772
+ DIRECTIONS.forEach((direction, d) => {
3773
+ for (let step = 0;step < STEPS2; step++) {
3774
+ const left = (d * STEPS2 + step) * SPRITE.w;
3775
+ frameRows(direction, step).forEach((row, y) => {
3776
+ [...row].forEach((pixel, x) => {
3777
+ if (pixel !== ".") {
3778
+ rect2(g, colors[pixel], left + x, y, 1, 1);
3779
+ }
3780
+ });
3781
+ });
3782
+ }
3783
+ });
3784
+ }
3785
+ var DINO_ROWS = [
3786
+ "..........######",
3787
+ ".........##o####",
3788
+ ".........#######",
3789
+ ".........#######",
3790
+ ".........####...",
3791
+ ".........######.",
3792
+ "#.......#####...",
3793
+ "#......#######..",
3794
+ "##...#########..",
3795
+ "###.#######.#...",
3796
+ "###########.....",
3797
+ ".#########......",
3798
+ "..#######.......",
3799
+ "...#####........"
3800
+ ];
3801
+ var DINO_LEGS = [
3802
+ ["...##.##........", "...#...#........", "...##..##......."],
3803
+ ["...##.##........", "...##...#.......", ".......##......."],
3804
+ ["...##.##........", "...#....#.......", "...##...##......"]
3805
+ ];
3806
+ function paintDino(g) {
3807
+ DINO_LEGS.forEach((legs, frame) => {
3808
+ [...DINO_ROWS, ...legs].forEach((row, y) => {
3809
+ [...row].forEach((pixel, x) => {
3810
+ if (pixel !== ".") {
3811
+ rect2(g, pixel === "o" ? "#ffffff" : TA_GREEN, frame * DINO.w + x, y, 1, 1);
3812
+ }
3813
+ });
3814
+ });
3815
+ });
3816
+ }
3817
+
3818
+ // web-src/town-card.tsx
3819
+ function Sprite({ resident, scale = 2 }) {
3820
+ const canvas = React.useRef(null);
3821
+ const double = resident.id === DOUBLE_ID;
3822
+ const size = double ? DINO : SPRITE;
3823
+ React.useEffect(() => {
3824
+ const context = canvas.current?.getContext("2d");
3825
+ if (!context) {
3826
+ return;
3827
+ }
3828
+ const sheet = document.createElement("canvas");
3829
+ sheet.width = size.w * 9;
3830
+ sheet.height = size.h;
3831
+ const paint = sheet.getContext("2d");
3832
+ if (!paint) {
3833
+ return;
3834
+ }
3835
+ if (double) {
3836
+ paintDino(paint);
3837
+ } else {
3838
+ paintResident(paint, lookOf(resident.id, resident.face));
3839
+ }
3840
+ context.clearRect(0, 0, size.w, size.h);
3841
+ context.drawImage(sheet, 0, 0, size.w, size.h, 0, 0, size.w, size.h);
3842
+ }, [double, resident.id, resident.face, size]);
3843
+ return /* @__PURE__ */ React.createElement("canvas", {
3844
+ ref: canvas,
3845
+ className: "twn-sprite",
3846
+ width: size.w,
3847
+ height: size.h,
3848
+ style: { width: size.w * scale, height: size.h * scale }
3849
+ });
3850
+ }
3851
+ function talkTarget(data, resident, w) {
3852
+ const agent = data.team.agents.find((each) => each.id === resident.id);
3853
+ const placeholder = TownWords.format(w.talkTo, { name: resident.name });
3854
+ return resident.id === DOUBLE_ID ? { to: DOUBLE_ID, kind: "double", placeholder } : agent ? { to: agent.id, kind: "agent", agent, placeholder } : undefined;
3855
+ }
3856
+ function TownCard({ pi, data, model, id, tasks, words: w, talk, onPick, onOpen, onPossess, onClose }) {
3857
+ const place = model.places.find((each) => each.id === id);
3858
+ const residentId = place?.kind === "office" ? DOUBLE_ID : place?.kind === "home" ? place.owner : place ? undefined : id;
3859
+ const resident = residentId ? model.residents.find((each) => each.id === residentId) : undefined;
3860
+ const X = pi.ui.icons.X;
3861
+ const Gamepad = pi.ui.icons.Gamepad2;
3862
+ let face;
3863
+ let title;
3864
+ let status;
3865
+ let body;
3866
+ let action;
3867
+ let target;
3868
+ let members;
3869
+ if (resident) {
3870
+ face = /* @__PURE__ */ React.createElement(Sprite, {
3871
+ resident,
3872
+ scale: 3
3873
+ });
3874
+ title = resident.name;
3875
+ status = `${TownWords.emoji(resident)} ${TownWords.status(w, resident)}`;
3876
+ body = resident.line && !talk.talks.some((each) => each.to === resident.id) && /* @__PURE__ */ React.createElement("span", {
3877
+ className: "twn-card-line"
3878
+ }, resident.line);
3879
+ action = { label: w.open, run: () => onOpen(resident.id) };
3880
+ target = talkTarget(data, resident, w);
3881
+ } else if (place?.kind === "meeting") {
3882
+ const channel = data.team.channels.find((each) => TownModel.roomOf(each.id) === id);
3883
+ members = (channel?.members ?? []).map((member) => model.residents.find((each) => each.id === member)).filter((each) => !!each);
3884
+ const messages = (channel && data.messages[channel.id]) ?? [];
3885
+ const name = (author) => author === "user" ? w.you : author === "ta" ? "Ta" : data.team.agents.find((each) => each.id === author)?.name ?? "";
3886
+ face = /* @__PURE__ */ React.createElement("span", {
3887
+ className: "twn-card-glyph"
3888
+ }, "#");
3889
+ title = `#${place.name}`;
3890
+ status = TownWords.format(w.members, { count: members.length });
3891
+ body = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
3892
+ className: "twn-card-members"
3893
+ }, members.map((member) => /* @__PURE__ */ React.createElement("button", {
3894
+ type: "button",
3895
+ key: member.id,
3896
+ className: "twn-card-member",
3897
+ title: member.name,
3898
+ onClick: () => onPick(member.id)
3899
+ }, /* @__PURE__ */ React.createElement(Sprite, {
3900
+ resident: member,
3901
+ scale: 1.5
3902
+ })))), messages.length === 0 ? /* @__PURE__ */ React.createElement("span", {
3903
+ className: "twn-card-line"
3904
+ }, w.noMessages) : messages.filter((message) => message.author !== "system").slice(-3).map((message) => /* @__PURE__ */ React.createElement("span", {
3905
+ key: message.id,
3906
+ className: "twn-card-line twn-card-message"
3907
+ }, /* @__PURE__ */ React.createElement("b", null, name(message.author)), " ", message.text.replace(/\s+/g, " "))));
3908
+ target = channel && { to: id, kind: "room", channelId: channel.id, placeholder: TownWords.format(w.postTo, { channel: channel.name }) };
3909
+ } else if (place?.kind === "bench") {
3910
+ const task = tasks.find((each) => TownModel.benchOf(each.key) === id);
3911
+ if (!task) {
3912
+ return null;
3913
+ }
3914
+ const Icon = task.icon;
3915
+ face = Icon ? /* @__PURE__ */ React.createElement(Icon, {
3916
+ size: 40
3917
+ }) : /* @__PURE__ */ React.createElement("span", {
3918
+ className: "twn-card-glyph"
3919
+ }, "✦");
3920
+ title = task.title;
3921
+ status = { running: w.taskRunning, waiting: w.taskWaiting, done: w.taskDone, failed: w.taskFailed, stopped: w.taskStopped }[task.status];
3922
+ body = task.detail && /* @__PURE__ */ React.createElement("span", {
3923
+ className: "twn-card-line"
3924
+ }, task.detail);
3925
+ action = { label: w.watch, run: () => task.open() };
3926
+ } else {
3927
+ return null;
3928
+ }
3929
+ return /* @__PURE__ */ React.createElement("div", {
3930
+ className: "twn-card",
3931
+ role: "dialog",
3932
+ "aria-label": title
3933
+ }, /* @__PURE__ */ React.createElement("div", {
3934
+ className: "twn-card-head"
3935
+ }, /* @__PURE__ */ React.createElement("span", {
3936
+ className: "twn-card-face"
3937
+ }, face), /* @__PURE__ */ React.createElement("span", {
3938
+ className: "twn-card-text"
3939
+ }, /* @__PURE__ */ React.createElement("span", {
3940
+ className: "twn-card-name"
3941
+ }, title), /* @__PURE__ */ React.createElement("span", {
3942
+ className: "twn-card-status"
3943
+ }, status), body), resident && onPossess && /* @__PURE__ */ React.createElement("button", {
3944
+ type: "button",
3945
+ className: "twn-card-go twn-card-possess",
3946
+ title: w.walk3d,
3947
+ onClick: () => onPossess(resident.id)
3948
+ }, Gamepad && /* @__PURE__ */ React.createElement(Gamepad, {
3949
+ size: 14
3950
+ }), w.possess), action && /* @__PURE__ */ React.createElement("button", {
3951
+ type: "button",
3952
+ className: "twn-card-go",
3953
+ onClick: action.run
3954
+ }, action.label), /* @__PURE__ */ React.createElement("button", {
3955
+ type: "button",
3956
+ className: "twn-card-close",
3957
+ title: w.close,
3958
+ "aria-label": w.close,
3959
+ onClick: onClose
3960
+ }, X && /* @__PURE__ */ React.createElement(X, {
3961
+ size: 14
3962
+ }))), target && /* @__PURE__ */ React.createElement(TalkBar, {
3963
+ key: target.to,
3964
+ pi,
3965
+ target,
3966
+ talk,
3967
+ words: w,
3968
+ name: title,
3969
+ face: resident,
3970
+ members
3971
+ }));
3972
+ }
3973
+ function phaseText(w, talk, name, last) {
3974
+ switch (talk.phase) {
3975
+ case "failed":
3976
+ return talk.error;
3977
+ case "sending":
3978
+ return w.sending;
3979
+ case "waiting":
3980
+ return w.waitingReply;
3981
+ case "answering":
3982
+ return w.answeringNow;
3983
+ default:
3984
+ if (!last) {
3985
+ return;
3986
+ }
3987
+ return talk.kind === "room" ? TownWords.format(w.posted, { channel: name.replace(/^#/, "") }) : talk.reply ? undefined : w.noReply;
3988
+ }
3989
+ }
3990
+ function TalkBar({
3991
+ pi,
3992
+ target,
3993
+ talk,
3994
+ words: w,
3995
+ name,
3996
+ face,
3997
+ members
3998
+ }) {
3999
+ const thread = QuickTalkUtil.thread(talk.talks, target.to);
4000
+ const last = thread[thread.length - 1];
4001
+ const Composer = pi.ui.Composer;
4002
+ const Markdown = pi.ui.Markdown;
4003
+ const Volume = pi.ui.icons.Volume2;
4004
+ const Square = pi.ui.icons.Square;
4005
+ const voice = pi.ui.voice;
4006
+ const list = React.useRef(null);
4007
+ const height = `${thread.length}:${last?.phase}:${last?.reply?.length ?? 0}`;
4008
+ React.useLayoutEffect(() => {
4009
+ const element = list.current;
4010
+ if (element) {
4011
+ element.scrollTop = element.scrollHeight;
4012
+ }
4013
+ }, [height]);
4014
+ const { listen } = talk;
4015
+ React.useEffect(() => () => listen(undefined), [listen]);
4016
+ const mentions = React.useMemo(() => members?.map((member) => ({ name: member.name })), [members]);
4017
+ return /* @__PURE__ */ React.createElement("div", {
4018
+ className: "twn-talk"
4019
+ }, thread.length > 0 && /* @__PURE__ */ React.createElement("div", {
4020
+ className: "twn-talk-thread",
4021
+ ref: list,
4022
+ "aria-live": "polite"
4023
+ }, thread.map((each, index) => {
4024
+ const state = phaseText(w, each, name, index === thread.length - 1);
4025
+ return /* @__PURE__ */ React.createElement(React.Fragment, {
4026
+ key: each.sentAt
4027
+ }, /* @__PURE__ */ React.createElement("div", {
4028
+ className: "twn-talk-said"
4029
+ }, /* @__PURE__ */ React.createElement("span", null, each.said)), each.reply && /* @__PURE__ */ React.createElement("div", {
4030
+ className: "twn-talk-reply"
4031
+ }, face && /* @__PURE__ */ React.createElement(Sprite, {
4032
+ resident: face,
4033
+ scale: 1.5
4034
+ }), /* @__PURE__ */ React.createElement("div", {
4035
+ className: "twn-talk-reply-text"
4036
+ }, Markdown ? /* @__PURE__ */ React.createElement(Markdown, {
4037
+ text: each.reply
4038
+ }) : each.reply), voice?.canSpeak() && /* @__PURE__ */ React.createElement("button", {
4039
+ type: "button",
4040
+ className: "twn-talk-icon",
4041
+ title: w.replay,
4042
+ "aria-label": w.replay,
4043
+ onClick: () => talk.speak(each.reply)
4044
+ }, Volume && /* @__PURE__ */ React.createElement(Volume, {
4045
+ size: 14
4046
+ }))), state && /* @__PURE__ */ React.createElement("div", {
4047
+ className: `twn-talk-state${each.phase === "failed" ? " twn-talk-failed" : each.phase === "done" ? " twn-talk-quiet" : ""}`
4048
+ }, face && each.phase !== "failed" && each.phase !== "done" && /* @__PURE__ */ React.createElement(Sprite, {
4049
+ resident: face,
4050
+ scale: 1.5
4051
+ }), /* @__PURE__ */ React.createElement("span", null, state)));
4052
+ })), /* @__PURE__ */ React.createElement("div", {
4053
+ className: "twn-talk-box"
4054
+ }, /* @__PURE__ */ React.createElement(Composer, {
4055
+ placeholder: target.placeholder,
4056
+ onSend: (text) => talk.send(target, text, false),
4057
+ voiceSends: true,
4058
+ onTalkSent: talk.spoken,
4059
+ onListening: (on) => listen(on ? target.to : undefined),
4060
+ working: target.kind === "agent" && QuickTalkUtil.working(last),
4061
+ onStop: talk.stop,
4062
+ mentions,
4063
+ mentionLabel: mentions ? w.mention : undefined,
4064
+ after: talk.speaking ? /* @__PURE__ */ React.createElement("button", {
4065
+ type: "button",
4066
+ className: "twn-talk-hush",
4067
+ title: w.hush,
4068
+ "aria-label": w.hush,
4069
+ onClick: talk.hush
4070
+ }, /* @__PURE__ */ React.createElement("span", {
4071
+ className: "twn-wave",
4072
+ "aria-hidden": "true"
4073
+ }, /* @__PURE__ */ React.createElement("i", null), /* @__PURE__ */ React.createElement("i", null), /* @__PURE__ */ React.createElement("i", null)), Square && /* @__PURE__ */ React.createElement(Square, {
4074
+ size: 10
4075
+ })) : undefined
4076
+ })));
4077
+ }
4078
+
4079
+ // ../ta-relay/esm/common/relay-room-chat.js
4080
+ var RELAY_CHAT_KEY = "chat:";
4081
+ var RELAY_CHAT_PART_BYTES = 8 * 1024;
4082
+ var RELAY_CHAT_PARTS = 6;
4083
+ var RELAY_CHAT_TEXT_MAX = 2000;
4084
+ var TRIES = 6;
4085
+ var RelayRoomChatUtil;
4086
+ (function(RelayRoomChatUtil2) {
4087
+ function key(member, part) {
4088
+ return `${RELAY_CHAT_KEY}${member}:${part}`;
4089
+ }
4090
+ RelayRoomChatUtil2.key = key;
4091
+ function parse(key2) {
4092
+ const match = /^chat:([^:]+):(\d+)$/.exec(key2);
4093
+ return match ? { member: match[1], part: Number(match[2]) } : undefined;
4094
+ }
4095
+ RelayRoomChatUtil2.parse = parse;
4096
+ function lines(member, value, by) {
4097
+ if (by !== member || !Array.isArray(value)) {
4098
+ return;
4099
+ }
4100
+ const lines2 = [];
4101
+ for (const line of value) {
4102
+ if (line && typeof line.id === "string" && typeof line.text === "string" && typeof line.at === "number") {
4103
+ lines2.push({ id: line.id, from: member, name: typeof line.name === "string" ? line.name : "", text: line.text, at: line.at, ...extra(line) });
4104
+ }
4105
+ }
4106
+ return lines2;
4107
+ }
4108
+ RelayRoomChatUtil2.lines = lines;
4109
+ function extra(line) {
4110
+ const to = Array.isArray(line.to) ? line.to.filter((each) => typeof each === "string").slice(0, 16) : [];
4111
+ const agent = line.agent;
4112
+ return {
4113
+ ...line.double === true ? { double: true } : {},
4114
+ ...agent && typeof agent.id === "string" && agent.id && typeof agent.name === "string" && line.double !== true ? { agent: { id: agent.id.slice(0, 64), name: agent.name.slice(0, 64) } } : {},
4115
+ ...to.length ? { to } : {},
4116
+ ...typeof line.re === "string" ? { re: line.re } : {},
4117
+ ...line.task === true && to.length ? { task: true } : {}
4118
+ };
4119
+ }
4120
+ RelayRoomChatUtil2.extra = extra;
4121
+ function stored(lines2) {
4122
+ return lines2.map(({ from: _from, ...line }) => line);
4123
+ }
4124
+ RelayRoomChatUtil2.stored = stored;
4125
+ function bytes(lines2) {
4126
+ return new TextEncoder().encode(JSON.stringify(lines2)).length;
4127
+ }
4128
+ RelayRoomChatUtil2.bytes = bytes;
4129
+ function id() {
4130
+ return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
4131
+ }
4132
+ RelayRoomChatUtil2.id = id;
4133
+ })(RelayRoomChatUtil || (RelayRoomChatUtil = {}));
4134
+
4135
+ class RelayRoomChat {
4136
+ constructor(rooms, room) {
4137
+ this.rooms = rooms;
4138
+ this.room = room;
4139
+ this.parts = new Map;
4140
+ this.listeners = new Set;
4141
+ this.all = [];
4142
+ }
4143
+ get lines() {
4144
+ return this.all;
4145
+ }
4146
+ subscribe(listener) {
4147
+ this.listeners.add(listener);
4148
+ return () => this.listeners.delete(listener);
4149
+ }
4150
+ async load() {
4151
+ const state = await this.rooms.getState(this.room, RELAY_CHAT_KEY);
4152
+ this.parts.clear();
4153
+ for (const [key, value] of Object.entries(state)) {
4154
+ this.put(key, value);
4155
+ }
4156
+ this.changed();
4157
+ }
4158
+ heard(key, value) {
4159
+ if (!RelayRoomChatUtil.parse(key)) {
4160
+ return false;
4161
+ }
4162
+ const known = this.parts.get(key);
4163
+ if (known && known.version >= value.version) {
4164
+ return true;
4165
+ }
4166
+ this.put(key, value);
4167
+ this.changed();
4168
+ return true;
4169
+ }
4170
+ async say(text, self, extra = {}) {
4171
+ var _a;
4172
+ var _b, _c;
4173
+ const said = text.trim().slice(0, RELAY_CHAT_TEXT_MAX);
4174
+ if (!said) {
4175
+ return;
4176
+ }
4177
+ for (let tries = 0;tries < TRIES; tries++) {
4178
+ const latest = this.latest(self.member);
4179
+ const last = latest === null || latest === undefined ? undefined : latest.lines[latest.lines.length - 1];
4180
+ const at = Math.max(Date.now(), ((_b = last === null || last === undefined ? undefined : last.at) !== null && _b !== undefined ? _b : 0) + 1);
4181
+ const line = {
4182
+ id: RelayRoomChatUtil.id(),
4183
+ from: self.member,
4184
+ name: self.name,
4185
+ text: said,
4186
+ at,
4187
+ ...RelayRoomChatUtil.extra(extra)
4188
+ };
4189
+ const fits = latest && RelayRoomChatUtil.bytes(RelayRoomChatUtil.stored([...latest.lines, line])) <= RELAY_CHAT_PART_BYTES;
4190
+ const part = !latest ? 0 : fits ? latest.part : latest.part + 1;
4191
+ const lines = fits && latest ? [...latest.lines, line] : [line];
4192
+ const key = RelayRoomChatUtil.key(self.member, part);
4193
+ const value = RelayRoomChatUtil.stored(lines);
4194
+ const result = await this.rooms.setState(this.room, key, value, (_c = (_a = this.parts.get(key)) === null || _a === undefined ? undefined : _a.version) !== null && _c !== undefined ? _c : 0);
4195
+ if (result.ok) {
4196
+ this.put(key, { value, version: result.version, by: self.member });
4197
+ this.changed();
4198
+ if (part >= RELAY_CHAT_PARTS) {
4199
+ this.clear(RelayRoomChatUtil.key(self.member, part - RELAY_CHAT_PARTS));
4200
+ }
4201
+ return line;
3673
4202
  }
3674
- case "scarecrow": {
3675
- shadow(g, x + 4, y + 30, 8, 2);
3676
- rect(g, "#8a6a48", x + 7, y + 10, 2, 21);
3677
- rect(g, "#8a6a48", x + 1, y + 14, 14, 2);
3678
- rect(g, "#4f8fd6", x + 4, y + 12, 8, 10);
3679
- rect(g, "#3f78b8", x + 4, y + 18, 8, 1);
3680
- rect(g, "#ead26a", x, y + 14, 2, 3);
3681
- rect(g, "#ead26a", x + 14, y + 14, 2, 3);
3682
- disc(g, "#f2d59a", x + 8, y + 8, 3);
3683
- rect(g, "#2c2830", x + 6, y + 7, 1, 1);
3684
- rect(g, "#2c2830", x + 9, y + 7, 1, 1);
3685
- rect(g, "#8a5f3c", x + 3, y + 4, 11, 1);
3686
- rect(g, "#8a5f3c", x + 5, y + 1, 7, 3);
3687
- return true;
4203
+ await this.load();
4204
+ }
4205
+ throw new Error("The room is busy: say it again.");
4206
+ }
4207
+ async clear(key) {
4208
+ await this.rooms.setState(this.room, key, null).catch(() => {
4209
+ return;
4210
+ });
4211
+ if (this.parts.delete(key)) {
4212
+ this.changed();
4213
+ }
4214
+ }
4215
+ latest(member) {
4216
+ let latest;
4217
+ for (const part of this.parts.values()) {
4218
+ if (part.member === member && (!latest || part.part > latest.part)) {
4219
+ latest = part;
3688
4220
  }
3689
- case "hay": {
3690
- shadow(g, x + 2, y + 13, 13);
3691
- disc(g, "#e2c15a", x + 8, y + 9, 6);
3692
- disc(g, "#f0d77a", x + 7, y + 7, 3);
3693
- rect(g, "#c9a646", x + 3, y + 10, 10, 1);
3694
- rect(g, "#c9a646", x + 4, y + 12, 8, 1);
3695
- return true;
4221
+ }
4222
+ return latest;
4223
+ }
4224
+ put(key, value) {
4225
+ const parsed = RelayRoomChatUtil.parse(key);
4226
+ const lines = parsed && value.value !== null ? RelayRoomChatUtil.lines(parsed.member, value.value, value.by) : undefined;
4227
+ if (!parsed || !lines) {
4228
+ this.parts.delete(key);
4229
+ return;
4230
+ }
4231
+ this.parts.set(key, { ...parsed, lines, version: value.version });
4232
+ }
4233
+ changed() {
4234
+ this.all = [...this.parts.values()].flatMap((part) => part.lines).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
4235
+ for (const listener of this.listeners) {
4236
+ listener();
4237
+ }
4238
+ }
4239
+ }
4240
+
4241
+ // web-src/town-rooms.ts
4242
+ var ROOMS_PACKAGE = "@celljs/ta-rooms";
4243
+ var ROOMS_VIEW = "@celljs/ta-rooms/rooms";
4244
+ var MAX_ROOMS = 6;
4245
+ var MAX_VISITORS = 8;
4246
+ var LIVELY_MS = 3 * 60000;
4247
+ var FACES = 16;
4248
+
4249
+ class TownRoomsWatch {
4250
+ rooms;
4251
+ listen;
4252
+ state = { rooms: [], lines: {} };
4253
+ chats = new Map;
4254
+ listeners = new Set;
4255
+ stopEvents;
4256
+ reading;
4257
+ again = false;
4258
+ live = false;
4259
+ constructor(rooms, listen) {
4260
+ this.rooms = rooms;
4261
+ this.listen = listen;
4262
+ }
4263
+ get = () => this.state;
4264
+ chat(room) {
4265
+ return this.chats.get(room)?.chat;
4266
+ }
4267
+ subscribe = (listener) => {
4268
+ this.listeners.add(listener);
4269
+ return () => {
4270
+ this.listeners.delete(listener);
4271
+ };
4272
+ };
4273
+ start() {
4274
+ if (!this.rooms) {
4275
+ return () => {
4276
+ return;
4277
+ };
4278
+ }
4279
+ this.live = true;
4280
+ this.stopEvents = this.listen?.((event) => this.heard(event), { messages: false, state: [RELAY_CHAT_KEY] });
4281
+ this.read();
4282
+ return () => {
4283
+ this.live = false;
4284
+ this.stopEvents?.();
4285
+ for (const held of this.chats.values()) {
4286
+ held.stop();
3696
4287
  }
3697
- case "scope": {
3698
- rect(g, "#4b4b52", x + 7, y + 7, 2, 8);
3699
- rect(g, "#4b4b52", x + 4, y + 13, 2, 2);
3700
- rect(g, "#4b4b52", x + 10, y + 13, 2, 2);
3701
- for (let step = 0;step < 9; step++) {
3702
- rect(g, "#8d97a6", x + 3 + step, y + 6 - Math.floor(step / 2), 2, 3);
4288
+ this.chats.clear();
4289
+ };
4290
+ }
4291
+ heard(event) {
4292
+ if (event.type === "rooms") {
4293
+ this.read();
4294
+ } else if (event.type === "state") {
4295
+ this.chats.get(event.room)?.chat.heard(event.key, { value: event.value, version: event.version, by: event.by });
4296
+ }
4297
+ }
4298
+ read() {
4299
+ if (this.reading) {
4300
+ this.again = true;
4301
+ return this.reading;
4302
+ }
4303
+ const rooms = this.rooms;
4304
+ this.reading = (async () => {
4305
+ do {
4306
+ this.again = false;
4307
+ const list = await rooms.listRooms().catch(() => {
4308
+ return;
4309
+ });
4310
+ if (!this.live) {
4311
+ return;
3703
4312
  }
3704
- rect(g, "#bfe3f5", x + 12, y + 2, 2, 2);
3705
- return true;
4313
+ if (list) {
4314
+ this.put(TownRoomsUtil.shown(list));
4315
+ }
4316
+ } while (this.again);
4317
+ })().finally(() => {
4318
+ this.reading = undefined;
4319
+ });
4320
+ return this.reading;
4321
+ }
4322
+ put(list) {
4323
+ const ids = new Set(list.map((room) => room.id));
4324
+ for (const [id, held] of this.chats) {
4325
+ if (!ids.has(id)) {
4326
+ held.stop();
4327
+ this.chats.delete(id);
4328
+ }
4329
+ }
4330
+ for (const room of list) {
4331
+ if (!this.chats.has(room.id)) {
4332
+ const chat = new RelayRoomChat(this.rooms, room.id);
4333
+ const stop = chat.subscribe(() => this.changed());
4334
+ this.chats.set(room.id, { chat, stop });
4335
+ chat.load().catch(() => {
4336
+ return;
4337
+ });
3706
4338
  }
3707
- default:
3708
- return false;
3709
4339
  }
4340
+ this.state = { ...this.state, rooms: list };
4341
+ this.changed();
3710
4342
  }
3711
- WildArt.paint = paint;
3712
- })(WildArt ||= {});
3713
-
3714
- // web-src/pixel-art.ts
3715
- var SHIRTS = [
3716
- "#5cc27f",
3717
- "#4285f4",
3718
- "#ea4335",
3719
- "#f1dfc0",
3720
- "#34a853",
3721
- "#5c6bc0",
3722
- "#fbbc05",
3723
- "#8c5cf0",
3724
- "#dce3f0",
3725
- "#45b5e8",
3726
- "#ee7b3b",
3727
- "#ffffff",
3728
- "#26b0a9",
3729
- "#f27ba6",
3730
- "#b49cf5",
3731
- "#fbbc05"
3732
- ];
3733
- var SKINS = ["#f6d3b3", "#eebd94", "#d39a6c", "#a86f4c", "#7d4f35"];
3734
- var HAIRS = ["#2e2a2b", "#5a3a28", "#8d5634", "#d8a650", "#9a9aa6", "#b5452f", "#3a3f6b"];
3735
- var PANTS = ["#3e4a6b", "#4b4b52", "#6b4f3a", "#2f5d50", "#5b4570"];
3736
- var OUTLINE = "#2c2830";
3737
- var TA_GREEN = "#10b981";
3738
- var SPRITE = { w: 12, h: 16 };
3739
- var DINO = { w: 16, h: 17 };
3740
- var DIRECTIONS = ["down", "up", "left"];
3741
- var STEPS2 = 3;
3742
- function rect2(g, color, x, y, w = 1, h = 1) {
3743
- g.fillStyle = color;
3744
- g.fillRect(x, y, w, h);
3745
- }
3746
- function disc2(g, color, cx, cy, r) {
3747
- g.fillStyle = color;
3748
- for (let y = -r;y <= r; y++) {
3749
- const half = Math.round(Math.sqrt(r * r - y * y));
3750
- g.fillRect(cx - half, cy + y, half * 2 + 1, 1);
4343
+ changed() {
4344
+ const lines = {};
4345
+ for (const [id, held] of this.chats) {
4346
+ lines[id] = held.chat.lines;
4347
+ }
4348
+ this.state = { rooms: this.state.rooms, lines };
4349
+ for (const listener of this.listeners) {
4350
+ listener();
4351
+ }
3751
4352
  }
3752
4353
  }
3753
- function noise(a, b, c = 0) {
3754
- let x = Math.imul(a, 374761393) + Math.imul(b, 668265263) + Math.imul(c, 2147483647);
3755
- x = Math.imul(x ^ x >>> 13, 1274126177);
3756
- return ((x ^ x >>> 16) >>> 0) / 4294967296;
4354
+ function useTownRooms(pi) {
4355
+ const watch = React.useMemo(() => new TownRoomsWatch(pi.rooms, pi.onRoomEvent?.bind(pi)), [pi]);
4356
+ React.useEffect(() => watch.start(), [watch]);
4357
+ const state = React.useSyncExternalStore(watch.subscribe, watch.get);
4358
+ return { state, watch };
3757
4359
  }
3758
- function hashText(text) {
3759
- let value = 2166136261;
3760
- for (let index = 0;index < text.length; index++) {
3761
- value = Math.imul(value ^ text.charCodeAt(index), 16777619);
4360
+ var TownRoomsUtil;
4361
+ ((TownRoomsUtil) => {
4362
+ function shown(list) {
4363
+ return list.filter((room) => room.status === "member" && !room.unlisted).sort((a, b) => (a.joinedAt ?? a.createdAt) - (b.joinedAt ?? b.createdAt) || a.id.localeCompare(b.id)).slice(-MAX_ROOMS);
4364
+ }
4365
+ TownRoomsUtil.shown = shown;
4366
+ TownRoomsUtil.visitorOf = (room, member) => `visitor:${room}:${member}`;
4367
+ function faceOf(id) {
4368
+ let hash2 = 0;
4369
+ for (const char of id) {
4370
+ hash2 = hash2 * 31 + char.charCodeAt(0) >>> 0;
4371
+ }
4372
+ return hash2 % FACES;
4373
+ }
4374
+ TownRoomsUtil.faceOf = faceOf;
4375
+ function of(state, input) {
4376
+ const agents = new Set(input.agents.map((agent) => agent.id));
4377
+ const seated = new Map;
4378
+ for (const room of state.rooms) {
4379
+ const said = state.lines[room.id] ?? [];
4380
+ for (const member of room.members.filter((each) => !each.self && each.online)) {
4381
+ const at = [...said].reverse().find((line) => line.from === member.member)?.at ?? 0;
4382
+ const before = seated.get(member.id);
4383
+ if (!before || at > before.at) {
4384
+ seated.set(member.id, { room: room.id, at });
4385
+ }
4386
+ }
4387
+ }
4388
+ return state.rooms.map((room) => {
4389
+ const said = state.lines[room.id] ?? [];
4390
+ const self = room.members.find((member) => member.self)?.member;
4391
+ const lately = said.filter((line) => line.at > input.now - LIVELY_MS);
4392
+ const busy = new Set;
4393
+ for (const line of lately) {
4394
+ if (line.from === self && line.agent && agents.has(line.agent.id)) {
4395
+ busy.add(line.agent.id);
4396
+ } else if (line.from === self && line.double) {
4397
+ busy.add(DOUBLE_ID);
4398
+ }
4399
+ }
4400
+ const visitors = room.members.filter((member) => !member.self && member.online && seated.get(member.id)?.room === room.id).slice(0, MAX_VISITORS).map((member) => {
4401
+ const line = [...said].reverse().find((each) => each.from === member.member && !each.agent && !each.double);
4402
+ return {
4403
+ id: TownRoomsUtil.visitorOf(room.id, member.member),
4404
+ name: member.name,
4405
+ face: faceOf(member.id),
4406
+ ...line ? { line: { text: line.text, at: line.at } } : {}
4407
+ };
4408
+ });
4409
+ return { id: room.id, title: room.title, visitors, busy: [...busy], look: input.unseen(room.id), lively: lately.length > 0 };
4410
+ });
3762
4411
  }
3763
- return value >>> 0;
3764
- }
3765
- function shade(hex, amount) {
3766
- const value = Number.parseInt(hex.slice(1), 16);
3767
- const channel = (shift) => Math.max(0, Math.min(255, Math.round((value >> shift & 255) * (1 - amount))));
3768
- return `#${(channel(16) << 16 | channel(8) << 8 | channel(0)).toString(16).padStart(6, "0")}`;
3769
- }
3770
- var FURNITURE_PAD = 8;
3771
- var FLAT = new Set(["rug", "flowers", "chair", ...WildArt.FLAT]);
3772
- var LOOKS = { tree: 4, pine: 3, boulder: 3, parasol: 3, towel: 3, peak: 3, reeds: 3 };
3773
- var FurnitureArt;
3774
- ((FurnitureArt) => {
3775
- function flat(item) {
3776
- return FLAT.has(item.kind);
4412
+ TownRoomsUtil.of = of;
4413
+ function unseen(items) {
4414
+ const marked = new Set(items.filter((item) => item.extension === ROOMS_PACKAGE && item.unseen).map((item) => item.id));
4415
+ return (room) => marked.has(room);
3777
4416
  }
3778
- FurnitureArt.flat = flat;
3779
- function variant(item) {
3780
- if (item.kind === "flowers" || item.kind === "shelf") {
3781
- return (item.x + item.y) % 3;
4417
+ TownRoomsUtil.unseen = unseen;
4418
+ function open(pi, room, items) {
4419
+ const item = items.find((each) => each.extension === ROOMS_PACKAGE && each.id === room);
4420
+ if (item) {
4421
+ item.open();
4422
+ } else {
4423
+ pi.ui.showView(ROOMS_VIEW);
3782
4424
  }
3783
- const looks = LOOKS[item.kind];
3784
- return looks ? Math.floor(noise(item.x, item.y, 77) * looks) : 0;
3785
4425
  }
3786
- FurnitureArt.variant = variant;
3787
- function key(item, faces) {
3788
- const variant2 = FurnitureArt.variant(item);
3789
- const face = item.kind === "bed" ? faces.get(item.place ?? "") ?? 0 : "";
3790
- return `furniture:${item.kind}:${item.w}x${item.h}:${variant2}:${face}`;
4426
+ TownRoomsUtil.open = open;
4427
+ function nameOf(line, room, w) {
4428
+ const self = room.members.find((member) => member.self)?.member;
4429
+ const person = room.members.find((member) => member.member === line.from)?.name ?? line.name;
4430
+ if (line.agent) {
4431
+ return line.agent.name;
4432
+ }
4433
+ if (line.double) {
4434
+ return line.from === self ? w.roomMyDouble : TownWords.format(w.roomDouble, { name: person });
4435
+ }
4436
+ return line.from === self ? w.you : person;
3791
4437
  }
3792
- FurnitureArt.key = key;
3793
- function size(item) {
3794
- return { width: item.w * TILE + 2 * FURNITURE_PAD, height: item.h * TILE + 2 * FURNITURE_PAD };
4438
+ TownRoomsUtil.nameOf = nameOf;
4439
+ function mentions(room, w) {
4440
+ return askable(room).map((member) => ({ name: TownWords.format(w.roomDouble, { name: member.name }), detail: w.askDouble }));
3795
4441
  }
3796
- FurnitureArt.size = size;
3797
- function paint(g, item, faces) {
3798
- g.imageSmoothingEnabled = false;
3799
- const variant2 = FurnitureArt.variant(item);
3800
- const shown = { ...item, x: variant2, y: 0 };
3801
- g.save();
3802
- g.translate(FURNITURE_PAD - shown.x * TILE, FURNITURE_PAD);
3803
- paintFurniture(g, shown, faces);
3804
- g.restore();
4442
+ TownRoomsUtil.mentions = mentions;
4443
+ function addressed(text, room, w) {
4444
+ return askable(room).filter((member) => text.includes(`@${TownWords.format(w.roomDouble, { name: member.name })}`)).map((member) => member.member);
3805
4445
  }
3806
- FurnitureArt.paint = paint;
3807
- })(FurnitureArt ||= {});
3808
- function paintFurniture(g, item, faces) {
3809
- const x = item.x * TILE;
3810
- const y = item.y * TILE;
3811
- const w = item.w * TILE;
3812
- const h = item.h * TILE;
3813
- if (WildArt.paint(g, item.kind, x, y, w, h, item.x)) {
3814
- return;
4446
+ TownRoomsUtil.addressed = addressed;
4447
+ function askable(room) {
4448
+ return room.members.filter((member) => !member.self && !member.guest);
4449
+ }
4450
+ })(TownRoomsUtil ||= {});
4451
+
4452
+ // web-src/room-card.tsx
4453
+ var SHOWN = 4;
4454
+ function RoomCard({ pi, room, chat, lines, model, words: w, visitor, onPick, onOpen, onPlay, onClose }) {
4455
+ const X = pi.ui.icons.X;
4456
+ const Gamepad = pi.ui.icons.Gamepad2;
4457
+ const Markdown = pi.ui.Markdown;
4458
+ const Composer = pi.ui.Composer;
4459
+ const place = TownModel.sharedOf(room.id);
4460
+ const here = model.residents.filter((each) => each.place === place);
4461
+ const online = room.members.filter((member2) => member2.online).length;
4462
+ const self = room.members.find((member2) => member2.self);
4463
+ const mentions = React.useMemo(() => TownRoomsUtil.mentions(room, w), [room, w]);
4464
+ const list = React.useRef(null);
4465
+ const said = lines.slice(-SHOWN);
4466
+ const last = said.at(-1)?.id;
4467
+ React.useLayoutEffect(() => {
4468
+ const element = list.current;
4469
+ if (element && last) {
4470
+ element.scrollTop = element.scrollHeight;
4471
+ }
4472
+ }, [last]);
4473
+ const member = visitor ? room.members.find((each) => TownRoomsUtil.visitorOf(room.id, each.member) === visitor.id) : undefined;
4474
+ const status = visitor ? [TownWords.format(w.inRoom, { room: room.title }), member?.guest ? w.roomGuest : ""].filter(Boolean).join(" · ") : [TownWords.format(w.roomOnline, { count: online }), room.owner ? w.ownRoom : TownWords.format(w.roomOf, { name: room.ownerName })].join(" · ");
4475
+ const say = async (text) => {
4476
+ if (!chat || !self) {
4477
+ throw new Error(w.togetherBusy);
4478
+ }
4479
+ const to = TownRoomsUtil.addressed(text, room, w);
4480
+ await chat.say(text, self, to.length ? { to } : {});
4481
+ };
4482
+ const GroupFace = pi.ui.GroupFace;
4483
+ return /* @__PURE__ */ React.createElement("div", {
4484
+ className: "twn-card",
4485
+ role: "dialog",
4486
+ "aria-label": visitor?.name ?? room.title
4487
+ }, /* @__PURE__ */ React.createElement("div", {
4488
+ className: "twn-card-head"
4489
+ }, /* @__PURE__ */ React.createElement("span", {
4490
+ className: "twn-card-face"
4491
+ }, visitor ? /* @__PURE__ */ React.createElement(Sprite, {
4492
+ resident: visitor,
4493
+ scale: 3
4494
+ }) : GroupFace ? /* @__PURE__ */ React.createElement(GroupFace, {
4495
+ members: room.members.map((each) => ({ seed: each.id, face: TownRoomsUtil.faceOf(each.id) })),
4496
+ size: 40
4497
+ }) : /* @__PURE__ */ React.createElement("span", {
4498
+ className: "twn-card-glyph"
4499
+ }, "\uD83C\uDF10")), /* @__PURE__ */ React.createElement("span", {
4500
+ className: "twn-card-text"
4501
+ }, /* @__PURE__ */ React.createElement("span", {
4502
+ className: "twn-card-name"
4503
+ }, visitor?.name ?? room.title), /* @__PURE__ */ React.createElement("span", {
4504
+ className: "twn-card-status"
4505
+ }, visitor && `${TownWords.emoji(visitor)} `, status), !visitor && here.length > 0 && /* @__PURE__ */ React.createElement("span", {
4506
+ className: "twn-card-members"
4507
+ }, here.map((each) => /* @__PURE__ */ React.createElement("button", {
4508
+ type: "button",
4509
+ key: each.id,
4510
+ className: "twn-card-member",
4511
+ title: each.name,
4512
+ onClick: () => onPick(each.id)
4513
+ }, /* @__PURE__ */ React.createElement(Sprite, {
4514
+ resident: each,
4515
+ scale: 1.5
4516
+ }))))), onPlay && /* @__PURE__ */ React.createElement("button", {
4517
+ type: "button",
4518
+ className: "twn-card-go twn-card-possess",
4519
+ title: w.walk3d,
4520
+ onClick: onPlay
4521
+ }, Gamepad && /* @__PURE__ */ React.createElement(Gamepad, {
4522
+ size: 14
4523
+ }), w.playRoom), /* @__PURE__ */ React.createElement("button", {
4524
+ type: "button",
4525
+ className: "twn-card-go",
4526
+ onClick: onOpen
4527
+ }, w.openRoom), /* @__PURE__ */ React.createElement("button", {
4528
+ type: "button",
4529
+ className: "twn-card-close",
4530
+ title: w.close,
4531
+ "aria-label": w.close,
4532
+ onClick: onClose
4533
+ }, X && /* @__PURE__ */ React.createElement(X, {
4534
+ size: 14
4535
+ }))), /* @__PURE__ */ React.createElement("div", {
4536
+ className: "twn-talk"
4537
+ }, /* @__PURE__ */ React.createElement("div", {
4538
+ className: "twn-talk-thread",
4539
+ ref: list,
4540
+ "aria-live": "polite"
4541
+ }, said.length === 0 && /* @__PURE__ */ React.createElement("div", {
4542
+ className: "twn-talk-state twn-talk-quiet"
4543
+ }, w.roomQuiet), said.map((line) => line.from === self?.member && !line.agent && !line.double ? /* @__PURE__ */ React.createElement("div", {
4544
+ key: line.id,
4545
+ className: "twn-talk-said"
4546
+ }, /* @__PURE__ */ React.createElement("span", null, line.text)) : /* @__PURE__ */ React.createElement("div", {
4547
+ key: line.id,
4548
+ className: "twn-talk-reply"
4549
+ }, /* @__PURE__ */ React.createElement("div", {
4550
+ className: "twn-talk-reply-text"
4551
+ }, /* @__PURE__ */ React.createElement("b", null, TownRoomsUtil.nameOf(line, room, w)), Markdown ? /* @__PURE__ */ React.createElement(Markdown, {
4552
+ text: line.text
4553
+ }) : line.text)))), /* @__PURE__ */ React.createElement("div", {
4554
+ className: "twn-talk-box"
4555
+ }, /* @__PURE__ */ React.createElement(Composer, {
4556
+ placeholder: TownWords.format(w.sayInRoom, { room: room.title }),
4557
+ onSend: say,
4558
+ mentions,
4559
+ mentionLabel: mentions.length ? w.mention : undefined
4560
+ }))));
4561
+ }
4562
+ function playable(room) {
4563
+ return room.kind === TOWN_KIND;
4564
+ }
4565
+
4566
+ // web-src/town-camera.ts
4567
+ var ZOOMS = [0.5, 1, 1.5, 2, 2.5, 3, 4];
4568
+ var SLOP = 6;
4569
+ var ACROSS = 28 * 16;
4570
+ var ZOOM_MS = 200;
4571
+ var FLY_MS = 520;
4572
+ var OVERVIEW_ROOM = 0.94;
4573
+ var KEY_SPEED = 420;
4574
+
4575
+ class Glide {
4576
+ static WINDOW_MS = 100;
4577
+ static DECAY = 2;
4578
+ static STOP = 12;
4579
+ static FLICK = 120;
4580
+ static MAX = 6000;
4581
+ samples = [];
4582
+ vx = 0;
4583
+ vy = 0;
4584
+ get moving() {
4585
+ return this.vx !== 0 || this.vy !== 0;
3815
4586
  }
3816
- switch (item.kind) {
3817
- case "tree": {
3818
- const [dark, mid, light] = [
3819
- ["#3f8a45", "#58a957", "#79c46a"],
3820
- ["#2f7a43", "#479a4f", "#66b15f"],
3821
- ["#4c9a48", "#6bbb5c", "#8fd174"],
3822
- ["#c46a2e", "#e08d3c", "#f2b553"]
3823
- ][item.x % 4];
3824
- g.globalAlpha = 0.18;
3825
- rect2(g, "#000000", x + 5, y + 27, 22, 4);
3826
- g.globalAlpha = 1;
3827
- rect2(g, "#7d5a3c", x + 14, y + 20, 4, 9);
3828
- disc2(g, dark, x + 16, y + 13, 13);
3829
- disc2(g, mid, x + 15, y + 11, 11);
3830
- disc2(g, light, x + 12, y + 8, 5);
3831
- disc2(g, light, x + 20, y + 13, 3);
3832
- break;
3833
- }
3834
- case "flowers": {
3835
- for (let index = 0;index < 8; index++) {
3836
- const fx = x + 2 + Math.floor(noise(item.x, item.y, index) * (w - 4));
3837
- const fy = y + 3 + Math.floor(noise(item.y, item.x, index) * (h - 6));
3838
- rect2(g, "#5e9f4c", fx, fy + 1, 1, 2);
3839
- rect2(g, ["#f28fb0", "#ffd166", "#ffffff", "#c39bf0"][index % 4], fx - 1, fy - 1, 3, 2);
3840
- }
3841
- break;
3842
- }
3843
- case "bench": {
3844
- rect2(g, "#6b4a33", x + 2, y + 10, 2, 5);
3845
- rect2(g, "#6b4a33", x + w - 4, y + 10, 2, 5);
3846
- rect2(g, "#b07c4f", x + 1, y + 3, w - 2, 3);
3847
- rect2(g, "#c28d5d", x + 1, y + 8, w - 2, 3);
3848
- rect2(g, "#8f6240", x + 1, y + 11, w - 2, 1);
3849
- break;
4587
+ track(at, x, y) {
4588
+ this.samples.push({ at, x, y });
4589
+ while (this.samples.length > 2 && at - this.samples[0].at > Glide.WINDOW_MS) {
4590
+ this.samples.shift();
3850
4591
  }
3851
- case "lamp": {
3852
- rect2(g, "#4b4b57", x + 7, y + 3, 2, 12);
3853
- rect2(g, "#4b4b57", x + 5, y + 14, 6, 2);
3854
- rect2(g, "#4b4b57", x + 5, y - 2, 6, 2);
3855
- rect2(g, "#ffe8a3", x + 6, y, 4, 3);
3856
- break;
4592
+ }
4593
+ release(at) {
4594
+ const first = this.samples[0];
4595
+ const last = this.samples[this.samples.length - 1];
4596
+ this.samples = [];
4597
+ this.stop();
4598
+ if (!first || !last || last === first || at - last.at > Glide.WINDOW_MS / 2) {
4599
+ return;
3857
4600
  }
3858
- case "bed": {
3859
- const shirt = SHIRTS[faces.get(item.place ?? "") ?? 0];
3860
- rect2(g, "#8f6240", x + 1, y, w - 2, h - 1);
3861
- rect2(g, "#a9774c", x + 1, y, w - 2, 5);
3862
- rect2(g, "#ffffff", x + 4, y + 6, w - 8, 7);
3863
- rect2(g, "#e5e7ec", x + 4, y + 12, w - 8, 1);
3864
- rect2(g, shirt, x + 2, y + 15, w - 4, h - 18);
3865
- rect2(g, shade(shirt, -0.25), x + 2, y + 15, w - 4, 3);
3866
- rect2(g, shade(shirt, 0.18), x + 2, y + h - 5, w - 4, 2);
3867
- break;
4601
+ const seconds = Math.max(0.008, (last.at - first.at) / 1000);
4602
+ const vx = (last.x - first.x) / seconds;
4603
+ const vy = (last.y - first.y) / seconds;
4604
+ const speed = Math.hypot(vx, vy);
4605
+ if (speed < Glide.FLICK) {
4606
+ return;
3868
4607
  }
3869
- case "desk":
3870
- case "workbench": {
3871
- const top = item.kind === "desk" ? "#b98552" : "#a3abb5";
3872
- const front = item.kind === "desk" ? "#94653d" : "#7c858f";
3873
- rect2(g, top, x, y + 5, w, 7);
3874
- rect2(g, front, x, y + 12, w, 3);
3875
- rect2(g, front, x + 1, y + 15, 2, 1);
3876
- rect2(g, front, x + w - 3, y + 15, 2, 1);
3877
- for (let index = 0;index < item.w; index++) {
3878
- const mx = x + index * TILE + 2;
3879
- rect2(g, OUTLINE, mx, y - 3, 12, 9);
3880
- rect2(g, "#2b3342", mx + 1, y - 2, 10, 7);
3881
- rect2(g, OUTLINE, mx + 5, y + 6, 2, 2);
3882
- rect2(g, "#e9e6e0", mx + 2, y + 9, 8, 2);
3883
- }
3884
- break;
4608
+ const scale = Math.min(1, Glide.MAX / speed);
4609
+ this.vx = vx * scale;
4610
+ this.vy = vy * scale;
4611
+ }
4612
+ stop() {
4613
+ this.vx = 0;
4614
+ this.vy = 0;
4615
+ }
4616
+ step(seconds) {
4617
+ if (!this.moving) {
4618
+ return { dx: 0, dy: 0 };
3885
4619
  }
3886
- case "shelf": {
3887
- rect2(g, "#8d633f", x, y - 6, w, h + 4);
3888
- rect2(g, "#6f4b2e", x, y + h - 3, w, 1);
3889
- const colors = ["#e46b5d", "#4f8fd6", "#f2c14e", "#62b87a", "#a678d6", "#ef9a62"];
3890
- for (let shelf = 0;shelf < 2; shelf++) {
3891
- const sy = y - 4 + shelf * 9;
3892
- for (let bx = x + 1;bx < x + w - 2; bx += 3) {
3893
- rect2(g, colors[(bx + shelf * 3 + item.y) % colors.length], bx, sy, 2, 7);
3894
- }
3895
- rect2(g, "#6f4b2e", x, sy + 7, w, 1);
3896
- }
3897
- break;
4620
+ const keep = Math.exp(-Glide.DECAY * seconds);
4621
+ const travel = (1 - keep) / Glide.DECAY;
4622
+ const move = { dx: this.vx * travel, dy: this.vy * travel };
4623
+ this.vx *= keep;
4624
+ this.vy *= keep;
4625
+ if (Math.hypot(this.vx, this.vy) < Glide.STOP) {
4626
+ this.stop();
3898
4627
  }
3899
- case "plant": {
3900
- rect2(g, "#c2774f", x + 4, y + 9, 8, 6);
3901
- rect2(g, "#a5603c", x + 4, y + 9, 8, 1);
3902
- disc2(g, "#4f9a4a", x + 8, y + 5, 5);
3903
- disc2(g, "#6cbb5f", x + 7, y + 4, 3);
3904
- break;
4628
+ return move;
4629
+ }
4630
+ reset() {
4631
+ this.samples = [];
4632
+ this.stop();
4633
+ }
4634
+ }
4635
+ var StageSize;
4636
+ ((StageSize) => {
4637
+ function next(measured, full, typing) {
4638
+ if (!typing) {
4639
+ return { size: measured, full: measured };
3905
4640
  }
3906
- case "rug": {
3907
- rect2(g, "#d9968a", x + 1, y + 2, w - 2, h - 4);
3908
- rect2(g, "#efb9a8", x + 3, y + 4, w - 6, h - 8);
3909
- for (let rx = x + 5;rx < x + w - 5; rx += 4) {
3910
- rect2(g, "#d9968a", rx, y + h / 2 - 1, 2, 2);
3911
- }
3912
- break;
4641
+ if (full && full.width === measured.width) {
4642
+ return { size: { width: measured.width, height: Math.max(measured.height, full.height) }, full };
3913
4643
  }
3914
- case "table": {
3915
- rect2(g, "#c69560", x, y + 2, w, h - 5);
3916
- rect2(g, "#a77845", x, y + h - 3, w, 3);
3917
- for (let index = 0;index < item.w; index += 2) {
3918
- rect2(g, "#ffffff", x + index * TILE + 5, y + 7 + index % 4 * 3, 7, 9);
3919
- rect2(g, "#c9ced8", x + index * TILE + 6, y + 9 + index % 4 * 3, 5, 1);
4644
+ return { size: measured, full };
4645
+ }
4646
+ StageSize.next = next;
4647
+ })(StageSize ||= {});
4648
+
4649
+ class TownCamera {
4650
+ scene;
4651
+ ratio;
4652
+ host;
4653
+ following;
4654
+ index = 2;
4655
+ press;
4656
+ pinch;
4657
+ glide = new Glide;
4658
+ zooming;
4659
+ resolution = 0;
4660
+ clear;
4661
+ before;
4662
+ smoothed = false;
4663
+ keys;
4664
+ constructor(scene, ratio, host) {
4665
+ this.scene = scene;
4666
+ this.ratio = ratio;
4667
+ this.host = host;
4668
+ }
4669
+ get camera() {
4670
+ return this.scene.cameras.main;
4671
+ }
4672
+ listen() {
4673
+ const { scene } = this;
4674
+ scene.input.addPointer(1);
4675
+ scene.scale.on("resize", () => {
4676
+ if (this.before) {
4677
+ this.fly(this.fitAll(), this.mapMiddle(this.fitAll()), 0);
4678
+ } else {
4679
+ this.zoomAt(this.camera.zoom, this.scene.scale.width / 2, this.middleY());
3920
4680
  }
3921
- rect2(g, "#3a3f4b", x + w / 2 - 6, y + 12, 12, 7);
3922
- rect2(g, "#7fb0e0", x + w / 2 - 5, y + 13, 10, 4);
3923
- break;
3924
- }
3925
- case "chair": {
3926
- rect2(g, "#7c5b44", x + 3, y + 6, 10, 8);
3927
- rect2(g, "#9a7559", x + 4, y + 7, 8, 5);
3928
- break;
3929
- }
3930
- case "whiteboard": {
3931
- rect2(g, "#aab1bd", x + 2, y + 1, w - 4, 12);
3932
- rect2(g, "#ffffff", x + 3, y + 2, w - 6, 10);
3933
- rect2(g, "#e46b5d", x + 6, y + 4, 14, 1);
3934
- rect2(g, "#4f8fd6", x + 6, y + 7, 22, 1);
3935
- rect2(g, "#62b87a", x + 30, y + 4, 12, 5);
3936
- rect2(g, "#4f8fd6", x + w - 26, y + 9, 16, 1);
3937
- break;
3938
- }
3939
- case "board": {
3940
- rect2(g, "#a8784a", x + 2, y + 1, w - 4, 12);
3941
- rect2(g, "#c99d6b", x + 3, y + 2, w - 6, 10);
3942
- const notes = ["#ffe17a", "#9ad7f5", "#f7a8c4", "#b9e6a0"];
3943
- for (let index = 0;index < 7; index++) {
3944
- rect2(g, notes[index % notes.length], x + 6 + index * 10, y + 3 + index % 2 * 3, 6, 5);
4681
+ });
4682
+ scene.input.on("pointerdown", (pointer) => this.down(pointer));
4683
+ scene.input.on("pointermove", (pointer) => this.move(pointer));
4684
+ scene.input.on("pointerup", (pointer) => this.up(pointer));
4685
+ scene.input.on("wheel", (pointer, _objects, dx, dy) => {
4686
+ const event = pointer.event;
4687
+ if (event?.ctrlKey || event?.metaKey) {
4688
+ this.zoomBy(dy < 0 ? 1 : -1, pointer);
4689
+ return;
3945
4690
  }
3946
- break;
4691
+ this.following = undefined;
4692
+ this.glide.stop();
4693
+ this.camera.scrollX += dx / this.camera.zoom;
4694
+ this.camera.scrollY += dy / this.camera.zoom;
4695
+ });
4696
+ const keyboard = scene.input.keyboard;
4697
+ if (keyboard) {
4698
+ this.keys = keyboard.addKeys({ up: "UP", down: "DOWN", left: "LEFT", right: "RIGHT", w: "W", a: "A", s: "S", d: "D" }, false);
4699
+ keyboard.on("keydown", (event) => {
4700
+ if (event.key === "+" || event.key === "=") {
4701
+ this.zoomBy(1);
4702
+ } else if (event.key === "-" || event.key === "_") {
4703
+ this.zoomBy(-1);
4704
+ } else if (event.key.toLowerCase() === "m") {
4705
+ this.toggleOverview();
4706
+ }
4707
+ });
3947
4708
  }
3948
- case "sofa": {
3949
- rect2(g, "#5f8eac", x, y + 1, w, h - 2);
3950
- rect2(g, "#7aa6c2", x + 3, y + 4, w - 6, 7);
3951
- for (let sx = x + 3 + 14;sx < x + w - 3; sx += 14) {
3952
- rect2(g, "#5f8eac", sx, y + 4, 1, 7);
4709
+ }
4710
+ step(seconds) {
4711
+ const keys = this.keys;
4712
+ if (keys) {
4713
+ const dx2 = (keys.right.isDown || keys.d.isDown ? 1 : 0) - (keys.left.isDown || keys.a.isDown ? 1 : 0);
4714
+ const dy2 = (keys.down.isDown || keys.s.isDown ? 1 : 0) - (keys.up.isDown || keys.w.isDown ? 1 : 0);
4715
+ if (dx2 || dy2) {
4716
+ const { camera: camera2 } = this;
4717
+ const speed = KEY_SPEED * this.ratio * seconds / camera2.zoom;
4718
+ this.following = undefined;
4719
+ this.glide.stop();
4720
+ camera2.scrollX = camera2.clampX(camera2.scrollX + dx2 * speed);
4721
+ camera2.scrollY = camera2.clampY(camera2.scrollY + dy2 * speed);
3953
4722
  }
3954
- break;
3955
- }
3956
- case "crate": {
3957
- rect2(g, "#c08f5a", x + 1, y + 2, 14, 13);
3958
- rect2(g, "#9a6e40", x + 1, y + 2, 14, 1);
3959
- rect2(g, "#9a6e40", x + 1, y + 8, 14, 1);
3960
- rect2(g, "#9a6e40", x + 7, y + 2, 1, 13);
3961
- break;
3962
- }
3963
- case "bush":
3964
- disc2(g, "#58a957", x + 8, y + 9, 6);
3965
- break;
3966
- case "coffee": {
3967
- rect2(g, "#8d633f", x + 2, y + 8, 12, 7);
3968
- rect2(g, "#3a3f4b", x + 3, y - 3, 10, 12);
3969
- rect2(g, "#555c6b", x + 4, y - 2, 8, 3);
3970
- rect2(g, "#e46b5d", x + 10, y - 1, 1, 1);
3971
- rect2(g, "#1f232b", x + 6, y + 3, 4, 3);
3972
- rect2(g, "#ffffff", x + 6, y + 5, 4, 3);
3973
- break;
3974
4723
  }
3975
- case "cooler": {
3976
- rect2(g, "#d9dde4", x + 4, y + 4, 8, 11);
3977
- rect2(g, "#b9bfc9", x + 4, y + 13, 8, 2);
3978
- rect2(g, "#7fc6ea", x + 5, y - 4, 6, 8);
3979
- rect2(g, "#b1e0f6", x + 6, y - 3, 2, 5);
3980
- rect2(g, "#4f8fd6", x + 7, y + 7, 2, 1);
3981
- break;
4724
+ if (!this.glide.moving) {
4725
+ return;
3982
4726
  }
3983
- case "floorlamp": {
3984
- rect2(g, "#4b4b57", x + 7, y - 2, 2, 15);
3985
- rect2(g, "#4b4b57", x + 5, y + 13, 6, 2);
3986
- rect2(g, "#f6d58a", x + 3, y - 7, 10, 6);
3987
- rect2(g, "#e8c06a", x + 3, y - 2, 10, 1);
3988
- break;
4727
+ const { camera } = this;
4728
+ const { dx, dy } = this.glide.step(seconds);
4729
+ const before = { x: camera.scrollX, y: camera.scrollY };
4730
+ camera.scrollX = camera.clampX(camera.scrollX - dx / camera.zoom);
4731
+ camera.scrollY = camera.clampY(camera.scrollY - dy / camera.zoom);
4732
+ if (camera.scrollX === before.x) {
4733
+ this.glide.vx = 0;
3989
4734
  }
3990
- case "tv": {
3991
- rect2(g, "#8d633f", x + 1, y + 9, 14, 6);
3992
- rect2(g, OUTLINE, x + 1, y - 2, 14, 10);
3993
- rect2(g, "#3d5a80", x + 2, y - 1, 12, 8);
3994
- rect2(g, "#5c7fa8", x + 3, y, 5, 2);
3995
- break;
4735
+ if (camera.scrollY === before.y) {
4736
+ this.glide.vy = 0;
3996
4737
  }
3997
- case "kiosk": {
3998
- rect2(g, "#b07c4f", x + 2, y + 10, w - 4, h - 12);
3999
- rect2(g, "#c99d6b", x + 2, y + 10, w - 4, 3);
4000
- for (let index = 0;index < 8; index++) {
4001
- rect2(g, index % 2 === 0 ? "#e46b5d" : "#fff6e8", x + index * (w / 8), y - 4, w / 8, 8);
4002
- }
4003
- rect2(g, "#9a5132", x, y + 4, w, 2);
4004
- rect2(g, "#4b4b57", x + 3, y + 4, 2, 8);
4005
- rect2(g, "#4b4b57", x + w - 5, y + 4, 2, 8);
4006
- for (let cup = 0;cup < 3; cup++) {
4007
- rect2(g, "#ffffff", x + 14 + cup * 9, y + 7, 4, 4);
4008
- rect2(g, "#7a4a2a", x + 15 + cup * 9, y + 7, 2, 1);
4738
+ }
4739
+ fit() {
4740
+ const width = this.scene.scale.width / this.ratio;
4741
+ this.index = TownCamera.nearest(Math.max(1.5, Math.min(3, width / ACROSS)));
4742
+ this.zoomAt(this.whole(ZOOMS[this.index]), this.scene.scale.width / 2, this.scene.scale.height / 2);
4743
+ }
4744
+ zoomBy(change, about) {
4745
+ if (this.before) {
4746
+ if (change > 0) {
4747
+ this.leaveOverview(about && this.camera.getWorldPoint(about.x, about.y));
4009
4748
  }
4010
- rect2(g, "#2f3a33", x + w - 18, y + 14, 12, 9);
4011
- rect2(g, "#f2e8cf", x + w - 16, y + 16, 8, 1);
4012
- rect2(g, "#f2e8cf", x + w - 16, y + 19, 6, 1);
4013
- break;
4749
+ return;
4014
4750
  }
4015
- case "umbrella": {
4016
- rect2(g, "#c69560", x + 6, y + 14, 20, 12);
4017
- rect2(g, "#a77845", x + 6, y + 24, 20, 2);
4018
- const stripes = ["#62b87a", "#fff6e8"];
4019
- for (let ring = 0;ring < 8; ring++) {
4020
- disc2(g, stripes[ring % 2], x + 16, y + 10, 13 - ring * 1.6);
4021
- }
4022
- rect2(g, "#4b4b57", x + 15, y + 9, 2, 2);
4023
- break;
4751
+ if (change < 0 && this.index === 0) {
4752
+ this.toggleOverview();
4753
+ return;
4024
4754
  }
4025
- case "toolwall": {
4026
- rect2(g, "#a8784a", x + 1, y + 1, w - 2, 12);
4027
- rect2(g, "#c99d6b", x + 2, y + 2, w - 4, 10);
4028
- const tools = ["#7c858f", "#e46b5d", "#4f8fd6", "#f2c14e", "#62b87a"];
4029
- for (let index = 0;index < 6; index++) {
4030
- const tx = x + 5 + index * 7;
4031
- rect2(g, "#6f4b2e", tx, y + 3, 1, 1);
4032
- rect2(g, tools[index % tools.length], tx - 1, y + 4, 3, 2);
4033
- rect2(g, "#4b4b57", tx, y + 6, 1, 5);
4034
- }
4035
- break;
4755
+ this.index = Math.max(0, Math.min(ZOOMS.length - 1, this.index + change));
4756
+ this.settle(this.whole(ZOOMS[this.index]), about?.x ?? this.scene.scale.width / 2, about?.y ?? this.middleY());
4757
+ }
4758
+ get overviewing() {
4759
+ return !!this.before;
4760
+ }
4761
+ setClear(clear) {
4762
+ this.clear = clear;
4763
+ if (this.before && !this.zooming) {
4764
+ const zoom = this.fitAll();
4765
+ this.fly(zoom, this.mapMiddle(zoom), this.host.reduceMotion() ? 0 : ZOOM_MS);
4766
+ this.host.overview?.(true, zoom);
4036
4767
  }
4037
4768
  }
4038
- }
4039
- function lookOf(id, face) {
4040
- const hash2 = hashText(id);
4041
- return {
4042
- skin: SKINS[hash2 % SKINS.length],
4043
- hair: HAIRS[(hash2 >>> 4) % HAIRS.length],
4044
- shirt: SHIRTS[face ?? hash2 % SHIRTS.length],
4045
- pants: PANTS[(hash2 >>> 9) % PANTS.length]
4046
- };
4047
- }
4048
- var BODY = {
4049
- down: [
4050
- "...kkkkkk...",
4051
- "..khhhhhhk..",
4052
- ".khhhhhhhhk.",
4053
- ".khhhhhhhhk.",
4054
- ".khsssssshk.",
4055
- ".ksessssesk.",
4056
- ".ksrssssrsk.",
4057
- "..kssssssk..",
4058
- ".kcccccccck.",
4059
- "kscccccccsk.",
4060
- "kscccccccsk.",
4061
- ".kddddddddk.",
4062
- ".kppppppppk."
4063
- ],
4064
- up: [
4065
- "...kkkkkk...",
4066
- "..khhhhhhk..",
4067
- ".khhhhhhhhk.",
4068
- ".khhhhhhhhk.",
4069
- ".khhhhhhhhk.",
4070
- ".khhhhhhhhk.",
4071
- ".khhhhhhhhk.",
4072
- "..khhhhhhk..",
4073
- ".kcccccccck.",
4074
- "kscccccccsk.",
4075
- "kscccccccsk.",
4076
- ".kddddddddk.",
4077
- ".kppppppppk."
4078
- ],
4079
- left: [
4080
- "...kkkkkk...",
4081
- "..khhhhhhk..",
4082
- ".khhhhhhhhk.",
4083
- ".khhhhhhhhk.",
4084
- ".ksshhhhhhk.",
4085
- ".kesshhhhhk.",
4086
- ".krsshhhhhk.",
4087
- "..ksssshhk..",
4088
- "..kcccccck..",
4089
- "..kcscccck..",
4090
- "..kcscccck..",
4091
- "..kddddddk..",
4092
- "..kppppppk.."
4093
- ]
4094
- };
4095
- var LEGS = {
4096
- down: [
4097
- ["..kppkkppk..", "..kbbkkbbk..", "...kk..kk..."],
4098
- ["..kppkkppk..", "..kbbkkbbk..", "...kk......."],
4099
- ["..kppkkppk..", "..kbbkkbbk..", ".......kk..."]
4100
- ],
4101
- up: [
4102
- ["..kppkkppk..", "..kbbkkbbk..", "...kk..kk..."],
4103
- ["..kppkkppk..", "..kbbkkbbk..", "...kk......."],
4104
- ["..kppkkppk..", "..kbbkkbbk..", ".......kk..."]
4105
- ],
4106
- left: [
4107
- ["...kppppk...", "..kbbbbbk...", "..kkkkkk...."],
4108
- ["..kppkppk...", ".kbbk.kbbk..", ".kkk...kkk.."],
4109
- ["...kppppk...", "..kbbbbbk...", "..kkkkkk...."]
4110
- ]
4111
- };
4112
- function frameRows(direction, step) {
4113
- return [...BODY[direction], ...LEGS[direction][step]];
4114
- }
4115
- function paintResident(g, look) {
4116
- const colors = {
4117
- k: OUTLINE,
4118
- h: look.hair,
4119
- s: look.skin,
4120
- e: OUTLINE,
4121
- r: "#f19a96",
4122
- c: look.shirt,
4123
- d: shade(look.shirt, 0.22),
4124
- p: look.pants,
4125
- b: "#3b3330"
4126
- };
4127
- DIRECTIONS.forEach((direction, d) => {
4128
- for (let step = 0;step < STEPS2; step++) {
4129
- const left = (d * STEPS2 + step) * SPRITE.w;
4130
- frameRows(direction, step).forEach((row, y) => {
4131
- [...row].forEach((pixel, x) => {
4132
- if (pixel !== ".") {
4133
- rect2(g, colors[pixel], left + x, y, 1, 1);
4134
- }
4135
- });
4136
- });
4769
+ inClear(point) {
4770
+ const { camera } = this;
4771
+ const y = (point.y - camera.worldView.y) * camera.zoom;
4772
+ const x = (point.x - camera.worldView.x) * camera.zoom;
4773
+ const { top, bottom } = this.clearView();
4774
+ return x >= 0 && x <= this.scene.scale.width && y >= top && y <= bottom;
4775
+ }
4776
+ toggleOverview() {
4777
+ if (this.before) {
4778
+ this.leaveOverview();
4779
+ return;
4137
4780
  }
4138
- });
4139
- }
4140
- var DINO_ROWS = [
4141
- "..........######",
4142
- ".........##o####",
4143
- ".........#######",
4144
- ".........#######",
4145
- ".........####...",
4146
- ".........######.",
4147
- "#.......#####...",
4148
- "#......#######..",
4149
- "##...#########..",
4150
- "###.#######.#...",
4151
- "###########.....",
4152
- ".#########......",
4153
- "..#######.......",
4154
- "...#####........"
4155
- ];
4156
- var DINO_LEGS = [
4157
- ["...##.##........", "...#...#........", "...##..##......."],
4158
- ["...##.##........", "...##...#.......", ".......##......."],
4159
- ["...##.##........", "...#....#.......", "...##...##......"]
4160
- ];
4161
- function paintDino(g) {
4162
- DINO_LEGS.forEach((legs, frame) => {
4163
- [...DINO_ROWS, ...legs].forEach((row, y) => {
4164
- [...row].forEach((pixel, x) => {
4165
- if (pixel !== ".") {
4166
- rect2(g, pixel === "o" ? "#ffffff" : TA_GREEN, frame * DINO.w + x, y, 1, 1);
4167
- }
4168
- });
4781
+ const { camera } = this;
4782
+ const mid = camera.midPoint;
4783
+ this.before = { zoom: camera.zoom, index: this.index, x: mid.x, y: mid.y - this.below() };
4784
+ this.following = undefined;
4785
+ this.glide.reset();
4786
+ this.zooming?.stop();
4787
+ camera.useBounds = false;
4788
+ const zoom = this.fitAll();
4789
+ this.fly(zoom, this.mapMiddle(zoom), this.host.reduceMotion() ? 0 : FLY_MS);
4790
+ this.host.overview?.(true, zoom);
4791
+ }
4792
+ leaveOverview(point) {
4793
+ const before = this.before;
4794
+ if (!before) {
4795
+ return;
4796
+ }
4797
+ const zoom = before.zoom;
4798
+ const target = point ?? { x: before.x, y: before.y };
4799
+ this.endOverview();
4800
+ this.index = before.index;
4801
+ this.fly(zoom, this.within({ x: target.x, y: target.y + this.offsetAt(zoom) }, zoom), this.host.reduceMotion() ? 0 : FLY_MS, () => {
4802
+ this.camera.useBounds = true;
4169
4803
  });
4170
- });
4171
- }
4172
-
4173
- // web-src/town-card.tsx
4174
- function Sprite({ resident, scale = 2 }) {
4175
- const canvas = React.useRef(null);
4176
- const double = resident.id === DOUBLE_ID;
4177
- const size = double ? DINO : SPRITE;
4178
- React.useEffect(() => {
4179
- const context = canvas.current?.getContext("2d");
4180
- if (!context) {
4804
+ }
4805
+ endOverview() {
4806
+ this.before = undefined;
4807
+ this.host.overview?.(false, this.camera.zoom);
4808
+ }
4809
+ within(center2, zoom) {
4810
+ const bounds = this.camera.getBounds();
4811
+ const half = { x: this.scene.scale.width / zoom / 2, y: this.scene.scale.height / zoom / 2 };
4812
+ const clamp = (value, low, high) => low > high ? (low + high) / 2 : Math.max(low, Math.min(high, value));
4813
+ return {
4814
+ x: clamp(center2.x, bounds.x + half.x, bounds.right - half.x),
4815
+ y: clamp(center2.y, bounds.y + half.y, bounds.bottom - half.y)
4816
+ };
4817
+ }
4818
+ fitAll() {
4819
+ const { width, height } = this.host.world();
4820
+ const { top, bottom } = this.clearView();
4821
+ return Math.max(0.05, Math.min(this.scene.scale.width / width, (bottom - top) / height) * OVERVIEW_ROOM);
4822
+ }
4823
+ mapMiddle(zoom) {
4824
+ const { width, height } = this.host.world();
4825
+ return { x: width / 2, y: height / 2 + (this.scene.scale.height / 2 - this.middleY()) / zoom };
4826
+ }
4827
+ fly(zoom, center2, duration, done) {
4828
+ const { camera } = this;
4829
+ this.zooming?.stop();
4830
+ this.zooming = undefined;
4831
+ const from = { zoom: camera.zoom, x: camera.midPoint.x, y: camera.midPoint.y };
4832
+ const at = (t) => {
4833
+ const z = from.zoom * (zoom / from.zoom) ** t;
4834
+ const k = from.zoom === zoom ? t : (1 / from.zoom - 1 / z) / (1 / from.zoom - 1 / zoom);
4835
+ this.setZoom(z);
4836
+ camera.centerOn(from.x + (center2.x - from.x) * k, from.y + (center2.y - from.y) * k);
4837
+ };
4838
+ if (duration <= 0) {
4839
+ at(1);
4840
+ done?.();
4181
4841
  return;
4182
4842
  }
4183
- const sheet = document.createElement("canvas");
4184
- sheet.width = size.w * 9;
4185
- sheet.height = size.h;
4186
- const paint = sheet.getContext("2d");
4187
- if (!paint) {
4843
+ this.zooming = this.scene.tweens.addCounter({
4844
+ from: 0,
4845
+ to: 1,
4846
+ duration,
4847
+ ease: "Cubic.easeInOut",
4848
+ onUpdate: (tween) => at(tween.getValue() ?? 1),
4849
+ onComplete: () => {
4850
+ at(1);
4851
+ this.zooming = undefined;
4852
+ done?.();
4853
+ }
4854
+ });
4855
+ }
4856
+ setZoom(zoom) {
4857
+ this.camera.setZoom(zoom);
4858
+ const smooth = zoom < 1;
4859
+ if (smooth !== this.smoothed) {
4860
+ this.smoothed = smooth;
4861
+ this.host.smooth?.(smooth);
4862
+ }
4863
+ if (Number.isInteger(zoom) && zoom !== this.resolution) {
4864
+ this.resolution = zoom;
4865
+ for (const text of this.host.texts()) {
4866
+ text.setResolution(zoom);
4867
+ }
4868
+ }
4869
+ }
4870
+ clearView() {
4871
+ const height = this.scene.scale.height;
4872
+ const clear = this.clear;
4873
+ return clear && clear.bottom - clear.top > 40 ? { top: Math.max(0, clear.top), bottom: Math.min(height, clear.bottom) } : { top: 0, bottom: height };
4874
+ }
4875
+ middleY() {
4876
+ const { top, bottom } = this.clearView();
4877
+ return (top + bottom) / 2;
4878
+ }
4879
+ panTo(point, follow) {
4880
+ this.following = follow;
4881
+ this.glide.stop();
4882
+ if (this.before) {
4883
+ this.leaveOverview(point);
4884
+ this.following = follow;
4188
4885
  return;
4189
4886
  }
4190
- if (double) {
4191
- paintDino(paint);
4192
- } else {
4193
- paintResident(paint, lookOf(resident.id, resident.face));
4887
+ this.camera.pan(point.x, point.y + this.below(), this.host.reduceMotion() ? 0 : 450, "Sine.easeInOut");
4888
+ }
4889
+ keepOn(point, seconds) {
4890
+ const { camera } = this;
4891
+ const mid = camera.midPoint;
4892
+ const pull = Math.min(1, seconds * 4);
4893
+ camera.centerOn(mid.x + (point.x - mid.x) * pull, mid.y + (point.y + this.below() - mid.y) * pull);
4894
+ }
4895
+ whole(zoom) {
4896
+ return Math.max(1, Math.floor(zoom * this.ratio + 0.25));
4897
+ }
4898
+ zoomAt(zoom, x, y) {
4899
+ const { camera } = this;
4900
+ const width = camera.width;
4901
+ const height = camera.height;
4902
+ const worldX = camera.scrollX + width / 2 + (x - width / 2) / camera.zoom;
4903
+ const worldY = camera.scrollY + height / 2 + (y - height / 2) / camera.zoom;
4904
+ this.setZoom(zoom);
4905
+ camera.scrollX = camera.clampX(worldX - width / 2 - (x - width / 2) / zoom);
4906
+ camera.scrollY = camera.clampY(worldY - height / 2 - (y - height / 2) / zoom);
4907
+ }
4908
+ settle(zoom, x, y) {
4909
+ this.zooming?.stop();
4910
+ this.zooming = undefined;
4911
+ const from = this.camera.zoom;
4912
+ if (from === zoom || this.host.reduceMotion()) {
4913
+ this.zoomAt(zoom, x, y);
4914
+ return;
4194
4915
  }
4195
- context.clearRect(0, 0, size.w, size.h);
4196
- context.drawImage(sheet, 0, 0, size.w, size.h, 0, 0, size.w, size.h);
4197
- }, [double, resident.id, resident.face, size]);
4198
- return /* @__PURE__ */ React.createElement("canvas", {
4199
- ref: canvas,
4200
- className: "twn-sprite",
4201
- width: size.w,
4202
- height: size.h,
4203
- style: { width: size.w * scale, height: size.h * scale }
4204
- });
4205
- }
4206
- function talkTarget(data, resident, w) {
4207
- const agent = data.team.agents.find((each) => each.id === resident.id);
4208
- const placeholder = TownWords.format(w.talkTo, { name: resident.name });
4209
- return resident.id === DOUBLE_ID ? { to: DOUBLE_ID, kind: "double", placeholder } : agent ? { to: agent.id, kind: "agent", agent, placeholder } : undefined;
4210
- }
4211
- function TownCard({ pi, data, model, id, tasks, words: w, talk, onPick, onOpen, onPossess, onClose }) {
4212
- const place = model.places.find((each) => each.id === id);
4213
- const residentId = place?.kind === "office" ? DOUBLE_ID : place?.kind === "home" ? place.owner : place ? undefined : id;
4214
- const resident = residentId ? model.residents.find((each) => each.id === residentId) : undefined;
4215
- const X = pi.ui.icons.X;
4216
- const Gamepad = pi.ui.icons.Gamepad2;
4217
- let face;
4218
- let title;
4219
- let status;
4220
- let body;
4221
- let action;
4222
- let target;
4223
- let members;
4224
- if (resident) {
4225
- face = /* @__PURE__ */ React.createElement(Sprite, {
4226
- resident,
4227
- scale: 3
4916
+ this.zooming = this.scene.tweens.addCounter({
4917
+ from,
4918
+ to: zoom,
4919
+ duration: ZOOM_MS,
4920
+ ease: "Cubic.easeOut",
4921
+ onUpdate: (tween) => this.zoomAt(tween.getValue() ?? zoom, x, y),
4922
+ onComplete: () => {
4923
+ this.zoomAt(zoom, x, y);
4924
+ this.zooming = undefined;
4925
+ }
4228
4926
  });
4229
- title = resident.name;
4230
- status = `${TownWords.emoji(resident)} ${TownWords.status(w, resident)}`;
4231
- body = resident.line && !talk.talks.some((each) => each.to === resident.id) && /* @__PURE__ */ React.createElement("span", {
4232
- className: "twn-card-line"
4233
- }, resident.line);
4234
- action = { label: w.open, run: () => onOpen(resident.id) };
4235
- target = talkTarget(data, resident, w);
4236
- } else if (place?.kind === "meeting") {
4237
- const channel = data.team.channels.find((each) => TownModel.roomOf(each.id) === id);
4238
- members = (channel?.members ?? []).map((member) => model.residents.find((each) => each.id === member)).filter((each) => !!each);
4239
- const messages = (channel && data.messages[channel.id]) ?? [];
4240
- const name = (author) => author === "user" ? w.you : author === "ta" ? "Ta" : data.team.agents.find((each) => each.id === author)?.name ?? "";
4241
- face = /* @__PURE__ */ React.createElement("span", {
4242
- className: "twn-card-glyph"
4243
- }, "#");
4244
- title = `#${place.name}`;
4245
- status = TownWords.format(w.members, { count: members.length });
4246
- body = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
4247
- className: "twn-card-members"
4248
- }, members.map((member) => /* @__PURE__ */ React.createElement("button", {
4249
- type: "button",
4250
- key: member.id,
4251
- className: "twn-card-member",
4252
- title: member.name,
4253
- onClick: () => onPick(member.id)
4254
- }, /* @__PURE__ */ React.createElement(Sprite, {
4255
- resident: member,
4256
- scale: 1.5
4257
- })))), messages.length === 0 ? /* @__PURE__ */ React.createElement("span", {
4258
- className: "twn-card-line"
4259
- }, w.noMessages) : messages.filter((message) => message.author !== "system").slice(-3).map((message) => /* @__PURE__ */ React.createElement("span", {
4260
- key: message.id,
4261
- className: "twn-card-line twn-card-message"
4262
- }, /* @__PURE__ */ React.createElement("b", null, name(message.author)), " ", message.text.replace(/\s+/g, " "))));
4263
- target = channel && { to: id, kind: "room", channelId: channel.id, placeholder: TownWords.format(w.postTo, { channel: channel.name }) };
4264
- } else if (place?.kind === "bench") {
4265
- const task = tasks.find((each) => TownModel.benchOf(each.key) === id);
4266
- if (!task) {
4267
- return null;
4927
+ }
4928
+ below() {
4929
+ return this.offsetAt(this.camera.zoom);
4930
+ }
4931
+ offsetAt(zoom) {
4932
+ const { top, bottom } = this.clearView();
4933
+ return (this.scene.scale.height / 2 - (top + (bottom - top) * 0.45)) / zoom;
4934
+ }
4935
+ touches() {
4936
+ return this.scene.input.manager.pointers.filter((each) => each.isDown);
4937
+ }
4938
+ startPinch(a, b) {
4939
+ this.zooming?.stop();
4940
+ this.zooming = undefined;
4941
+ if (this.before) {
4942
+ this.endOverview();
4943
+ this.camera.useBounds = true;
4944
+ }
4945
+ this.pinch = { distance: Math.max(1, Math.hypot(a.x - b.x, a.y - b.y)), zoom: this.camera.zoom, x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
4946
+ this.press = undefined;
4947
+ this.following = undefined;
4948
+ this.glide.reset();
4949
+ }
4950
+ startPress(pointer, moved, caught) {
4951
+ const { camera } = this;
4952
+ this.press = { x: pointer.x, y: pointer.y, sx: camera.scrollX, sy: camera.scrollY, moved, caught };
4953
+ this.glide.reset();
4954
+ this.glide.track(performance.now(), pointer.x, pointer.y);
4955
+ }
4956
+ down(pointer) {
4957
+ const touches = this.touches();
4958
+ if (touches.length >= 2) {
4959
+ this.startPinch(touches[0], touches[1]);
4960
+ return;
4268
4961
  }
4269
- const Icon = task.icon;
4270
- face = Icon ? /* @__PURE__ */ React.createElement(Icon, {
4271
- size: 40
4272
- }) : /* @__PURE__ */ React.createElement("span", {
4273
- className: "twn-card-glyph"
4274
- }, "✦");
4275
- title = task.title;
4276
- status = { running: w.taskRunning, waiting: w.taskWaiting, done: w.taskDone, failed: w.taskFailed, stopped: w.taskStopped }[task.status];
4277
- body = task.detail && /* @__PURE__ */ React.createElement("span", {
4278
- className: "twn-card-line"
4279
- }, task.detail);
4280
- action = { label: w.watch, run: () => task.open() };
4281
- } else {
4282
- return null;
4962
+ const caught = this.glide.moving || !!this.zooming;
4963
+ this.camera.panEffect.reset();
4964
+ this.startPress(pointer, false, caught);
4283
4965
  }
4284
- return /* @__PURE__ */ React.createElement("div", {
4285
- className: "twn-card",
4286
- role: "dialog",
4287
- "aria-label": title
4288
- }, /* @__PURE__ */ React.createElement("div", {
4289
- className: "twn-card-head"
4290
- }, /* @__PURE__ */ React.createElement("span", {
4291
- className: "twn-card-face"
4292
- }, face), /* @__PURE__ */ React.createElement("span", {
4293
- className: "twn-card-text"
4294
- }, /* @__PURE__ */ React.createElement("span", {
4295
- className: "twn-card-name"
4296
- }, title), /* @__PURE__ */ React.createElement("span", {
4297
- className: "twn-card-status"
4298
- }, status), body), resident && onPossess && /* @__PURE__ */ React.createElement("button", {
4299
- type: "button",
4300
- className: "twn-card-go twn-card-possess",
4301
- title: w.walk3d,
4302
- onClick: () => onPossess(resident.id)
4303
- }, Gamepad && /* @__PURE__ */ React.createElement(Gamepad, {
4304
- size: 14
4305
- }), w.possess), action && /* @__PURE__ */ React.createElement("button", {
4306
- type: "button",
4307
- className: "twn-card-go",
4308
- onClick: action.run
4309
- }, action.label), /* @__PURE__ */ React.createElement("button", {
4310
- type: "button",
4311
- className: "twn-card-close",
4312
- title: w.close,
4313
- "aria-label": w.close,
4314
- onClick: onClose
4315
- }, X && /* @__PURE__ */ React.createElement(X, {
4316
- size: 14
4317
- }))), target && /* @__PURE__ */ React.createElement(TalkBar, {
4318
- key: target.to,
4319
- pi,
4320
- target,
4321
- talk,
4322
- words: w,
4323
- name: title,
4324
- face: resident,
4325
- members
4326
- }));
4327
- }
4328
- function phaseText(w, talk, name, last) {
4329
- switch (talk.phase) {
4330
- case "failed":
4331
- return talk.error;
4332
- case "sending":
4333
- return w.sending;
4334
- case "waiting":
4335
- return w.waitingReply;
4336
- case "answering":
4337
- return w.answeringNow;
4338
- default:
4339
- if (!last) {
4966
+ move(pointer) {
4967
+ const { camera } = this;
4968
+ if (this.pinch) {
4969
+ const touches = this.touches();
4970
+ if (touches.length >= 2) {
4971
+ const [a, b] = touches;
4972
+ const { pinch } = this;
4973
+ const zoom = Math.max(Math.min(this.whole(ZOOMS[0]), this.fitAll()), Math.min(this.whole(ZOOMS[ZOOMS.length - 1]), pinch.zoom * Math.hypot(a.x - b.x, a.y - b.y) / pinch.distance));
4974
+ const x = (a.x + b.x) / 2;
4975
+ const y = (a.y + b.y) / 2;
4976
+ this.zoomAt(zoom, pinch.x, pinch.y);
4977
+ camera.scrollX = camera.clampX(camera.scrollX - (x - pinch.x) / zoom);
4978
+ camera.scrollY = camera.clampY(camera.scrollY - (y - pinch.y) / zoom);
4979
+ pinch.x = x;
4980
+ pinch.y = y;
4981
+ }
4982
+ return;
4983
+ }
4984
+ const { press } = this;
4985
+ if (press && pointer.isDown) {
4986
+ this.glide.track(performance.now(), pointer.x, pointer.y);
4987
+ if (!press.moved) {
4988
+ if (Math.hypot(pointer.x - press.x, pointer.y - press.y) <= SLOP * this.ratio) {
4989
+ return;
4990
+ }
4991
+ press.moved = true;
4992
+ press.x = pointer.x;
4993
+ press.y = pointer.y;
4994
+ press.sx = camera.scrollX;
4995
+ press.sy = camera.scrollY;
4996
+ this.following = undefined;
4340
4997
  return;
4341
4998
  }
4342
- return talk.kind === "room" ? TownWords.format(w.posted, { channel: name.replace(/^#/, "") }) : talk.reply ? undefined : w.noReply;
4999
+ camera.scrollX = press.sx - (pointer.x - press.x) / camera.zoom;
5000
+ camera.scrollY = press.sy - (pointer.y - press.y) / camera.zoom;
5001
+ return;
5002
+ }
5003
+ if (!pointer.wasTouch) {
5004
+ this.scene.input.setDefaultCursor(this.host.hit(camera.getWorldPoint(pointer.x, pointer.y)) ? "pointer" : "default");
5005
+ }
4343
5006
  }
4344
- }
4345
- function TalkBar({
4346
- pi,
4347
- target,
4348
- talk,
4349
- words: w,
4350
- name,
4351
- face,
4352
- members
4353
- }) {
4354
- const thread = QuickTalkUtil.thread(talk.talks, target.to);
4355
- const last = thread[thread.length - 1];
4356
- const Composer = pi.ui.Composer;
4357
- const Markdown = pi.ui.Markdown;
4358
- const Volume = pi.ui.icons.Volume2;
4359
- const Square = pi.ui.icons.Square;
4360
- const voice = pi.ui.voice;
4361
- const list = React.useRef(null);
4362
- const height = `${thread.length}:${last?.phase}:${last?.reply?.length ?? 0}`;
4363
- React.useLayoutEffect(() => {
4364
- const element = list.current;
4365
- if (element) {
4366
- element.scrollTop = element.scrollHeight;
5007
+ up(pointer) {
5008
+ if (this.pinch) {
5009
+ const { pinch } = this;
5010
+ const left = this.touches();
5011
+ this.pinch = undefined;
5012
+ if (this.camera.zoom < this.whole(ZOOMS[0]) * 0.8 && left.length === 0) {
5013
+ this.index = 0;
5014
+ this.toggleOverview();
5015
+ if (this.before) {
5016
+ this.before = { ...this.before, zoom: this.whole(ZOOMS[0]), index: 0 };
5017
+ }
5018
+ return;
5019
+ }
5020
+ this.index = TownCamera.nearest(this.camera.zoom / this.ratio);
5021
+ this.settle(this.whole(ZOOMS[this.index]), pinch.x, pinch.y);
5022
+ if (left.length === 1) {
5023
+ this.startPress(left[0], true, true);
5024
+ }
5025
+ return;
4367
5026
  }
4368
- }, [height]);
4369
- const { listen } = talk;
4370
- React.useEffect(() => () => listen(undefined), [listen]);
4371
- const mentions = React.useMemo(() => members?.map((member) => ({ name: member.name })), [members]);
4372
- return /* @__PURE__ */ React.createElement("div", {
4373
- className: "twn-talk"
4374
- }, thread.length > 0 && /* @__PURE__ */ React.createElement("div", {
4375
- className: "twn-talk-thread",
4376
- ref: list,
4377
- "aria-live": "polite"
4378
- }, thread.map((each, index) => {
4379
- const state = phaseText(w, each, name, index === thread.length - 1);
4380
- return /* @__PURE__ */ React.createElement(React.Fragment, {
4381
- key: each.sentAt
4382
- }, /* @__PURE__ */ React.createElement("div", {
4383
- className: "twn-talk-said"
4384
- }, /* @__PURE__ */ React.createElement("span", null, each.said)), each.reply && /* @__PURE__ */ React.createElement("div", {
4385
- className: "twn-talk-reply"
4386
- }, face && /* @__PURE__ */ React.createElement(Sprite, {
4387
- resident: face,
4388
- scale: 1.5
4389
- }), /* @__PURE__ */ React.createElement("div", {
4390
- className: "twn-talk-reply-text"
4391
- }, Markdown ? /* @__PURE__ */ React.createElement(Markdown, {
4392
- text: each.reply
4393
- }) : each.reply), voice?.canSpeak() && /* @__PURE__ */ React.createElement("button", {
4394
- type: "button",
4395
- className: "twn-talk-icon",
4396
- title: w.replay,
4397
- "aria-label": w.replay,
4398
- onClick: () => talk.speak(each.reply)
4399
- }, Volume && /* @__PURE__ */ React.createElement(Volume, {
4400
- size: 14
4401
- }))), state && /* @__PURE__ */ React.createElement("div", {
4402
- className: `twn-talk-state${each.phase === "failed" ? " twn-talk-failed" : each.phase === "done" ? " twn-talk-quiet" : ""}`
4403
- }, face && each.phase !== "failed" && each.phase !== "done" && /* @__PURE__ */ React.createElement(Sprite, {
4404
- resident: face,
4405
- scale: 1.5
4406
- }), /* @__PURE__ */ React.createElement("span", null, state)));
4407
- })), /* @__PURE__ */ React.createElement("div", {
4408
- className: "twn-talk-box"
4409
- }, /* @__PURE__ */ React.createElement(Composer, {
4410
- placeholder: target.placeholder,
4411
- onSend: (text) => talk.send(target, text, false),
4412
- voiceSends: true,
4413
- onTalkSent: talk.spoken,
4414
- onListening: (on) => listen(on ? target.to : undefined),
4415
- working: target.kind === "agent" && QuickTalkUtil.working(last),
4416
- onStop: talk.stop,
4417
- mentions,
4418
- mentionLabel: mentions ? w.mention : undefined,
4419
- after: talk.speaking ? /* @__PURE__ */ React.createElement("button", {
4420
- type: "button",
4421
- className: "twn-talk-hush",
4422
- title: w.hush,
4423
- "aria-label": w.hush,
4424
- onClick: talk.hush
4425
- }, /* @__PURE__ */ React.createElement("span", {
4426
- className: "twn-wave",
4427
- "aria-hidden": "true"
4428
- }, /* @__PURE__ */ React.createElement("i", null), /* @__PURE__ */ React.createElement("i", null), /* @__PURE__ */ React.createElement("i", null)), Square && /* @__PURE__ */ React.createElement(Square, {
4429
- size: 10
4430
- })) : undefined
4431
- })));
5027
+ const { press } = this;
5028
+ this.press = undefined;
5029
+ if (!press) {
5030
+ return;
5031
+ }
5032
+ if (press.moved) {
5033
+ this.glide.release(performance.now());
5034
+ return;
5035
+ }
5036
+ this.glide.reset();
5037
+ if (!press.caught) {
5038
+ this.host.tap(this.camera.getWorldPoint(pointer.x, pointer.y));
5039
+ }
5040
+ }
5041
+ static nearest(zoom) {
5042
+ let best = 0;
5043
+ ZOOMS.forEach((each, index) => {
5044
+ if (Math.abs(each - zoom) < Math.abs(ZOOMS[best] - zoom)) {
5045
+ best = index;
5046
+ }
5047
+ });
5048
+ return best;
5049
+ }
4432
5050
  }
4433
5051
 
4434
5052
  // web-src/resident-view.ts
@@ -4818,9 +5436,10 @@ class TownDecor {
4818
5436
  var TILE_MARGIN = 1;
4819
5437
  var TILE_SPACING = 2;
4820
5438
  var COLUMNS = 16;
4821
- var FACES = {
5439
+ var FACES2 = {
4822
5440
  office: "#eaf3ee",
4823
5441
  meeting: "#e8eef8",
5442
+ room: "#e4eef9",
4824
5443
  home: "#f4ece0",
4825
5444
  bench: "#dedad4",
4826
5445
  workshop: "#dedad4"
@@ -5013,7 +5632,7 @@ var TownTiles;
5013
5632
  break;
5014
5633
  }
5015
5634
  case Tile.WALL_FACE: {
5016
- const face = FACES[a] ?? FACES.home;
5635
+ const face = FACES2[a] ?? FACES2.home;
5017
5636
  rect3(g, face, x, y, TILE, TILE);
5018
5637
  rect3(g, shade(face, 0.06), x, y, TILE, 3);
5019
5638
  rect3(g, shade(face, 0.22), x, y + 13, TILE, 3);
@@ -8208,6 +8827,7 @@ var BED = { 1: 10327144, 2: 14271630 };
8208
8827
  var BUILDING = {
8209
8828
  office: { wall: 15525592, roof: 2923128 },
8210
8829
  meeting: { wall: 14929838, roof: 11817788 },
8830
+ room: { wall: 14674162, roof: 4161476 },
8211
8831
  home: { wall: 15852488, roof: 8084378 },
8212
8832
  bench: { wall: 13488598, roof: 5792109 },
8213
8833
  workshop: { wall: 13488598, roof: 5792109 }
@@ -14154,6 +14774,7 @@ var ORDER = {
14154
14774
  listening: 0,
14155
14775
  answering: 0,
14156
14776
  meeting: 1,
14777
+ room: 1,
14157
14778
  working: 2,
14158
14779
  waiting: 3,
14159
14780
  news: 4,
@@ -14167,6 +14788,7 @@ var ORDER = {
14167
14788
  };
14168
14789
  var JOINED_MS = 15 * 60 * 1000;
14169
14790
  var opened = new Set;
14791
+ var NO_ITEMS = [];
14170
14792
  var PANEL_ROOM = 900;
14171
14793
  function pixelRatio() {
14172
14794
  return Math.max(1, Math.min(3, Math.round(globalThis.devicePixelRatio || 1)));
@@ -14269,6 +14891,10 @@ function TownPage({ pi }) {
14269
14891
  const now = useNow();
14270
14892
  const talk = useQuickTalk(pi, data, sessions, double);
14271
14893
  const [help, setHelp] = React.useState(false);
14894
+ const rooms = useTownRooms(pi);
14895
+ const homeItems = pi.ui.useHomeItems?.() ?? NO_ITEMS;
14896
+ const time = now.getTime();
14897
+ const shared = React.useMemo(() => TownRoomsUtil.of(rooms.state, { agents: data.team.agents, unseen: TownRoomsUtil.unseen(homeItems), now: time }), [rooms.state, data.team.agents, homeItems, time]);
14272
14898
  const answering = React.useMemo(() => {
14273
14899
  const busy = new Set;
14274
14900
  for (const session of sessions) {
@@ -14280,17 +14906,24 @@ function TownPage({ pi }) {
14280
14906
  return busy;
14281
14907
  }, [sessions, data.team.agents]);
14282
14908
  const lines = React.useMemo(() => TownModel.lastLines(data.team.agents, data.messages, [...data.saved, ...sessions.filter((session) => !session.isStreaming)]), [data.team.agents, data.messages, data.saved, sessions]);
14909
+ const doubleAt = double?.preview?.at;
14910
+ const doubleBusy = !!double?.busy;
14911
+ const marks = React.useMemo(() => {
14912
+ const busy = new Set([...answering, ...Object.values(data.working).flat()]);
14913
+ return TownLook.marks(data.team.agents, [...data.saved, ...sessions], data, busy, { at: doubleAt, busy: doubleBusy });
14914
+ }, [data, sessions, answering, doubleAt, doubleBusy]);
14283
14915
  const model = TownModel.of({
14284
14916
  team: data.team,
14285
14917
  working: data.working,
14286
14918
  answering,
14287
- marks: data.marks,
14919
+ marks,
14288
14920
  lines,
14289
14921
  tasks,
14290
14922
  needsLook: (task) => needsLook(task, data.seen),
14291
14923
  double: { name: double?.title || "Ta", busy: !!double?.busy, line: double?.preview },
14292
14924
  now,
14293
- talking: QuickTalkUtil.talking(talk.talk, talk.listening)
14925
+ talking: QuickTalkUtil.talking(talk.talk, talk.listening),
14926
+ rooms: shared
14294
14927
  });
14295
14928
  const key = TownModel.key(model);
14296
14929
  const latest = React.useRef({ key, model });
@@ -14308,7 +14941,16 @@ function TownPage({ pi }) {
14308
14941
  const words = React.useRef(w);
14309
14942
  words.current = w;
14310
14943
  const fail = (error) => pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
14944
+ const roomAt = (id) => {
14945
+ const place = model.places.find((each) => each.id === id) ?? model.places.find((each) => each.id === model.residents.find((one) => one.id === id)?.place);
14946
+ return place?.kind === "room" ? rooms.state.rooms.find((room) => room.id === place.owner) : undefined;
14947
+ };
14311
14948
  const open = (id) => {
14949
+ const room = id.startsWith("visitor:") || id.startsWith("shared:") ? roomAt(id) : undefined;
14950
+ if (room) {
14951
+ TownRoomsUtil.open(pi, room.id, homeItems);
14952
+ return;
14953
+ }
14312
14954
  if (id === DOUBLE_ID) {
14313
14955
  pi.ui.showView(DOUBLE_PAGE);
14314
14956
  return;
@@ -14490,6 +15132,7 @@ function TownPage({ pi }) {
14490
15132
  }, [exists]);
14491
15133
  const clock = clockOf(now, language);
14492
15134
  const selectedResident = selected && model.residents.some((each) => each.id === selected) ? selected : undefined;
15135
+ const selectedRoom = roomAt(selected);
14493
15136
  const Game = pi.ui.Game;
14494
15137
  const Users = pi.ui.icons.Users;
14495
15138
  const Plus = pi.ui.icons.Plus;
@@ -14587,7 +15230,20 @@ function TownPage({ pi }) {
14587
15230
  words: w,
14588
15231
  touch: device.touch,
14589
15232
  onClose: () => setHelp(false)
14590
- }), selected && exists && !world && /* @__PURE__ */ React.createElement(TownCard, {
15233
+ }), selected && exists && !world && selectedRoom && /* @__PURE__ */ React.createElement(RoomCard, {
15234
+ key: selected,
15235
+ pi,
15236
+ room: selectedRoom,
15237
+ chat: rooms.watch.chat(selectedRoom.id),
15238
+ lines: rooms.state.lines[selectedRoom.id] ?? [],
15239
+ model,
15240
+ words: w,
15241
+ visitor: model.residents.find((each) => each.id === selected && each.kind === "visitor"),
15242
+ onPick: pick,
15243
+ onOpen: () => open(selected),
15244
+ onPlay: Game3D && playable(selectedRoom) ? () => void play(selectedRoom) : undefined,
15245
+ onClose: () => setSelected(undefined)
15246
+ }), selected && exists && !world && !selectedRoom && /* @__PURE__ */ React.createElement(TownCard, {
14591
15247
  pi,
14592
15248
  data,
14593
15249
  model,