@adatechnology/game-player 0.7.0 → 0.8.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/README.md +8 -0
- package/dist/hud.d.ts +1 -1
- package/dist/index.d.ts +63 -3
- package/dist/index.global.js +32 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/dist/{player-BRl5ea2y.d.ts → player-Bjhc2M8F.d.ts} +1 -1
- package/dist/testing.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -87,3 +87,11 @@ The walk with the piece speeds up and brakes like a person's (`accel`: the force
|
|
|
87
87
|
## Opening doors by hand
|
|
88
88
|
|
|
89
89
|
`createDoorUse(rules?)` is the logic of working a door, lid or drawer by hand: `begin({ opening, massKg, locked })` answers where the leaf goes (1 open, 0 closed; a second `begin` in the middle of a swing turns it round) or null for a locked leaf, which only rattles. `step(dt, isFree, hand?)` then goes through `reach` (the hand to the handle), `swing` (the leaf follows the hand, a little at a time so it stops at the first thing in its way, `block: 'obstacle'`) and `release`. The player does not follow the leaf: when `hand.reaches()` says the handle left the arm (`DOOR_ARM_REACH` from the shoulder), a leaf that goes away gets a shove (`push`, `hand.pull` false) and one that comes toward the body is let go (`release`), and the leaf finishes on its own to its goal. A heavier leaf swings slower (`swingSecondsFor`); every number is in `DoorUseRules` (`DOOR_USE_DEFAULTS`).
|
|
90
|
+
|
|
91
|
+
## The hands and the weapon
|
|
92
|
+
|
|
93
|
+
`planHands({ hands, weapons: { R, L }, slots })` is the owner's rule (2026-11-24): an interaction of one hand (a small thing picked up, a door, a switch) takes the free hand, not the
|
|
94
|
+
weapon hand, and the weapon stays in its hand; one of both hands (a big thing carried, a push, a climb) first puts the weapon away in a slot the body wears that takes it (a holster at
|
|
95
|
+
the hip for a pistol, a sling on the back for a rifle) and, with none, drops it to the ground. A two-handed weapon (a rifle, a shotgun) leaves no hand free, so any interaction puts it
|
|
96
|
+
away or drops it. `drawBackOf(plan)` says what comes back to the hands when the interaction ends: what was put away, never what fell. `interactionHandsFor({ massKg, size })` says
|
|
97
|
+
whether a thing goes in one hand (up to 4 kg and 0.7 m, `HANDS_DEFAULTS`). The hands and slot of each weapon come from `weaponHandsOf` of `@adatechnology/game-weapons`.
|
package/dist/hud.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as AttributeId,
|
|
1
|
+
import { a as PlayerMessageId, K as KnownDeathCause } from './player-Bjhc2M8F.js';
|
|
2
|
+
export { A as AttributeId, b as Attributes, D as DeathCause, c as Derived, d as DerivedFormulas, e as DerivedId, I as InfectionRule, L as LinearFormula, M as MeleeItem, f as PLAYER_DEFAULTS, P as Player, g as PlayerAction, h as PlayerCollider, i as PlayerCrowd, j as PlayerEvent, k as PlayerEventMap, l as PlayerEventName, m as PlayerInput, n as PlayerNumbers, o as PlayerOptions, p as PlayerSave, q as PlayerSoundId, r as PlayerState, s as PlayerWorld, W as WoundRule, t as WoundTable, u as createPlayer, v as deriveVitals, w as drawWound } from './player-Bjhc2M8F.js';
|
|
3
3
|
import { SurfaceId } from '@adatechnology/game-contracts';
|
|
4
4
|
export { PlayerTestModule, PlayerTestModuleOptions, createPlayerTestModule } from './testing.js';
|
|
5
5
|
|
|
@@ -202,4 +202,64 @@ interface DoorUse {
|
|
|
202
202
|
}
|
|
203
203
|
declare function createDoorUse(rules?: Partial<DoorUseRules>): DoorUse;
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
/**
|
|
206
|
+
* The hands and the weapon (decision of the owner, 2026-11-24): an interaction of one hand (a small thing picked up, a door, a switch) takes the free hand, the one that does not
|
|
207
|
+
* hold the weapon, and the weapon stays in its hand; one of both hands (a big thing carried, a push, a climb) first puts the weapon away in a slot of the body that takes it
|
|
208
|
+
* (a holster at the hip, a sling or back slot for a long gun) and, with none, lets it fall to the ground. A two-handed weapon (a rifle, a shotgun) leaves no hand free, so any
|
|
209
|
+
* 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.
|
|
210
|
+
* 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.
|
|
211
|
+
*/
|
|
212
|
+
/** `R` the weapon hand, `L` the other one. */
|
|
213
|
+
type BodyHand = 'R' | 'L';
|
|
214
|
+
/** A weapon in a hand: `hands` it takes (0 the bare hand, 1, 2) and the slot of the body that takes it (`hip`, `back`...), null when none does. */
|
|
215
|
+
interface HandWeapon {
|
|
216
|
+
readonly id: string;
|
|
217
|
+
readonly hands: 0 | 1 | 2;
|
|
218
|
+
readonly slot: string | null;
|
|
219
|
+
}
|
|
220
|
+
interface HandsRules {
|
|
221
|
+
/** A thing up to `maxKg` whose longest side is up to `maxLength` metres goes in one hand; anything bigger or heavier takes both. */
|
|
222
|
+
readonly oneHand: {
|
|
223
|
+
readonly maxKg: number;
|
|
224
|
+
readonly maxLength: number;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
declare const HANDS_DEFAULTS: HandsRules;
|
|
228
|
+
/** What a weapon does when the hands are wanted: `holster` goes to `slot` and comes back after, `drop` falls to the ground and stays there. */
|
|
229
|
+
interface HandsMove {
|
|
230
|
+
readonly hand: BodyHand;
|
|
231
|
+
readonly weapon: string;
|
|
232
|
+
readonly move: 'holster' | 'drop';
|
|
233
|
+
readonly slot?: string;
|
|
234
|
+
}
|
|
235
|
+
interface HandsPlan {
|
|
236
|
+
/** The hand the interaction takes, or `both`. */
|
|
237
|
+
readonly hand: BodyHand | 'both';
|
|
238
|
+
/** What happens to each weapon that is in the way, the weapon hand first. */
|
|
239
|
+
readonly moves: readonly HandsMove[];
|
|
240
|
+
}
|
|
241
|
+
interface PlanHandsParams {
|
|
242
|
+
/** The hands the interaction takes (`interactionHandsFor` for a thing picked up). */
|
|
243
|
+
readonly hands: 1 | 2;
|
|
244
|
+
/** What each hand holds; absent or null is an empty hand. */
|
|
245
|
+
readonly weapons: {
|
|
246
|
+
readonly R?: HandWeapon | null;
|
|
247
|
+
readonly L?: HandWeapon | null;
|
|
248
|
+
};
|
|
249
|
+
/** The slots the body wears and that are empty (a holster, a sling); one weapon each. */
|
|
250
|
+
readonly slots: readonly string[];
|
|
251
|
+
}
|
|
252
|
+
/** How many hands it takes to carry a thing of `massKg` and `size` (metres, any order). */
|
|
253
|
+
declare function interactionHandsFor(thing: {
|
|
254
|
+
readonly massKg: number;
|
|
255
|
+
readonly size?: readonly number[];
|
|
256
|
+
}, rules?: HandsRules): 1 | 2;
|
|
257
|
+
/** Which hand acts and what happens to each weapon in the way. */
|
|
258
|
+
declare function planHands(params: PlanHandsParams): HandsPlan;
|
|
259
|
+
/** What comes back to the hands once the interaction ends: the weapons that were put away, each to its hand; the dropped ones stay on the ground. */
|
|
260
|
+
declare function drawBackOf(plan: HandsPlan): readonly {
|
|
261
|
+
readonly hand: BodyHand;
|
|
262
|
+
readonly weapon: string;
|
|
263
|
+
}[];
|
|
264
|
+
|
|
265
|
+
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, type HandWeapon, type HandsMove, type HandsPlan, type HandsRules, KnownDeathCause, PLAYER_TEXT, type PlanHandsParams, PlayerMessageId, type PlayerText, canPush, createDoorUse, createFurniturePush, createRng, dragMarkFor, drawBackOf, frictionFor, gripSecondsFor, interactionHandsFor, planHands, playerTextOf, pushAccelerationFor, pushSpeedFor, slipsOnTop, swingSecondsFor };
|
package/dist/index.global.js
CHANGED
|
@@ -25,6 +25,7 @@ var GamePlayer = (() => {
|
|
|
25
25
|
DOOR_SHOULDER_HEIGHT: () => DOOR_SHOULDER_HEIGHT,
|
|
26
26
|
DOOR_USE_DEFAULTS: () => DOOR_USE_DEFAULTS,
|
|
27
27
|
FURNITURE_PUSH_DEFAULTS: () => FURNITURE_PUSH_DEFAULTS,
|
|
28
|
+
HANDS_DEFAULTS: () => HANDS_DEFAULTS,
|
|
28
29
|
PLAYER_DEFAULTS: () => PLAYER_DEFAULTS,
|
|
29
30
|
PLAYER_TEXT: () => PLAYER_TEXT,
|
|
30
31
|
canPush: () => canPush,
|
|
@@ -35,9 +36,12 @@ var GamePlayer = (() => {
|
|
|
35
36
|
createRng: () => createRng,
|
|
36
37
|
deriveVitals: () => deriveVitals,
|
|
37
38
|
dragMarkFor: () => dragMarkFor,
|
|
39
|
+
drawBackOf: () => drawBackOf,
|
|
38
40
|
drawWound: () => drawWound,
|
|
39
41
|
frictionFor: () => frictionFor,
|
|
40
42
|
gripSecondsFor: () => gripSecondsFor,
|
|
43
|
+
interactionHandsFor: () => interactionHandsFor,
|
|
44
|
+
planHands: () => planHands,
|
|
41
45
|
playerTextOf: () => playerTextOf,
|
|
42
46
|
pushAccelerationFor: () => pushAccelerationFor,
|
|
43
47
|
pushSpeedFor: () => pushSpeedFor,
|
|
@@ -1557,6 +1561,34 @@ var GamePlayer = (() => {
|
|
|
1557
1561
|
}
|
|
1558
1562
|
};
|
|
1559
1563
|
}
|
|
1564
|
+
|
|
1565
|
+
// src/hands.ts
|
|
1566
|
+
var HANDS_DEFAULTS = { oneHand: { maxKg: 4, maxLength: 0.7 } };
|
|
1567
|
+
function interactionHandsFor(thing, rules = HANDS_DEFAULTS) {
|
|
1568
|
+
const longest = Math.max(0, ...thing.size ?? []);
|
|
1569
|
+
return thing.massKg > rules.oneHand.maxKg || longest > rules.oneHand.maxLength ? 2 : 1;
|
|
1570
|
+
}
|
|
1571
|
+
var holds = (weapon) => !!weapon && weapon.hands > 0;
|
|
1572
|
+
function planHands(params) {
|
|
1573
|
+
const { R, L } = params.weapons;
|
|
1574
|
+
const free = [...params.slots];
|
|
1575
|
+
const stow = (hand, weapon) => {
|
|
1576
|
+
const at = weapon.slot === null ? -1 : free.indexOf(weapon.slot);
|
|
1577
|
+
if (at < 0) return { hand, weapon: weapon.id, move: "drop" };
|
|
1578
|
+
free.splice(at, 1);
|
|
1579
|
+
return { hand, weapon: weapon.id, move: "holster", slot: weapon.slot };
|
|
1580
|
+
};
|
|
1581
|
+
if (params.hands === 2) {
|
|
1582
|
+
const moves = [...holds(R) ? [stow("R", R)] : [], ...holds(L) ? [stow("L", L)] : []];
|
|
1583
|
+
return { hand: "both", moves };
|
|
1584
|
+
}
|
|
1585
|
+
if (holds(L)) return { hand: "L", moves: [stow("L", L)] };
|
|
1586
|
+
if (!holds(R)) return { hand: "R", moves: [] };
|
|
1587
|
+
return { hand: "L", moves: R.hands === 2 ? [stow("R", R)] : [] };
|
|
1588
|
+
}
|
|
1589
|
+
function drawBackOf(plan) {
|
|
1590
|
+
return plan.moves.filter((move) => move.move === "holster").map((move) => ({ hand: move.hand, weapon: move.weapon }));
|
|
1591
|
+
}
|
|
1560
1592
|
return __toCommonJS(index_exports);
|
|
1561
1593
|
})();
|
|
1562
1594
|
//# sourceMappingURL=index.global.js.map
|