@adatechnology/game-player 0.12.3 → 0.13.1

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/hud.js CHANGED
@@ -16,7 +16,7 @@ var PLAYER_HUD_CSS = `
16
16
  .gp-hud-row output{text-align:right;font-variant-numeric:tabular-nums}
17
17
  .gp-hud-bar{height:7px;background:#2a2e36;border-radius:4px;overflow:hidden}
18
18
  .gp-hud-bar i{display:block;height:100%;width:0;background:#4fc3f7}
19
- .gp-hud-bar.hp i{background:#66bb6a}.gp-hud-bar.warn i{background:#ffb300}.gp-hud-bar.bad i{background:#ef5350}
19
+ .gp-hud-bar.hp i{background:#66bb6a}.gp-hud-bar.need i{background:#c8a165}.gp-hud-bar.warn i{background:#ffb300}.gp-hud-bar.bad i{background:#ef5350}
20
20
  .gp-hud-status{display:flex;flex-wrap:wrap;gap:4px}
21
21
  .gp-hud-status:empty{display:none}
22
22
  .gp-hud-tag{border-radius:4px;padding:0 6px;background:#2a2e36}
@@ -59,6 +59,8 @@ function positionContainer(container) {
59
59
  var PT_BR = {
60
60
  health: "Vida",
61
61
  stamina: "F\xF4lego",
62
+ hunger: "Fome",
63
+ thirst: "Sede",
62
64
  bleeding: "Sangrando",
63
65
  wounds: "Ferimentos",
64
66
  infected: "Infectado",
@@ -76,6 +78,8 @@ var PT_BR = {
76
78
  var EN = {
77
79
  health: "Health",
78
80
  stamina: "Stamina",
81
+ hunger: "Hunger",
82
+ thirst: "Thirst",
79
83
  bleeding: "Bleeding",
80
84
  wounds: "Wounds",
81
85
  infected: "Infected",
@@ -120,9 +124,9 @@ var element = (tag, className, text) => {
120
124
  if (text !== void 0) node.textContent = text;
121
125
  return node;
122
126
  };
123
- function createGauge(label, tone) {
127
+ function createGauge(label, tone, starving = 0.9) {
124
128
  const row = element("div", "gp-hud-row");
125
- const bar = element("div", tone === "hp" ? "gp-hud-bar hp" : "gp-hud-bar");
129
+ const bar = element("div", tone === "hp" ? "gp-hud-bar hp" : tone === "need" ? "gp-hud-bar need" : "gp-hud-bar");
126
130
  const fill = element("i");
127
131
  const value = element("output");
128
132
  bar.appendChild(fill);
@@ -141,6 +145,7 @@ function createGauge(label, tone) {
141
145
  fill.style.width = `${percent}%`;
142
146
  value.textContent = String(shownValue);
143
147
  if (tone === "hp") bar.className = share <= LOW_SHARE ? "gp-hud-bar bad" : share <= WARN_SHARE ? "gp-hud-bar warn" : "gp-hud-bar hp";
148
+ else if (tone === "need") bar.className = share > starving ? "gp-hud-bar bad" : share > WARN_SHARE ? "gp-hud-bar warn" : "gp-hud-bar need";
144
149
  }
145
150
  };
146
151
  }
@@ -156,37 +161,22 @@ function statusTags(view, text) {
156
161
  }
157
162
  return tags;
158
163
  }
159
- function createPlayerHud({ container, locale = "pt-BR", title }) {
164
+ function createVitalsPanel(locale = "pt-BR") {
160
165
  const text = playerHudTextOf(locale);
161
166
  ensurePlayerHudStyle();
162
- const restorePosition = positionContainer(container);
163
- const root = element("div", "gp-hud");
164
- root.dataset.hud = "player";
165
- const titleBox = element("div", "gp-hud-pill gp-hud-title");
166
- const messageBox = element("div", "gp-hud-message");
167
167
  const vitals = element("div", "gp-hud-vitals");
168
168
  const health = createGauge(text.health, "hp");
169
169
  const stamina = createGauge(text.stamina, "stamina");
170
170
  const status = element("div", "gp-hud-status");
171
171
  vitals.append(health.row, stamina.row, status);
172
- const weaponBox = element("div", "gp-hud-pill gp-hud-weapon");
173
- const cross = element("div", "gp-hud-cross");
174
- cross.appendChild(element("i"));
175
- root.append(titleBox, messageBox, vitals, weaponBox, cross);
176
- container.appendChild(root);
172
+ let needs = null;
177
173
  let lastBleeding = null;
178
174
  let lastInfection = "";
179
175
  let lastWounds = null;
180
176
  let lastWoundCount = -1;
181
177
  let lastAlive = null;
182
- let lastView = null;
183
- let messageTimer = null;
184
- const setTitle = (next) => {
185
- titleBox.textContent = next ?? "";
186
- titleBox.style.display = next ? "block" : "none";
187
- };
188
- setTitle(title ?? null);
189
178
  return {
179
+ element: vitals,
190
180
  update(view) {
191
181
  if (view.alive !== lastAlive) {
192
182
  lastAlive = view.alive;
@@ -194,6 +184,22 @@ function createPlayerHud({ container, locale = "pt-BR", title }) {
194
184
  }
195
185
  health.set(view.health, view.maxHealth);
196
186
  stamina.set(view.stamina, view.maxStamina);
187
+ stamina.row.style.display = view.maxStamina > 0 ? "" : "none";
188
+ if (view.hunger !== void 0 && view.thirst !== void 0) {
189
+ const max = view.needMax ?? 100;
190
+ if (!needs) {
191
+ const starving = max > 0 ? (view.needStarving ?? max * 0.9) / max : 0.9;
192
+ needs = { hunger: createGauge(text.hunger, "need", starving), thirst: createGauge(text.thirst, "need", starving) };
193
+ vitals.insertBefore(needs.hunger.row, status);
194
+ vitals.insertBefore(needs.thirst.row, status);
195
+ }
196
+ needs.hunger.set(view.hunger, max);
197
+ needs.thirst.set(view.thirst, max);
198
+ } else if (needs) {
199
+ needs.hunger.row.remove();
200
+ needs.thirst.row.remove();
201
+ needs = null;
202
+ }
197
203
  if (view.bleeding === lastBleeding && view.infection === lastInfection && view.wounds === lastWounds && view.wounds.length === lastWoundCount) return;
198
204
  lastBleeding = view.bleeding;
199
205
  lastInfection = view.infection;
@@ -201,7 +207,31 @@ function createPlayerHud({ container, locale = "pt-BR", title }) {
201
207
  lastWoundCount = view.wounds.length;
202
208
  const tags = statusTags(view, text);
203
209
  status.replaceChildren(...tags.map((tag) => element("span", tag.tone ? `gp-hud-tag ${tag.tone}` : "gp-hud-tag", tag.label)));
204
- },
210
+ }
211
+ };
212
+ }
213
+ function createPlayerHud({ container, locale = "pt-BR", title }) {
214
+ ensurePlayerHudStyle();
215
+ const restorePosition = positionContainer(container);
216
+ const root = element("div", "gp-hud");
217
+ root.dataset.hud = "player";
218
+ const titleBox = element("div", "gp-hud-pill gp-hud-title");
219
+ const messageBox = element("div", "gp-hud-message");
220
+ const vitals = createVitalsPanel(locale);
221
+ const weaponBox = element("div", "gp-hud-pill gp-hud-weapon");
222
+ const cross = element("div", "gp-hud-cross");
223
+ cross.appendChild(element("i"));
224
+ root.append(titleBox, messageBox, vitals.element, weaponBox, cross);
225
+ container.appendChild(root);
226
+ let lastView = null;
227
+ let messageTimer = null;
228
+ const setTitle = (next) => {
229
+ titleBox.textContent = next ?? "";
230
+ titleBox.style.display = next ? "block" : "none";
231
+ };
232
+ setTitle(title ?? null);
233
+ return {
234
+ update: (view) => vitals.update(view),
205
235
  setTitle,
206
236
  setWeapon(weapon) {
207
237
  weaponBox.replaceChildren();
@@ -351,6 +381,11 @@ function writePlayerHudView(player, view) {
351
381
  view.bleeding = state.bleeding > 0;
352
382
  view.wounds = state.wounds;
353
383
  view.infection = state.infected ? player.stage() : "none";
384
+ const needs = player.needs;
385
+ view.hunger = needs ? state.hunger : void 0;
386
+ view.thirst = needs ? state.thirst : void 0;
387
+ view.needMax = needs?.max;
388
+ view.needStarving = needs?.starvingAt;
354
389
  return view;
355
390
  }
356
391
  export {
@@ -360,6 +395,7 @@ export {
360
395
  createDeathScreen,
361
396
  createPlayerHud,
362
397
  createPlayerHudView,
398
+ createVitalsPanel,
363
399
  formatSurvived,
364
400
  playerHudTextOf,
365
401
  playerHudViewOf,
package/dist/hud.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hud/hud-style.ts","../src/hud/hud-text.ts","../src/hud/player-hud.ts","../src/hud/death-screen.ts","../src/hud/hud-view.ts"],"sourcesContent":["// The death panel sits in the lower third: the death camera keeps the body at the centre of the view.\n// The same tokens as the test room's HUD (panel rgba(10,12,16,.72), accent #ffd23f, bars #2a2e36 / #66bb6a / #ffb300 / #ef5350 / #4fc3f7), so a game and its room read alike.\nexport const PLAYER_HUD_CSS = `\n.gp-hud{position:absolute;inset:0;pointer-events:none;font:12px/1.35 system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif;color:#e8eaee;overflow:hidden;z-index:10}\n.gp-hud *{box-sizing:border-box}\n.gp-hud-pill{background:rgba(10,12,16,.72);padding:4px 12px;border-radius:6px;font-size:14px;font-weight:600}\n.gp-hud-pill small{font-weight:400;opacity:.8;margin-left:8px}\n.gp-hud-title{position:absolute;top:8px;left:8px;display:none}\n.gp-hud-message{position:absolute;top:8px;left:50%;transform:translateX(-50%);max-width:60vw;text-align:center;color:#ffd23f;text-shadow:0 1px 2px #000;font-size:14px;font-weight:600;display:none}\n.gp-hud-vitals{position:absolute;left:8px;bottom:8px;width:210px;background:rgba(10,12,16,.72);border-radius:6px;padding:6px 8px;display:flex;flex-direction:column;gap:4px}\n.gp-hud-row{display:grid;grid-template-columns:62px 1fr 30px;align-items:center;gap:6px}\n.gp-hud-row span:first-child{color:#9aa3b2}\n.gp-hud-row output{text-align:right;font-variant-numeric:tabular-nums}\n.gp-hud-bar{height:7px;background:#2a2e36;border-radius:4px;overflow:hidden}\n.gp-hud-bar i{display:block;height:100%;width:0;background:#4fc3f7}\n.gp-hud-bar.hp i{background:#66bb6a}.gp-hud-bar.warn i{background:#ffb300}.gp-hud-bar.bad i{background:#ef5350}\n.gp-hud-status{display:flex;flex-wrap:wrap;gap:4px}\n.gp-hud-status:empty{display:none}\n.gp-hud-tag{border-radius:4px;padding:0 6px;background:#2a2e36}\n.gp-hud-tag.bad{background:rgba(183,28,28,.9);color:#fff}.gp-hud-tag.warn{background:rgba(120,90,10,.9);color:#fff}\n.gp-hud-weapon{position:absolute;right:8px;bottom:8px;display:none}\n.gp-hud-cross{position:absolute;left:50%;top:50%;width:18px;height:18px;margin:-9px 0 0 -9px;display:none}\n.gp-hud-cross:before,.gp-hud-cross:after{content:\"\";position:absolute;background:#fff;opacity:.85;box-shadow:0 0 2px #000}\n.gp-hud-cross:before{left:8px;top:0;width:2px;height:18px}.gp-hud-cross:after{top:8px;left:0;height:2px;width:18px}\n.gp-hud-cross i{position:absolute;left:6px;top:6px;width:6px;height:6px;background:#0b0c0e;border-radius:50%;z-index:1}\n.gp-death{position:absolute;inset:0;display:none;align-items:flex-end;justify-content:center;padding-bottom:12vh;background:linear-gradient(transparent 45%,rgba(0,0,0,.55));font:13px/1.4 system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif;color:#e8eaee;z-index:20}\n.gp-death.open{display:flex}\n.gp-death-panel{min-width:min(320px,90vw);max-width:90vw;background:rgba(12,14,19,.92);border:1px solid #2c313b;border-radius:8px;padding:18px 22px;text-align:center;box-shadow:0 4px 18px rgba(0,0,0,.5)}\n.gp-death-panel h2{margin:0 0 6px;font-size:22px;color:#ef5350}\n.gp-death-panel p{margin:2px 0;color:#9aa3b2}\n.gp-death-actions{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin-top:14px}\n.gp-death-actions button{background:#232831;border:1px solid #3a404c;color:#e8eaee;border-radius:5px;padding:6px 14px;cursor:pointer;font:inherit}\n.gp-death-actions button:hover,.gp-death-actions button:focus-visible{background:#2d3440;border-color:#ffd23f}\n.gp-death-actions button:disabled{opacity:.5;cursor:default}\n.gp-death-actions kbd{background:#2a2e36;border:1px solid #4a505c;border-radius:3px;padding:0 4px;font:inherit;font-weight:700;margin-left:6px}\n`\n\nconst STYLE_ID = 'gp-hud-style'\n\n/** Puts the HUD's style in the document once (the HUD and the death screen share it). */\nexport function ensurePlayerHudStyle(): void {\n if (document.getElementById(STYLE_ID)) return\n const style = document.createElement('style')\n style.id = STYLE_ID\n style.textContent = PLAYER_HUD_CSS\n document.head.appendChild(style)\n}\n\n/** Makes `container` the positioning box of an overlay laid over it; the answer puts back what it changed. */\nexport function positionContainer(container: HTMLElement): () => void {\n const position = getComputedStyle(container).position\n if (position && position !== 'static') return () => undefined\n const before = container.style.position\n container.style.position = 'relative'\n return () => {\n if (container.style.position === 'relative') container.style.position = before\n }\n}\n","/** The words of the player's HUD and of the death screen, in a locale. */\nexport type PlayerHudText = {\n readonly health: string\n readonly stamina: string\n readonly bleeding: string\n readonly wounds: string\n readonly infected: string\n readonly stageMalaise: string\n readonly stageFever: string\n readonly stageDelirium: string\n readonly woundScratch: string\n readonly woundLaceration: string\n readonly woundBite: string\n readonly died: string\n readonly survived: string\n readonly restart: string\n readonly backToStart: string\n}\n\nconst PT_BR: PlayerHudText = {\n health: 'Vida',\n stamina: 'Fôlego',\n bleeding: 'Sangrando',\n wounds: 'Ferimentos',\n infected: 'Infectado',\n stageMalaise: 'mal-estar',\n stageFever: 'febre',\n stageDelirium: 'delírio',\n woundScratch: 'arranhão',\n woundLaceration: 'corte',\n woundBite: 'mordida',\n died: 'Você morreu',\n survived: 'Sobreviveu {time}',\n restart: 'Reiniciar cena',\n backToStart: 'Voltar ao início',\n}\n\nconst EN: PlayerHudText = {\n health: 'Health',\n stamina: 'Stamina',\n bleeding: 'Bleeding',\n wounds: 'Wounds',\n infected: 'Infected',\n stageMalaise: 'malaise',\n stageFever: 'fever',\n stageDelirium: 'delirium',\n woundScratch: 'scratch',\n woundLaceration: 'laceration',\n woundBite: 'bite',\n died: 'You died',\n survived: 'Survived {time}',\n restart: 'Restart scene',\n backToStart: 'Back to the start',\n}\n\nexport const PLAYER_HUD_TEXT: Readonly<Record<'en' | 'pt-BR', PlayerHudText>> = { en: EN, 'pt-BR': PT_BR }\n\n/** The HUD's words for a locale (`pt-BR` or `en`, the language part is enough; anything else is `pt-BR`). */\nexport const playerHudTextOf = (locale = 'pt-BR'): PlayerHudText => (locale.toLowerCase().startsWith('en') ? EN : PT_BR)\n\nconst WOUND_KEY: Readonly<Record<string, keyof PlayerHudText>> = { scratch: 'woundScratch', laceration: 'woundLaceration', bite: 'woundBite' }\nconst STAGE_KEY: Readonly<Record<string, keyof PlayerHudText>> = { malaise: 'stageMalaise', fever: 'stageFever', delirium: 'stageDelirium' }\n\n/** A wound kind in words; a kind the table does not know (a game's own) comes back as it is. */\nexport const woundTextOf = (text: PlayerHudText, kind: string): string => {\n const key = WOUND_KEY[kind]\n return key ? text[key] : kind\n}\n\n/** An infection stage in words (`none` gives an empty text). */\nexport const stageTextOf = (text: PlayerHudText, stage: string): string => {\n const key = STAGE_KEY[stage]\n return key ? text[key] : ''\n}\n\n/** Seconds as `m:ss` (or `h:mm:ss` past the hour). */\nexport const formatSurvived = (seconds: number): string => {\n const whole = Math.max(0, Math.floor(seconds))\n const hours = Math.floor(whole / 3600)\n const minutes = Math.floor((whole % 3600) / 60)\n const rest = String(whole % 60).padStart(2, '0')\n return hours > 0 ? `${hours}:${String(minutes).padStart(2, '0')}:${rest}` : `${minutes}:${rest}`\n}\n","import { ensurePlayerHudStyle, positionContainer } from './hud-style'\nimport { playerHudTextOf, stageTextOf, woundTextOf } from './hud-text'\nimport type { PlayerHudText } from './hud-text'\nimport type { PlayerHudView } from './hud-view'\n\n/** The weapon in the hand: its name and, for a gun, the rounds as the game writes them (`12 / 48`). */\nexport type PlayerHudWeapon = { readonly name: string; readonly ammo?: string }\n\nexport type PlayerHudOptions = {\n /** The box the HUD is laid over (the game's canvas box). */\n readonly container: HTMLElement\n /** `pt-BR` (default) or `en`. */\n readonly locale?: string\n /** A name shown at the top left (the level, the scenario); absent, nothing there. */\n readonly title?: string\n}\n\nexport type PlayerHud = {\n /** The body's numbers now (call it every frame; it writes the DOM only when a shown value changes). */\n update(view: PlayerHudView): void\n setTitle(title: string | null): void\n /** The weapon in the hand, or null when the hand is empty. */\n setWeapon(weapon: PlayerHudWeapon | null): void\n /** The crosshair is drawn in the first person only (the third person aims with the body). */\n setView(view: 'first' | 'third'): void\n /** A line at the top centre for `seconds` (the body's `message` events, in `playerTextOf` words). */\n message(text: string, seconds: number): void\n dispose(): void\n}\n\nconst LOW_SHARE = 0.25\nconst WARN_SHARE = 0.5\nconst MS_PER_SECOND = 1000\n\nconst element = <K extends keyof HTMLElementTagNameMap>(tag: K, className?: string, text?: string): HTMLElementTagNameMap[K] => {\n const node = document.createElement(tag)\n if (className) node.className = className\n if (text !== undefined) node.textContent = text\n return node\n}\n\ntype Gauge = { readonly row: HTMLElement; set(value: number, max: number): void }\n\nfunction createGauge(label: string, tone: 'hp' | 'stamina'): Gauge {\n const row = element('div', 'gp-hud-row')\n const bar = element('div', tone === 'hp' ? 'gp-hud-bar hp' : 'gp-hud-bar')\n const fill = element('i')\n const value = element('output')\n bar.appendChild(fill)\n row.append(element('span', undefined, label), bar, value)\n let lastValue = Number.NaN\n let lastPercent = Number.NaN\n return {\n row,\n set(current, max) {\n const share = max > 0 ? Math.max(0, Math.min(1, current / max)) : 0\n const shownValue = Math.max(0, Math.round(current))\n const percent = Math.round(share * 100)\n if (shownValue === lastValue && percent === lastPercent) return\n lastValue = shownValue\n lastPercent = percent\n fill.style.width = `${percent}%`\n value.textContent = String(shownValue)\n if (tone === 'hp') bar.className = share <= LOW_SHARE ? 'gp-hud-bar bad' : share <= WARN_SHARE ? 'gp-hud-bar warn' : 'gp-hud-bar hp'\n },\n }\n}\n\nfunction statusTags(view: PlayerHudView, text: PlayerHudText): Array<{ readonly label: string; readonly tone: 'bad' | 'warn' | '' }> {\n const tags: Array<{ label: string; tone: 'bad' | 'warn' | '' }> = []\n if (view.bleeding) tags.push({ label: text.bleeding, tone: 'bad' })\n if (view.infection !== 'none') tags.push({ label: `${text.infected} · ${stageTextOf(text, view.infection)}`, tone: 'warn' })\n if (view.wounds.length > 0) {\n const counts = new Map<string, number>()\n for (const kind of view.wounds) counts.set(kind, (counts.get(kind) ?? 0) + 1)\n const list = [...counts].map(([kind, count]) => (count > 1 ? `${count}× ${woundTextOf(text, kind)}` : woundTextOf(text, kind))).join(', ')\n tags.push({ label: `${text.wounds}: ${list}`, tone: '' })\n }\n return tags\n}\n\n/**\n * The player's HUD over the game's view (DOM, no three.js): the health and stamina bars with the bleeding, the infection and the wounds under them at the bottom left, the\n * weapon and its rounds at the bottom right, a name at the top left, the body's messages at the top centre and the crosshair in the first person. Small boxes at the edges:\n * the view stays clear, and nothing takes the mouse.\n */\nexport function createPlayerHud({ container, locale = 'pt-BR', title }: PlayerHudOptions): PlayerHud {\n const text = playerHudTextOf(locale)\n ensurePlayerHudStyle()\n const restorePosition = positionContainer(container)\n const root = element('div', 'gp-hud')\n root.dataset.hud = 'player'\n const titleBox = element('div', 'gp-hud-pill gp-hud-title')\n const messageBox = element('div', 'gp-hud-message')\n const vitals = element('div', 'gp-hud-vitals')\n const health = createGauge(text.health, 'hp')\n const stamina = createGauge(text.stamina, 'stamina')\n const status = element('div', 'gp-hud-status')\n vitals.append(health.row, stamina.row, status)\n const weaponBox = element('div', 'gp-hud-pill gp-hud-weapon')\n const cross = element('div', 'gp-hud-cross')\n cross.appendChild(element('i'))\n root.append(titleBox, messageBox, vitals, weaponBox, cross)\n container.appendChild(root)\n\n // the status line is rebuilt only when one of these scalars moves: the frame allocates nothing\n let lastBleeding: boolean | null = null\n let lastInfection = ''\n let lastWounds: readonly string[] | null = null\n let lastWoundCount = -1\n let lastAlive: boolean | null = null\n let lastView: 'first' | 'third' | null = null\n let messageTimer: ReturnType<typeof setTimeout> | null = null\n const setTitle = (next: string | null): void => {\n titleBox.textContent = next ?? ''\n titleBox.style.display = next ? 'block' : 'none'\n }\n setTitle(title ?? null)\n\n return {\n update(view) {\n if (view.alive !== lastAlive) {\n lastAlive = view.alive\n vitals.style.display = view.alive ? 'flex' : 'none'\n }\n health.set(view.health, view.maxHealth)\n stamina.set(view.stamina, view.maxStamina)\n if (view.bleeding === lastBleeding && view.infection === lastInfection && view.wounds === lastWounds && view.wounds.length === lastWoundCount) return\n lastBleeding = view.bleeding\n lastInfection = view.infection\n lastWounds = view.wounds\n lastWoundCount = view.wounds.length\n const tags = statusTags(view, text)\n status.replaceChildren(...tags.map((tag) => element('span', tag.tone ? `gp-hud-tag ${tag.tone}` : 'gp-hud-tag', tag.label)))\n },\n setTitle,\n setWeapon(weapon) {\n weaponBox.replaceChildren()\n weaponBox.style.display = weapon ? 'block' : 'none'\n if (!weapon) return\n weaponBox.append(document.createTextNode(weapon.name))\n if (weapon.ammo) weaponBox.append(element('small', undefined, weapon.ammo))\n },\n setView(view) {\n if (view === lastView) return\n lastView = view\n cross.style.display = view === 'first' ? 'block' : 'none'\n },\n message(line, seconds) {\n messageBox.textContent = line\n messageBox.style.display = 'block'\n if (messageTimer) clearTimeout(messageTimer)\n messageTimer = setTimeout(() => {\n messageTimer = null\n messageBox.style.display = 'none'\n }, seconds * MS_PER_SECOND)\n },\n dispose() {\n if (messageTimer) clearTimeout(messageTimer)\n root.remove()\n restorePosition()\n },\n }\n}\n","import { playerTextOf } from '../locales'\nimport { ensurePlayerHudStyle, positionContainer } from './hud-style'\nimport { formatSurvived, playerHudTextOf } from './hud-text'\n\nexport type DeathScreenOptions = {\n readonly container: HTMLElement\n /** `pt-BR` (default) or `en`. */\n readonly locale?: string\n /** Seconds after the death before the panel opens: the death camera settles on the body first. Default 1.5. */\n readonly delaySeconds?: number\n /** Rebuilds the scene from its seed. Enter and R press it too. */\n readonly onRestart: () => void\n /** Puts the body back at the start with the world as it is. */\n readonly onBackToStart: () => void\n /** What takes the focus back when the panel shuts (the game's canvas); absent, what had it before the panel opened. */\n readonly returnFocus?: HTMLElement\n}\n\n/** The body as the death screen reads it: `game-player`'s `state.alive`, `state.deathTime` and `state.cause`, and the seconds the game ran before the death. */\nexport type DeathScreenState = {\n readonly alive: boolean\n /** Seconds since the death. */\n readonly deathTime: number\n /** The cause id (`killed`, `bled_out`...), shown in `playerTextOf` words. */\n readonly cause?: string\n readonly survivedSeconds: number\n}\n\nexport type DeathScreen = {\n /** Call it every frame: it opens once the body has been dead `delaySeconds`, and closes when the body is alive again. */\n update(state: DeathScreenState): void\n readonly isOpen: boolean\n dispose(): void\n}\n\nexport const DEATH_SCREEN_DELAY_SECONDS = 1.5\nconst RESTART_KEY = 'KeyR'\nlet nextHeadingId = 0\n\n/**\n * The death screen (DOM, no three.js): a panel in the lower third (the death camera keeps the body at the centre) with \"you died\", the cause, the time survived and two buttons,\n * restart the scene and back to the start. It opens once the death camera has settled, frees the mouse from the pointer lock and focuses the restart button (Enter presses the focused\n * button, R restarts from anywhere), calls each hook once until the body lives again, and gives the focus back when it shuts.\n */\nexport function createDeathScreen({ container, locale = 'pt-BR', delaySeconds = DEATH_SCREEN_DELAY_SECONDS, onRestart, onBackToStart, returnFocus }: DeathScreenOptions): DeathScreen {\n const text = playerHudTextOf(locale)\n ensurePlayerHudStyle()\n const restorePosition = positionContainer(container)\n const root = document.createElement('div')\n root.className = 'gp-death'\n root.setAttribute('role', 'dialog')\n root.setAttribute('aria-modal', 'true')\n const panel = document.createElement('div')\n panel.className = 'gp-death-panel'\n const heading = document.createElement('h2')\n heading.id = `gp-death-title-${nextHeadingId++}`\n heading.textContent = text.died\n root.setAttribute('aria-labelledby', heading.id)\n const cause = document.createElement('p')\n const survived = document.createElement('p')\n const actions = document.createElement('div')\n actions.className = 'gp-death-actions'\n const button = (label: string, key: string | null): HTMLButtonElement => {\n const node = document.createElement('button')\n node.type = 'button'\n node.append(document.createTextNode(label))\n if (key) {\n const hint = document.createElement('kbd')\n hint.textContent = key\n node.appendChild(hint)\n }\n actions.appendChild(node)\n return node\n }\n const restartButton = button(text.restart, 'R')\n const backButton = button(text.backToStart, null)\n panel.append(heading, cause, survived, actions)\n root.appendChild(panel)\n container.appendChild(root)\n\n let isOpen = false\n let isSpent = false\n let focusBefore: Element | null = null\n const setEnabled = (enabled: boolean): void => {\n restartButton.disabled = !enabled\n backButton.disabled = !enabled\n }\n const choose = (hook: () => void): void => {\n if (!isOpen || isSpent) return\n isSpent = true\n setEnabled(false)\n try {\n hook()\n } catch (error) {\n isSpent = false\n setEnabled(true)\n throw error\n }\n }\n restartButton.onclick = () => choose(onRestart)\n backButton.onclick = () => choose(onBackToStart)\n // Enter is left to the focused button (the browser presses it): only R is caught here, and it restarts from anywhere, a focused button included\n const onKeyDown = (event: KeyboardEvent): void => {\n if (!isOpen || event.code !== RESTART_KEY) return\n event.preventDefault()\n choose(onRestart)\n }\n window.addEventListener('keydown', onKeyDown)\n\n const open = (state: DeathScreenState): void => {\n isOpen = true\n isSpent = false\n restartButton.disabled = false\n backButton.disabled = false\n cause.textContent = state.cause ? playerTextOf(state.cause, locale) : ''\n cause.style.display = state.cause ? 'block' : 'none'\n survived.textContent = text.survived.replace('{time}', formatSurvived(state.survivedSeconds))\n root.classList.add('open')\n if (document.pointerLockElement) document.exitPointerLock()\n focusBefore = document.activeElement\n restartButton.focus()\n }\n const close = (): void => {\n isOpen = false\n if (root.contains(document.activeElement) && document.activeElement instanceof HTMLElement) document.activeElement.blur()\n root.classList.remove('open')\n const target = returnFocus ?? (focusBefore instanceof HTMLElement && focusBefore.isConnected && focusBefore !== document.body ? focusBefore : null)\n focusBefore = null\n target?.focus({ preventScroll: true })\n }\n\n return {\n update(state) {\n if (state.alive) {\n if (isOpen) close()\n return\n }\n if (!isOpen && state.deathTime >= delaySeconds) open(state)\n },\n get isOpen() {\n return isOpen\n },\n dispose() {\n window.removeEventListener('keydown', onKeyDown)\n root.remove()\n restorePosition()\n },\n }\n}\n","import type { Player } from '../player'\n\n/** An infection stage as `Player.stage()` answers it. */\nexport type InfectionStage = ReturnType<Player['stage']>\n\n/** What the HUD shows of a body, read from its state: plain numbers, so a game with its own body fills it too. */\nexport type PlayerHudView = {\n readonly alive: boolean\n readonly health: number\n readonly maxHealth: number\n readonly stamina: number\n readonly maxStamina: number\n readonly bleeding: boolean\n /** The open wounds by kind, oldest first (`scratch`, `laceration`, `bite`, or a game's own kinds). */\n readonly wounds: readonly string[]\n readonly infection: InfectionStage\n}\n\n/** The HUD's view of a `game-player` body now, as a new object (a frame loop refills one with `writePlayerHudView`). */\nexport const playerHudViewOf = (player: Pick<Player, 'state' | 'derived' | 'stage'>): PlayerHudView => writePlayerHudView(player, createPlayerHudView())\n\n/** A view the host keeps and refills every frame (`writePlayerHudView`), so the frame allocates nothing. */\nexport type MutablePlayerHudView = { -readonly [K in keyof PlayerHudView]: PlayerHudView[K] }\n\n/** An empty view to refill. */\nexport const createPlayerHudView = (): MutablePlayerHudView => ({ alive: true, health: 0, maxHealth: 0, stamina: 0, maxStamina: 0, bleeding: false, wounds: [], infection: 'none' })\n\n/** Writes the body's numbers now into `view` (no allocation) and answers it. */\nexport function writePlayerHudView(player: Pick<Player, 'state' | 'derived' | 'stage'>, view: MutablePlayerHudView): MutablePlayerHudView {\n const { state, derived } = player\n view.alive = state.alive\n view.health = state.health\n view.maxHealth = derived.maxHealth\n view.stamina = state.stamina\n view.maxStamina = derived.maxStamina\n view.bleeding = state.bleeding > 0\n view.wounds = state.wounds\n view.infection = state.infected ? player.stage() : 'none'\n return view\n}\n"],"mappings":";;;;;AAEO,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmC9B,IAAM,WAAW;AAGV,SAAS,uBAA6B;AAC3C,MAAI,SAAS,eAAe,QAAQ,EAAG;AACvC,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,KAAK;AACX,QAAM,cAAc;AACpB,WAAS,KAAK,YAAY,KAAK;AACjC;AAGO,SAAS,kBAAkB,WAAoC;AACpE,QAAM,WAAW,iBAAiB,SAAS,EAAE;AAC7C,MAAI,YAAY,aAAa,SAAU,QAAO,MAAM;AACpD,QAAM,SAAS,UAAU,MAAM;AAC/B,YAAU,MAAM,WAAW;AAC3B,SAAO,MAAM;AACX,QAAI,UAAU,MAAM,aAAa,WAAY,WAAU,MAAM,WAAW;AAAA,EAC1E;AACF;;;ACtCA,IAAM,QAAuB;AAAA,EAC3B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AACf;AAEA,IAAM,KAAoB;AAAA,EACxB,QAAQ;AAAA,EACR,SAAS;AAA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gBAAgB,uBAAuB,eAAe,YAAY,eAAe,gBAAgB,SAAS,OAAO,cAAc;AAC9I,kBAAc;AACd,YAAQ,MAAM,EAAE,eAAe,KAAK,CAAC;AAAA,EACvC;AAEA,SAAO;AAAA,IACL,OAAO,OAAO;AACZ,UAAI,MAAM,OAAO;AACf,YAAI,OAAQ,OAAM;AAClB;AAAA,MACF;AACA,UAAI,CAAC,UAAU,MAAM,aAAa,aAAc,MAAK,KAAK;AAAA,IAC5D;AAAA,IACA,IAAI,SAAS;AACX,aAAO;AAAA,IACT;AAAA,IACA,UAAU;AACR,aAAO,oBAAoB,WAAW,SAAS;AAC/C,WAAK,OAAO;AACZ,sBAAgB;AAAA,IAClB;AAAA,EACF;AACF;;;ACjIO,IAAM,kBAAkB,CAAC,WAAuE,mBAAmB,QAAQ,oBAAoB,CAAC;AAMhJ,IAAM,sBAAsB,OAA6B,EAAE,OAAO,MAAM,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,UAAU,OAAO,QAAQ,CAAC,GAAG,WAAW,OAAO;AAG3K,SAAS,mBAAmB,QAAqD,MAAkD;AACxI,QAAM,EAAE,OAAO,QAAQ,IAAI;AAC3B,OAAK,QAAQ,MAAM;AACnB,OAAK,SAAS,MAAM;AACpB,OAAK,YAAY,QAAQ;AACzB,OAAK,UAAU,MAAM;AACrB,OAAK,aAAa,QAAQ;AAC1B,OAAK,WAAW,MAAM,WAAW;AACjC,OAAK,SAAS,MAAM;AACpB,OAAK,YAAY,MAAM,WAAW,OAAO,MAAM,IAAI;AACnD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/hud/hud-style.ts","../src/hud/hud-text.ts","../src/hud/player-hud.ts","../src/hud/death-screen.ts","../src/hud/hud-view.ts"],"sourcesContent":["// The death panel sits in the lower third: the death camera keeps the body at the centre of the view.\n// The same tokens as the test room's HUD (panel rgba(10,12,16,.72), accent #ffd23f, bars #2a2e36 / #66bb6a / #ffb300 / #ef5350 / #4fc3f7), so a game and its room read alike.\nexport const PLAYER_HUD_CSS = `\n.gp-hud{position:absolute;inset:0;pointer-events:none;font:12px/1.35 system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif;color:#e8eaee;overflow:hidden;z-index:10}\n.gp-hud *{box-sizing:border-box}\n.gp-hud-pill{background:rgba(10,12,16,.72);padding:4px 12px;border-radius:6px;font-size:14px;font-weight:600}\n.gp-hud-pill small{font-weight:400;opacity:.8;margin-left:8px}\n.gp-hud-title{position:absolute;top:8px;left:8px;display:none}\n.gp-hud-message{position:absolute;top:8px;left:50%;transform:translateX(-50%);max-width:60vw;text-align:center;color:#ffd23f;text-shadow:0 1px 2px #000;font-size:14px;font-weight:600;display:none}\n.gp-hud-vitals{position:absolute;left:8px;bottom:8px;width:210px;background:rgba(10,12,16,.72);border-radius:6px;padding:6px 8px;display:flex;flex-direction:column;gap:4px}\n.gp-hud-row{display:grid;grid-template-columns:62px 1fr 30px;align-items:center;gap:6px}\n.gp-hud-row span:first-child{color:#9aa3b2}\n.gp-hud-row output{text-align:right;font-variant-numeric:tabular-nums}\n.gp-hud-bar{height:7px;background:#2a2e36;border-radius:4px;overflow:hidden}\n.gp-hud-bar i{display:block;height:100%;width:0;background:#4fc3f7}\n.gp-hud-bar.hp i{background:#66bb6a}.gp-hud-bar.need i{background:#c8a165}.gp-hud-bar.warn i{background:#ffb300}.gp-hud-bar.bad i{background:#ef5350}\n.gp-hud-status{display:flex;flex-wrap:wrap;gap:4px}\n.gp-hud-status:empty{display:none}\n.gp-hud-tag{border-radius:4px;padding:0 6px;background:#2a2e36}\n.gp-hud-tag.bad{background:rgba(183,28,28,.9);color:#fff}.gp-hud-tag.warn{background:rgba(120,90,10,.9);color:#fff}\n.gp-hud-weapon{position:absolute;right:8px;bottom:8px;display:none}\n.gp-hud-cross{position:absolute;left:50%;top:50%;width:18px;height:18px;margin:-9px 0 0 -9px;display:none}\n.gp-hud-cross:before,.gp-hud-cross:after{content:\"\";position:absolute;background:#fff;opacity:.85;box-shadow:0 0 2px #000}\n.gp-hud-cross:before{left:8px;top:0;width:2px;height:18px}.gp-hud-cross:after{top:8px;left:0;height:2px;width:18px}\n.gp-hud-cross i{position:absolute;left:6px;top:6px;width:6px;height:6px;background:#0b0c0e;border-radius:50%;z-index:1}\n.gp-death{position:absolute;inset:0;display:none;align-items:flex-end;justify-content:center;padding-bottom:12vh;background:linear-gradient(transparent 45%,rgba(0,0,0,.55));font:13px/1.4 system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif;color:#e8eaee;z-index:20}\n.gp-death.open{display:flex}\n.gp-death-panel{min-width:min(320px,90vw);max-width:90vw;background:rgba(12,14,19,.92);border:1px solid #2c313b;border-radius:8px;padding:18px 22px;text-align:center;box-shadow:0 4px 18px rgba(0,0,0,.5)}\n.gp-death-panel h2{margin:0 0 6px;font-size:22px;color:#ef5350}\n.gp-death-panel p{margin:2px 0;color:#9aa3b2}\n.gp-death-actions{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin-top:14px}\n.gp-death-actions button{background:#232831;border:1px solid #3a404c;color:#e8eaee;border-radius:5px;padding:6px 14px;cursor:pointer;font:inherit}\n.gp-death-actions button:hover,.gp-death-actions button:focus-visible{background:#2d3440;border-color:#ffd23f}\n.gp-death-actions button:disabled{opacity:.5;cursor:default}\n.gp-death-actions kbd{background:#2a2e36;border:1px solid #4a505c;border-radius:3px;padding:0 4px;font:inherit;font-weight:700;margin-left:6px}\n`\n\nconst STYLE_ID = 'gp-hud-style'\n\n/** Puts the HUD's style in the document once (the HUD and the death screen share it). */\nexport function ensurePlayerHudStyle(): void {\n if (document.getElementById(STYLE_ID)) return\n const style = document.createElement('style')\n style.id = STYLE_ID\n style.textContent = PLAYER_HUD_CSS\n document.head.appendChild(style)\n}\n\n/** Makes `container` the positioning box of an overlay laid over it; the answer puts back what it changed. */\nexport function positionContainer(container: HTMLElement): () => void {\n const position = getComputedStyle(container).position\n if (position && position !== 'static') return () => undefined\n const before = container.style.position\n container.style.position = 'relative'\n return () => {\n if (container.style.position === 'relative') container.style.position = before\n }\n}\n","/** The words of the player's HUD and of the death screen, in a locale. */\nexport type PlayerHudText = {\n readonly health: string\n readonly stamina: string\n readonly hunger: string\n readonly thirst: string\n readonly bleeding: string\n readonly wounds: string\n readonly infected: string\n readonly stageMalaise: string\n readonly stageFever: string\n readonly stageDelirium: string\n readonly woundScratch: string\n readonly woundLaceration: string\n readonly woundBite: string\n readonly died: string\n readonly survived: string\n readonly restart: string\n readonly backToStart: string\n}\n\nconst PT_BR: PlayerHudText = {\n health: 'Vida',\n stamina: 'Fôlego',\n hunger: 'Fome',\n thirst: 'Sede',\n bleeding: 'Sangrando',\n wounds: 'Ferimentos',\n infected: 'Infectado',\n stageMalaise: 'mal-estar',\n stageFever: 'febre',\n stageDelirium: 'delírio',\n woundScratch: 'arranhão',\n woundLaceration: 'corte',\n woundBite: 'mordida',\n died: 'Você morreu',\n survived: 'Sobreviveu {time}',\n restart: 'Reiniciar cena',\n backToStart: 'Voltar ao início',\n}\n\nconst EN: PlayerHudText = {\n health: 'Health',\n stamina: 'Stamina',\n hunger: 'Hunger',\n thirst: 'Thirst',\n bleeding: 'Bleeding',\n wounds: 'Wounds',\n infected: 'Infected',\n stageMalaise: 'malaise',\n stageFever: 'fever',\n stageDelirium: 'delirium',\n woundScratch: 'scratch',\n woundLaceration: 'laceration',\n woundBite: 'bite',\n died: 'You died',\n survived: 'Survived {time}',\n restart: 'Restart scene',\n backToStart: 'Back to the start',\n}\n\nexport const PLAYER_HUD_TEXT: Readonly<Record<'en' | 'pt-BR', PlayerHudText>> = { en: EN, 'pt-BR': PT_BR }\n\n/** The HUD's words for a locale (`pt-BR` or `en`, the language part is enough; anything else is `pt-BR`). */\nexport const playerHudTextOf = (locale = 'pt-BR'): PlayerHudText => (locale.toLowerCase().startsWith('en') ? EN : PT_BR)\n\nconst WOUND_KEY: Readonly<Record<string, keyof PlayerHudText>> = { scratch: 'woundScratch', laceration: 'woundLaceration', bite: 'woundBite' }\nconst STAGE_KEY: Readonly<Record<string, keyof PlayerHudText>> = { malaise: 'stageMalaise', fever: 'stageFever', delirium: 'stageDelirium' }\n\n/** A wound kind in words; a kind the table does not know (a game's own) comes back as it is. */\nexport const woundTextOf = (text: PlayerHudText, kind: string): string => {\n const key = WOUND_KEY[kind]\n return key ? text[key] : kind\n}\n\n/** An infection stage in words (`none` gives an empty text). */\nexport const stageTextOf = (text: PlayerHudText, stage: string): string => {\n const key = STAGE_KEY[stage]\n return key ? text[key] : ''\n}\n\n/** Seconds as `m:ss` (or `h:mm:ss` past the hour). */\nexport const formatSurvived = (seconds: number): string => {\n const whole = Math.max(0, Math.floor(seconds))\n const hours = Math.floor(whole / 3600)\n const minutes = Math.floor((whole % 3600) / 60)\n const rest = String(whole % 60).padStart(2, '0')\n return hours > 0 ? `${hours}:${String(minutes).padStart(2, '0')}:${rest}` : `${minutes}:${rest}`\n}\n","import { ensurePlayerHudStyle, positionContainer } from './hud-style'\nimport { playerHudTextOf, stageTextOf, woundTextOf } from './hud-text'\nimport type { PlayerHudText } from './hud-text'\nimport type { PlayerHudView } from './hud-view'\n\n/** The weapon in the hand: its name and, for a gun, the rounds as the game writes them (`12 / 48`). */\nexport type PlayerHudWeapon = { readonly name: string; readonly ammo?: string }\n\nexport type PlayerHudOptions = {\n /** The box the HUD is laid over (the game's canvas box). */\n readonly container: HTMLElement\n /** `pt-BR` (default) or `en`. */\n readonly locale?: string\n /** A name shown at the top left (the level, the scenario); absent, nothing there. */\n readonly title?: string\n}\n\nexport type PlayerHud = {\n /** The body's numbers now (call it every frame; it writes the DOM only when a shown value changes). */\n update(view: PlayerHudView): void\n setTitle(title: string | null): void\n /** The weapon in the hand, or null when the hand is empty. */\n setWeapon(weapon: PlayerHudWeapon | null): void\n /** The crosshair is drawn in the first person only (the third person aims with the body). */\n setView(view: 'first' | 'third'): void\n /** A line at the top centre for `seconds` (the body's `message` events, in `playerTextOf` words). */\n message(text: string, seconds: number): void\n dispose(): void\n}\n\nconst LOW_SHARE = 0.25\nconst WARN_SHARE = 0.5\nconst MS_PER_SECOND = 1000\n\nconst element = <K extends keyof HTMLElementTagNameMap>(tag: K, className?: string, text?: string): HTMLElementTagNameMap[K] => {\n const node = document.createElement(tag)\n if (className) node.className = className\n if (text !== undefined) node.textContent = text\n return node\n}\n\ntype Gauge = { readonly row: HTMLElement; set(value: number, max: number): void }\n\n/** `hp` greens when full and reds when low; `need` (hunger, thirst) turns amber past half and red past `starving` (a share of the bar). */\nfunction createGauge(label: string, tone: 'hp' | 'stamina' | 'need', starving = 0.9): Gauge {\n const row = element('div', 'gp-hud-row')\n const bar = element('div', tone === 'hp' ? 'gp-hud-bar hp' : tone === 'need' ? 'gp-hud-bar need' : 'gp-hud-bar')\n const fill = element('i')\n const value = element('output')\n bar.appendChild(fill)\n row.append(element('span', undefined, label), bar, value)\n let lastValue = Number.NaN\n let lastPercent = Number.NaN\n return {\n row,\n set(current, max) {\n const share = max > 0 ? Math.max(0, Math.min(1, current / max)) : 0\n const shownValue = Math.max(0, Math.round(current))\n const percent = Math.round(share * 100)\n if (shownValue === lastValue && percent === lastPercent) return\n lastValue = shownValue\n lastPercent = percent\n fill.style.width = `${percent}%`\n value.textContent = String(shownValue)\n if (tone === 'hp') bar.className = share <= LOW_SHARE ? 'gp-hud-bar bad' : share <= WARN_SHARE ? 'gp-hud-bar warn' : 'gp-hud-bar hp'\n else if (tone === 'need') bar.className = share > starving ? 'gp-hud-bar bad' : share > WARN_SHARE ? 'gp-hud-bar warn' : 'gp-hud-bar need'\n },\n }\n}\n\nfunction statusTags(view: PlayerHudView, text: PlayerHudText): Array<{ readonly label: string; readonly tone: 'bad' | 'warn' | '' }> {\n const tags: Array<{ label: string; tone: 'bad' | 'warn' | '' }> = []\n if (view.bleeding) tags.push({ label: text.bleeding, tone: 'bad' })\n if (view.infection !== 'none') tags.push({ label: `${text.infected} · ${stageTextOf(text, view.infection)}`, tone: 'warn' })\n if (view.wounds.length > 0) {\n const counts = new Map<string, number>()\n for (const kind of view.wounds) counts.set(kind, (counts.get(kind) ?? 0) + 1)\n const list = [...counts].map(([kind, count]) => (count > 1 ? `${count}× ${woundTextOf(text, kind)}` : woundTextOf(text, kind))).join(', ')\n tags.push({ label: `${text.wounds}: ${list}`, tone: '' })\n }\n return tags\n}\n\n/** The body's box of the HUD on its own (health, stamina, hunger, thirst, and the bleeding, infection and wounds under them), for a host that lays out its own screen. */\nexport type VitalsPanel = {\n /** The box (class `gp-hud-vitals`: the bottom left of an element of class `gp-hud`, which gives it the font). */\n readonly element: HTMLElement\n update(view: PlayerHudView): void\n}\n\n/** The vitals box of `createPlayerHud`, alone: put `element` inside an element of class `gp-hud` (the style goes in the document once). */\nexport function createVitalsPanel(locale = 'pt-BR'): VitalsPanel {\n const text = playerHudTextOf(locale)\n ensurePlayerHudStyle()\n const vitals = element('div', 'gp-hud-vitals')\n const health = createGauge(text.health, 'hp')\n const stamina = createGauge(text.stamina, 'stamina')\n const status = element('div', 'gp-hud-status')\n vitals.append(health.row, stamina.row, status)\n // the hunger and thirst rows come with the first view that has them, and go with the first that has not\n let needs: { readonly hunger: Gauge; readonly thirst: Gauge } | null = null\n // the status line is rebuilt only when one of these scalars moves: the frame allocates nothing\n let lastBleeding: boolean | null = null\n let lastInfection = ''\n let lastWounds: readonly string[] | null = null\n let lastWoundCount = -1\n let lastAlive: boolean | null = null\n return {\n element: vitals,\n update(view) {\n if (view.alive !== lastAlive) {\n lastAlive = view.alive\n vitals.style.display = view.alive ? 'flex' : 'none'\n }\n health.set(view.health, view.maxHealth)\n stamina.set(view.stamina, view.maxStamina)\n stamina.row.style.display = view.maxStamina > 0 ? '' : 'none'\n if (view.hunger !== undefined && view.thirst !== undefined) {\n const max = view.needMax ?? 100\n if (!needs) {\n const starving = max > 0 ? (view.needStarving ?? max * 0.9) / max : 0.9\n needs = { hunger: createGauge(text.hunger, 'need', starving), thirst: createGauge(text.thirst, 'need', starving) }\n vitals.insertBefore(needs.hunger.row, status)\n vitals.insertBefore(needs.thirst.row, status)\n }\n needs.hunger.set(view.hunger, max)\n needs.thirst.set(view.thirst, max)\n } else if (needs) {\n needs.hunger.row.remove()\n needs.thirst.row.remove()\n needs = null\n }\n if (view.bleeding === lastBleeding && view.infection === lastInfection && view.wounds === lastWounds && view.wounds.length === lastWoundCount) return\n lastBleeding = view.bleeding\n lastInfection = view.infection\n lastWounds = view.wounds\n lastWoundCount = view.wounds.length\n const tags = statusTags(view, text)\n status.replaceChildren(...tags.map((tag) => element('span', tag.tone ? `gp-hud-tag ${tag.tone}` : 'gp-hud-tag', tag.label)))\n },\n }\n}\n\n/**\n * The player's HUD over the game's view (DOM, no three.js): the health, stamina, hunger and thirst bars with the bleeding, the infection and the wounds under them at the bottom left, the\n * weapon and its rounds at the bottom right, a name at the top left, the body's messages at the top centre and the crosshair in the first person. Small boxes at the edges:\n * the view stays clear, and nothing takes the mouse.\n */\nexport function createPlayerHud({ container, locale = 'pt-BR', title }: PlayerHudOptions): PlayerHud {\n ensurePlayerHudStyle()\n const restorePosition = positionContainer(container)\n const root = element('div', 'gp-hud')\n root.dataset.hud = 'player'\n const titleBox = element('div', 'gp-hud-pill gp-hud-title')\n const messageBox = element('div', 'gp-hud-message')\n const vitals = createVitalsPanel(locale)\n const weaponBox = element('div', 'gp-hud-pill gp-hud-weapon')\n const cross = element('div', 'gp-hud-cross')\n cross.appendChild(element('i'))\n root.append(titleBox, messageBox, vitals.element, weaponBox, cross)\n container.appendChild(root)\n\n let lastView: 'first' | 'third' | null = null\n let messageTimer: ReturnType<typeof setTimeout> | null = null\n const setTitle = (next: string | null): void => {\n titleBox.textContent = next ?? ''\n titleBox.style.display = next ? 'block' : 'none'\n }\n setTitle(title ?? null)\n\n return {\n update: (view) => vitals.update(view),\n setTitle,\n setWeapon(weapon) {\n weaponBox.replaceChildren()\n weaponBox.style.display = weapon ? 'block' : 'none'\n if (!weapon) return\n weaponBox.append(document.createTextNode(weapon.name))\n if (weapon.ammo) weaponBox.append(element('small', undefined, weapon.ammo))\n },\n setView(view) {\n if (view === lastView) return\n lastView = view\n cross.style.display = view === 'first' ? 'block' : 'none'\n },\n message(line, seconds) {\n messageBox.textContent = line\n messageBox.style.display = 'block'\n if (messageTimer) clearTimeout(messageTimer)\n messageTimer = setTimeout(() => {\n messageTimer = null\n messageBox.style.display = 'none'\n }, seconds * MS_PER_SECOND)\n },\n dispose() {\n if (messageTimer) clearTimeout(messageTimer)\n root.remove()\n restorePosition()\n },\n }\n}\n","import { playerTextOf } from '../locales'\nimport { ensurePlayerHudStyle, positionContainer } from './hud-style'\nimport { formatSurvived, playerHudTextOf } from './hud-text'\n\nexport type DeathScreenOptions = {\n readonly container: HTMLElement\n /** `pt-BR` (default) or `en`. */\n readonly locale?: string\n /** Seconds after the death before the panel opens: the death camera settles on the body first. Default 1.5. */\n readonly delaySeconds?: number\n /** Rebuilds the scene from its seed. Enter and R press it too. */\n readonly onRestart: () => void\n /** Puts the body back at the start with the world as it is. */\n readonly onBackToStart: () => void\n /** What takes the focus back when the panel shuts (the game's canvas); absent, what had it before the panel opened. */\n readonly returnFocus?: HTMLElement\n}\n\n/** The body as the death screen reads it: `game-player`'s `state.alive`, `state.deathTime` and `state.cause`, and the seconds the game ran before the death. */\nexport type DeathScreenState = {\n readonly alive: boolean\n /** Seconds since the death. */\n readonly deathTime: number\n /** The cause id (`killed`, `bled_out`...), shown in `playerTextOf` words. */\n readonly cause?: string\n readonly survivedSeconds: number\n}\n\nexport type DeathScreen = {\n /** Call it every frame: it opens once the body has been dead `delaySeconds`, and closes when the body is alive again. */\n update(state: DeathScreenState): void\n readonly isOpen: boolean\n dispose(): void\n}\n\nexport const DEATH_SCREEN_DELAY_SECONDS = 1.5\nconst RESTART_KEY = 'KeyR'\nlet nextHeadingId = 0\n\n/**\n * The death screen (DOM, no three.js): a panel in the lower third (the death camera keeps the body at the centre) with \"you died\", the cause, the time survived and two buttons,\n * restart the scene and back to the start. It opens once the death camera has settled, frees the mouse from the pointer lock and focuses the restart button (Enter presses the focused\n * button, R restarts from anywhere), calls each hook once until the body lives again, and gives the focus back when it shuts.\n */\nexport function createDeathScreen({ container, locale = 'pt-BR', delaySeconds = DEATH_SCREEN_DELAY_SECONDS, onRestart, onBackToStart, returnFocus }: DeathScreenOptions): DeathScreen {\n const text = playerHudTextOf(locale)\n ensurePlayerHudStyle()\n const restorePosition = positionContainer(container)\n const root = document.createElement('div')\n root.className = 'gp-death'\n root.setAttribute('role', 'dialog')\n root.setAttribute('aria-modal', 'true')\n const panel = document.createElement('div')\n panel.className = 'gp-death-panel'\n const heading = document.createElement('h2')\n heading.id = `gp-death-title-${nextHeadingId++}`\n heading.textContent = text.died\n root.setAttribute('aria-labelledby', heading.id)\n const cause = document.createElement('p')\n const survived = document.createElement('p')\n const actions = document.createElement('div')\n actions.className = 'gp-death-actions'\n const button = (label: string, key: string | null): HTMLButtonElement => {\n const node = document.createElement('button')\n node.type = 'button'\n node.append(document.createTextNode(label))\n if (key) {\n const hint = document.createElement('kbd')\n hint.textContent = key\n node.appendChild(hint)\n }\n actions.appendChild(node)\n return node\n }\n const restartButton = button(text.restart, 'R')\n const backButton = button(text.backToStart, null)\n panel.append(heading, cause, survived, actions)\n root.appendChild(panel)\n container.appendChild(root)\n\n let isOpen = false\n let isSpent = false\n let focusBefore: Element | null = null\n const setEnabled = (enabled: boolean): void => {\n restartButton.disabled = !enabled\n backButton.disabled = !enabled\n }\n const choose = (hook: () => void): void => {\n if (!isOpen || isSpent) return\n isSpent = true\n setEnabled(false)\n try {\n hook()\n } catch (error) {\n isSpent = false\n setEnabled(true)\n throw error\n }\n }\n restartButton.onclick = () => choose(onRestart)\n backButton.onclick = () => choose(onBackToStart)\n // Enter is left to the focused button (the browser presses it): only R is caught here, and it restarts from anywhere, a focused button included\n const onKeyDown = (event: KeyboardEvent): void => {\n if (!isOpen || event.code !== RESTART_KEY) return\n event.preventDefault()\n choose(onRestart)\n }\n window.addEventListener('keydown', onKeyDown)\n\n const open = (state: DeathScreenState): void => {\n isOpen = true\n isSpent = false\n restartButton.disabled = false\n backButton.disabled = false\n cause.textContent = state.cause ? playerTextOf(state.cause, locale) : ''\n cause.style.display = state.cause ? 'block' : 'none'\n survived.textContent = text.survived.replace('{time}', formatSurvived(state.survivedSeconds))\n root.classList.add('open')\n if (document.pointerLockElement) document.exitPointerLock()\n focusBefore = document.activeElement\n restartButton.focus()\n }\n const close = (): void => {\n isOpen = false\n if (root.contains(document.activeElement) && document.activeElement instanceof HTMLElement) document.activeElement.blur()\n root.classList.remove('open')\n const target = returnFocus ?? (focusBefore instanceof HTMLElement && focusBefore.isConnected && focusBefore !== document.body ? focusBefore : null)\n focusBefore = null\n target?.focus({ preventScroll: true })\n }\n\n return {\n update(state) {\n if (state.alive) {\n if (isOpen) close()\n return\n }\n if (!isOpen && state.deathTime >= delaySeconds) open(state)\n },\n get isOpen() {\n return isOpen\n },\n dispose() {\n window.removeEventListener('keydown', onKeyDown)\n root.remove()\n restorePosition()\n },\n }\n}\n","import type { Player } from '../player'\n\n/** An infection stage as `Player.stage()` answers it. */\nexport type InfectionStage = ReturnType<Player['stage']>\n\n/** What the HUD shows of a body, read from its state: plain numbers, so a game with its own body fills it too. */\nexport type PlayerHudView = {\n readonly alive: boolean\n readonly health: number\n readonly maxHealth: number\n readonly stamina: number\n readonly maxStamina: number\n readonly bleeding: boolean\n /** The open wounds by kind, oldest first (`scratch`, `laceration`, `bite`, or a game's own kinds). */\n readonly wounds: readonly string[]\n readonly infection: InfectionStage\n /** Hunger and thirst, 0 fed and quenched up to `needMax` (`advanceNeeds`); absent, the HUD shows no needs. */\n readonly hunger?: number\n readonly thirst?: number\n readonly needMax?: number\n /** The level past which a need costs health (`NeedsRules.starvingAt`): the bar turns red there. */\n readonly needStarving?: number\n}\n\n/** The HUD's view of a `game-player` body now, as a new object (a frame loop refills one with `writePlayerHudView`). */\n/** The body the HUD reads: a `game-player` body, or one with the same fields (`needs` absent or null: no hunger and thirst bars). */\nexport type PlayerHudSource = Pick<Player, 'state' | 'derived' | 'stage'> & { readonly needs?: { readonly max: number; readonly starvingAt: number } | null }\n\nexport const playerHudViewOf = (player: PlayerHudSource): PlayerHudView => writePlayerHudView(player, createPlayerHudView())\n\n/** A view the host keeps and refills every frame (`writePlayerHudView`), so the frame allocates nothing. */\nexport type MutablePlayerHudView = { -readonly [K in keyof PlayerHudView]: PlayerHudView[K] }\n\n/** An empty view to refill. */\nexport const createPlayerHudView = (): MutablePlayerHudView => ({ alive: true, health: 0, maxHealth: 0, stamina: 0, maxStamina: 0, bleeding: false, wounds: [], infection: 'none' })\n\n/** Writes the body's numbers now into `view` (no allocation) and answers it. */\nexport function writePlayerHudView(player: PlayerHudSource, view: MutablePlayerHudView): MutablePlayerHudView {\n const { state, derived } = player\n view.alive = state.alive\n view.health = state.health\n view.maxHealth = derived.maxHealth\n view.stamina = state.stamina\n view.maxStamina = derived.maxStamina\n view.bleeding = state.bleeding > 0\n view.wounds = state.wounds\n view.infection = state.infected ? player.stage() : 'none'\n const needs = player.needs\n view.hunger = needs ? state.hunger : undefined\n view.thirst = needs ? state.thirst : undefined\n view.needMax = needs?.max\n view.needStarving = needs?.starvingAt\n return view\n}\n"],"mappings":";;;;;AAEO,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmC9B,IAAM,WAAW;AAGV,SAAS,uBAA6B;AAC3C,MAAI,SAAS,eAAe,QAAQ,EAAG;AACvC,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,KAAK;AACX,QAAM,cAAc;AACpB,WAAS,KAAK,YAAY,KAAK;AACjC;AAGO,SAAS,kBAAkB,WAAoC;AACpE,QAAM,WAAW,iBAAiB,SAAS,EAAE;AAC7C,MAAI,YAAY,aAAa,SAAU,QAAO,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,OAAO,MAAM,IAAI;AACnD,QAAM,QAAQ,OAAO;AACrB,OAAK,SAAS,QAAQ,MAAM,SAAS;AACrC,OAAK,SAAS,QAAQ,MAAM,SAAS;AACrC,OAAK,UAAU,OAAO;AACtB,OAAK,eAAe,OAAO;AAC3B,SAAO;AACT;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as PlayerCollider, b as PlayerController, c as PlayerMessageId, K as KnownDeathCause } from './player-B-CNsXV5.js';
2
- export { A as AttributeId, d as Attributes, D as DeathCause, e as Derived, f as DerivedFormulas, g as DerivedId, I as InfectionRule, L as LinearFormula, M as MeleeItem, h as PLAYER_DEFAULTS, P as Player, i as PlayerAction, j as PlayerCrowd, k as PlayerEvent, l as PlayerEventMap, m as PlayerEventName, n as PlayerInput, o as PlayerNumbers, p as PlayerOptions, q as PlayerSave, r as PlayerSoundId, s as PlayerState, t as PlayerWorld, W as WoundRule, u as WoundTable, v as createPlayer, w as deriveVitals, x as drawWound } from './player-B-CNsXV5.js';
1
+ import { a as PlayerCollider, b as PlayerController, c as PlayerMessageId, K as KnownDeathCause } from './player-D2QiWWBg.js';
2
+ export { A as AttributeId, d as Attributes, B as BodyVitals, e as BodyVitalsOptions, f as BodyVitalsState, D as DeathCause, g as Derived, h as DerivedFormulas, i as DerivedId, I as InfectionRule, j as ItemEffect, k as ItemEffectResult, L as LinearFormula, M as MeleeItem, N as NEEDS_DEFAULTS, l as NeedsRules, m as NeedsState, n as Nourishment, o as PLAYER_DEFAULTS, P as Player, p as PlayerAction, q as PlayerCrowd, r as PlayerEvent, s as PlayerEventMap, t as PlayerEventName, u as PlayerInput, v as PlayerNumbers, w as PlayerOptions, x as PlayerSave, y as PlayerSoundId, z as PlayerState, C as PlayerWorld, V as VitalsBody, W as WoundRule, E as WoundTable, F as advanceNeeds, G as applyItemEffect, H as createBodyVitals, J as createNeedsState, O as createPlayer, Q as deriveVitals, R as drawWound, S as isStarving, T as needsHoursOf, U as nourish } from './player-D2QiWWBg.js';
3
3
  import { Vec3, CharacterId, PhysicsWorld, Layer, PhysicsServices } from '@adatechnology/game-physics';
4
4
  import { SurfaceId } from '@adatechnology/game-contracts';
5
5
  export { PlayerTestModule, PlayerTestModuleOptions, createPlayerTestModule } from './testing.js';
@@ -303,6 +303,8 @@ declare function createDoorUse(rules?: Partial<DoorUseRules>): DoorUse;
303
303
  * interaction puts it away or drops it. When the interaction ends, what was put away comes back to its hand; what fell stays on the ground.
304
304
  * A long gun on its sling (decision of the owner, 2026-11-25) is not put away: it swings onto the sling and hangs on the body (`sling`), and stays there after the interaction until
305
305
  * the player brings it back to the hands; with no sling worn it goes to the next slot that takes it (`SLOT_FALLBACKS`: the back).
306
+ * A second weapon of the belt (a pistol or a knife in the other hand, decision of the owner 2026-11-27) is not thrown away when the holster is taken: it is tucked in the
307
+ * belt (`SLOT_FALLBACKS`: hip, then belt) and comes back after, as the holstered one does. Picking something up never drops a weapon the body has a place for.
306
308
  * Engine-agnostic: the host says what is in each hand and which slots the body wears; this says which hand acts and what happens to each weapon.
307
309
  */
308
310
  /** `R` the weapon hand, `L` the other one. */
@@ -321,8 +323,10 @@ interface HandsRules {
321
323
  };
322
324
  }
323
325
  declare const HANDS_DEFAULTS: HandsRules;
324
- /** The slot a weapon goes to when the body wears none of its own: a long gun with no sling goes across the back. */
326
+ /** The slot a weapon goes to when the body wears none of its own (or it is taken): a long gun with no sling goes across the back, a second handgun or knife into the belt. */
325
327
  declare const SLOT_FALLBACKS: Readonly<Record<string, readonly string[]>>;
328
+ /** The belt: where a one-handed weapon is tucked when its own place on the body is taken. */
329
+ declare const BELT_SLOT = "belt";
326
330
  /** The slot of a long gun that hangs on its sling. */
327
331
  declare const SLING_SLOT = "sling";
328
332
  /**
@@ -368,6 +372,38 @@ declare function drawBackOf(plan: HandsPlan): readonly {
368
372
  readonly weapon: string;
369
373
  }[];
370
374
 
375
+ /**
376
+ * Whether one person lifts a thing off the floor with the hands, from its mass and its size (the mass comes from the material of the SDK: density times volume, or
377
+ * the real mass of the catalogue). The strength is the most a person lifts held against the body; a bulky thing is held away from it, and the back takes the load
378
+ * times its lever (the horizontal multiplier of the NIOSH lifting equation: what is held at `H` metres from the spine is `closeReach / H` of what is held against
379
+ * it). The thing is held the easiest way: its thinnest side away from the body, the hands around the middle one. A sofa (45 kg, 2 x 0.9 x 0.85 m) is held at
380
+ * 0.58 m and weighs more than the 26 kg a person lifts that far out: it is pushed or dragged, not picked up. A gas bottle (16 kg, 0.36 m across) goes up.
381
+ * Engine-agnostic: the host passes the mass and the box of the thing.
382
+ */
383
+ interface LiftRules {
384
+ /** The most a person lifts held against the body, kg. */
385
+ readonly maxKg: number;
386
+ /** Distance (m) from the spine to a load held against the body: NIOSH's 25 cm, where the lever costs nothing. */
387
+ readonly closeReach: number;
388
+ /** Distance (m) from the spine to the near face of what is held: the front of the trunk. */
389
+ readonly bodyDepth: number;
390
+ /** The widest a person holds between the hands around a thing, metres: the arms hugging it. */
391
+ readonly maxSpan: number;
392
+ }
393
+ declare const LIFT_DEFAULTS: LiftRules;
394
+ /** `ok` it goes up; `too_heavy` heavier than the strength even against the body; `too_bulky` too wide for the arms or too far out for its weight. */
395
+ type LiftVerdict = 'ok' | 'too_heavy' | 'too_bulky';
396
+ interface LiftCheck {
397
+ readonly verdict: LiftVerdict;
398
+ /** The most this thing could weigh and still go up, held its easiest way, kg. */
399
+ readonly liftableKg: number;
400
+ }
401
+ /** Whether a thing of `massKg` and `size` (metres, any order; without it, a thing held against the body) goes up in one person's hands. */
402
+ declare function liftCheckFor(thing: {
403
+ readonly massKg: number;
404
+ readonly size?: readonly number[];
405
+ }, rules?: Partial<LiftRules>): LiftCheck;
406
+
371
407
  /**
372
408
  * The little pose algebra the hands need, engine-agnostic: a pose is a position and a unit quaternion `[x, y, z, w]` (local to world), as `HandPose` of game-contracts.
373
409
  */
@@ -505,4 +541,4 @@ declare const STEP_POSE_DEFAULTS: {
505
541
  };
506
542
  declare function createStepPose(start: StepPosition, options?: StepPoseOptions): StepPose;
507
543
 
508
- export { type BodyHand, DOOR_ARM_REACH, DOOR_SHOULDER_HEIGHT, DOOR_USE_DEFAULTS, type DoorUse, type DoorUseBlock, type DoorUseHand, type DoorUsePhase, type DoorUseRules, type DoorUseStep, type DoorUseTarget, type DragMark, FURNITURE_PUSH_DEFAULTS, type FurniturePush, type FurniturePushBlock, type FurniturePushInput, type FurniturePushLoad, type FurniturePushPhase, type FurniturePushRules, type FurniturePushStep, type FurniturePushTarget, HANDS_DEFAULTS, HANDS_TIMING, type HandWeapon, type HandsMove, type HandsMoveKind, type HandsPlan, type HandsRules, type HandsTiming, ITEM_GRIP, type ItemGrip, KnownDeathCause, PLAYER_MASS_KG, PLAYER_PUSH_STRENGTH_NEWTONS, PLAYER_TEXT, PLAYER_WALK_PUSH_NEWTONS, type PhysicsControllerOptions, type PhysicsPlayerController, type PlanHandsParams, PlayerCollider, PlayerController, PlayerMessageId, type PlayerPhysicsWorld, type PlayerText, type Pose, type QuatTuple, SLING_SLOT, SLOT_FALLBACKS, STEP_POSE_DEFAULTS, type StepPose, type StepPoseOptions, type StepPosition, type TakeProgress, type TakeSequence, type TakeStep, type TakeStepKind, type TakeTimeline, type Vec3Tuple, WALKER_JUMP_SPEED, type Walker, type WalkerOptions, type WalkerServices, type WalkerStance, blendPoses, canPush, composePose, conjugateQuaternion, createDoorUse, createFurniturePush, createPhysicsController, createRng, createStepPose, createTakeTimeline, createWalker, dragMarkFor, drawBackOf, easeInOut, footRestHeight, frictionFor, gripOfItem, gripSecondsFor, handPoseOnItem, interactionHandsFor, itemPoseInHand, multiplyQuaternions, planDrawSequence, planHands, planTakeSequence, playerTextOf, poseHolding, pushAccelerationFor, pushSpeedFor, quaternionOfBasis, rotateVector, slipsOnTop, swingSecondsFor };
544
+ export { BELT_SLOT, type BodyHand, DOOR_ARM_REACH, DOOR_SHOULDER_HEIGHT, DOOR_USE_DEFAULTS, type DoorUse, type DoorUseBlock, type DoorUseHand, type DoorUsePhase, type DoorUseRules, type DoorUseStep, type DoorUseTarget, type DragMark, FURNITURE_PUSH_DEFAULTS, type FurniturePush, type FurniturePushBlock, type FurniturePushInput, type FurniturePushLoad, type FurniturePushPhase, type FurniturePushRules, type FurniturePushStep, type FurniturePushTarget, HANDS_DEFAULTS, HANDS_TIMING, type HandWeapon, type HandsMove, type HandsMoveKind, type HandsPlan, type HandsRules, type HandsTiming, ITEM_GRIP, type ItemGrip, KnownDeathCause, LIFT_DEFAULTS, type LiftCheck, type LiftRules, type LiftVerdict, PLAYER_MASS_KG, PLAYER_PUSH_STRENGTH_NEWTONS, PLAYER_TEXT, PLAYER_WALK_PUSH_NEWTONS, type PhysicsControllerOptions, type PhysicsPlayerController, type PlanHandsParams, PlayerCollider, PlayerController, PlayerMessageId, type PlayerPhysicsWorld, type PlayerText, type Pose, type QuatTuple, SLING_SLOT, SLOT_FALLBACKS, STEP_POSE_DEFAULTS, type StepPose, type StepPoseOptions, type StepPosition, type TakeProgress, type TakeSequence, type TakeStep, type TakeStepKind, type TakeTimeline, type Vec3Tuple, WALKER_JUMP_SPEED, type Walker, type WalkerOptions, type WalkerServices, type WalkerStance, blendPoses, canPush, composePose, conjugateQuaternion, createDoorUse, createFurniturePush, createPhysicsController, createRng, createStepPose, createTakeTimeline, createWalker, dragMarkFor, drawBackOf, easeInOut, footRestHeight, frictionFor, gripOfItem, gripSecondsFor, handPoseOnItem, interactionHandsFor, itemPoseInHand, liftCheckFor, multiplyQuaternions, planDrawSequence, planHands, planTakeSequence, playerTextOf, poseHolding, pushAccelerationFor, pushSpeedFor, quaternionOfBasis, rotateVector, slipsOnTop, swingSecondsFor };