@adatechnology/game-test-room 0.4.0 → 0.6.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/dist/index.js CHANGED
@@ -1648,7 +1648,7 @@ var toHostEvent = (weapon, event, options = {}) => {
1648
1648
  return event.phase === "start" ? { type: "tool", weapon, ...durationOf(phase, "draw") } : null;
1649
1649
  // a launcher spends a round and throws one projectile: the weapon counts none because it is a throw, a host counts the one that leaves
1650
1650
  case "shot":
1651
- return { type: "shot", weapon, shots: Math.max(1, event.shots), recoil, rounds: event.rounds, mode: event.mode };
1651
+ return { type: "shot", weapon, shots: Math.max(1, event.shots), recoil, rounds: event.rounds, mode: event.mode, ...event.suppressed ? { suppressed: true } : {} };
1652
1652
  case "misfire":
1653
1653
  return { type: "misfire", weapon };
1654
1654
  case "reload":
@@ -1671,6 +1671,14 @@ var toHostEvent = (weapon, event, options = {}) => {
1671
1671
  return { type: "safety", weapon, on: event.on };
1672
1672
  case "cook":
1673
1673
  return { type: "cook", weapon, phase: event.phase, fuse: event.fuse };
1674
+ case "attachment":
1675
+ return { type: "attachment", weapon, action: event.action, attachment: event.id, mount: event.mount, ...event.action === "break" ? {} : durationOf(phase, "fit") };
1676
+ case "toggle":
1677
+ return { type: "toggle", weapon, attachment: event.id, on: event.on };
1678
+ case "stock":
1679
+ return { type: "stock", weapon, state: event.state, kind: event.kind, ...durationOf(phase, "stock") };
1680
+ case "underbarrel":
1681
+ return { type: "underbarrel", weapon, on: event.on, ...durationOf(phase, "switch") };
1674
1682
  default:
1675
1683
  return null;
1676
1684
  }
@@ -3150,6 +3158,10 @@ var CSS = `
3150
3158
  .tr-search{width:100%;margin:0 0 6px;padding:5px 8px;border-radius:5px;border:1px solid #3a404c;background:#0f1116;color:#e8eaee;font:inherit}
3151
3159
  .tr-search::placeholder{color:#7d8594}
3152
3160
  .tr-item small{color:#7d8594;margin-left:4px}
3161
+ .tr-thumb{display:block;width:100%;height:26px;background:currentColor;-webkit-mask:var(--tr-thumb) center/contain no-repeat;mask:var(--tr-thumb) center/contain no-repeat}
3162
+ .tr-item{min-width:0}
3163
+ .tr-item .tr-btn.has-thumb{display:flex;flex-direction:column;gap:3px;min-width:0}.tr-item .tr-btn.has-thumb .tr-name{overflow:hidden;text-overflow:ellipsis}
3164
+ .tr-insp .tr-thumb{width:140px;height:28px;margin-bottom:3px}
3153
3165
  .tr-empty{color:#9aa3b2;padding:4px 2px;grid-column:1/-1}
3154
3166
  .tr-cross{position:absolute;left:50%;top:50%;width:18px;height:18px;margin:-9px 0 0 -9px}
3155
3167
  .tr-cross:before,.tr-cross:after{content:"";position:absolute;background:#fff;opacity:.85;box-shadow:0 0 2px #000}
@@ -3215,6 +3227,17 @@ var mk2 = (tag, cls, text) => {
3215
3227
  if (text !== void 0) e.textContent = text;
3216
3228
  return e;
3217
3229
  };
3230
+ var thumbSource = (thumbnail) => {
3231
+ const source = thumbnail.trim().startsWith("<") ? `data:image/svg+xml,${encodeURIComponent(thumbnail.trim())}` : thumbnail.trim();
3232
+ return source.replace(/["\\\n\r]/g, (char) => encodeURIComponent(char));
3233
+ };
3234
+ var thumb = (thumbnail, credit) => {
3235
+ const e = mk2("span", "tr-thumb");
3236
+ if (credit) e.title = credit;
3237
+ else e.setAttribute("aria-hidden", "true");
3238
+ e.style.setProperty("--tr-thumb", `url("${thumbSource(thumbnail)}")`);
3239
+ return e;
3240
+ };
3218
3241
  function createUi(o) {
3219
3242
  const { t } = o;
3220
3243
  const style = mk2("style");
@@ -3368,7 +3391,8 @@ function createUi(o) {
3368
3391
  if (!found.length) items.appendChild(mk2("div", "tr-empty", t("ui.no_results")));
3369
3392
  for (const { item: it, group } of found) {
3370
3393
  const wrap = mk2("div", "tr-item");
3371
- const b = mk2("button", "tr-btn", it.name);
3394
+ const b = mk2("button", it.thumbnail ? "tr-btn has-thumb" : "tr-btn", it.thumbnail ? void 0 : it.name);
3395
+ if (it.thumbnail) b.append(thumb(it.thumbnail), mk2("span", "tr-name", it.name));
3372
3396
  if (searching) b.appendChild(mk2("small", void 0, group));
3373
3397
  b.type = "button";
3374
3398
  b.title = it.note ?? it.name;
@@ -3527,6 +3551,7 @@ function createUi(o) {
3527
3551
  insp.appendChild(mk2("div", void 0, t("ui.aim_at_something")));
3528
3552
  return;
3529
3553
  }
3554
+ if (i.thumbnail) insp.appendChild(thumb(i.thumbnail, i.thumbnailCredit));
3530
3555
  insp.appendChild(mk2("div", "t", `${i.object} \u203A ${i.part}`));
3531
3556
  insp.appendChild(row(t("ins.material"), i.material));
3532
3557
  insp.appendChild(row(t("ins.status"), i.status + (i.burning ? ` \xB7 ${t("ins.burning")}` : "")));
@@ -4898,6 +4923,8 @@ function createTestRoom(options) {
4898
4923
  stress: ext.stress,
4899
4924
  joints,
4900
4925
  note: e?.item?.note,
4926
+ thumbnail: e?.item?.thumbnail,
4927
+ thumbnailCredit: e?.item?.thumbnailCredit,
4901
4928
  distance: r.distance
4902
4929
  };
4903
4930
  };
@@ -5188,6 +5215,26 @@ function createTestRoom(options) {
5188
5215
  flushEvents(toolId, tool);
5189
5216
  say(t(tool.safety ? "hud.safety_on" : "hud.safety_off"));
5190
5217
  }
5218
+ function runToolCommand(request) {
5219
+ const work = (done) => done.ok ? { ok: true, seconds: done.seconds } : { ok: false, reason: done.reason };
5220
+ switch (request.type) {
5221
+ case "fit":
5222
+ return work(tool.fit(request.attachment, { install: "bench", ...request.mount ? { mount: request.mount } : {} }));
5223
+ case "remove":
5224
+ return work(tool.remove(request.attachment, { install: "bench" }));
5225
+ case "toggle":
5226
+ return tool.toggle(request.attachment) === null ? { ok: false, reason: "not_fitted" } : { ok: true };
5227
+ case "stock":
5228
+ return tool.setStock(request.state) ? { ok: true } : { ok: false, reason: "busy" };
5229
+ case "underbarrel":
5230
+ return tool.useUnderbarrel(request.on) ? { ok: true } : { ok: false, reason: "busy" };
5231
+ case "stance":
5232
+ tool.setStance({ ...request.aiming === void 0 ? {} : { aiming: request.aiming }, ...request.supported === void 0 ? {} : { supported: request.supported } });
5233
+ return { ok: true };
5234
+ default:
5235
+ return { ok: false, reason: "unknown" };
5236
+ }
5237
+ }
5191
5238
  const host = {
5192
5239
  THREE,
5193
5240
  scene,
@@ -5204,8 +5251,19 @@ function createTestRoom(options) {
5204
5251
  mode: tool.mode,
5205
5252
  ...tool.fault ? { fault: tool.fault } : {},
5206
5253
  safety: tool.safety,
5207
- heat: tool.heatLevel
5254
+ heat: tool.heatLevel,
5255
+ attachments: tool.attachments.map((part) => ({ id: part.id, mount: part.mount, ...part.integral ? { integral: true } : {}, ...part.on === void 0 ? {} : { on: part.on } })),
5256
+ stock: tool.stock,
5257
+ suppressed: tool.suppressed,
5258
+ underbarrelActive: tool.underbarrelActive,
5259
+ mass: tool.mass,
5260
+ aimSeconds: tool.aimSeconds
5208
5261
  }),
5262
+ command(request) {
5263
+ const result = runToolCommand(request);
5264
+ flushEvents(toolId, tool);
5265
+ return result;
5266
+ },
5209
5267
  configureTool(settings) {
5210
5268
  const condition = settings[SETTING_IDS.condition];
5211
5269
  const ammoQuality = settings[SETTING_IDS.ammoQuality];
@@ -5266,7 +5324,9 @@ function createTestRoom(options) {
5266
5324
  fluid: ti.fluid,
5267
5325
  weapon: ti.weapon,
5268
5326
  impl: ti.impl,
5269
- animations: ti.animations
5327
+ animations: ti.animations,
5328
+ thumbnail: ti.thumbnail,
5329
+ thumbnailCredit: ti.thumbnailCredit
5270
5330
  };
5271
5331
  catalogMap.set(item.id, item);
5272
5332
  const at = catalog.findIndex((c) => c.id === item.id);