@adatechnology/game-player 0.8.1 → 0.9.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/README.md +4 -0
- package/dist/index.d.ts +27 -1
- package/dist/index.global.js +25 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,10 @@ death.update({ alive: player.state.alive, deathTime: player.state.deathTime, cau
|
|
|
79
79
|
`examples/player-test-area` loads it into the shared test room (`PlayerArea.loadInto(room)`, `sala-jogador.html`), and `examples/interactables-test-area`
|
|
80
80
|
carries it too.
|
|
81
81
|
|
|
82
|
+
## Drawing between fixed steps
|
|
83
|
+
|
|
84
|
+
A body moved in fixed steps and drawn at the last step stutters on any display that is not the step's rate (0, 1 or 2 steps a frame). `createStepPose(start)` keeps the last two step poses: `record(position)` after each step, `blend(context.alpha)` when drawing the body and placing the camera; `reset(position)` after a respawn or a placed body (a step longer than `teleportDistance`, default 3 m, is a teleport and is not swept).
|
|
85
|
+
|
|
82
86
|
## Pushing furniture
|
|
83
87
|
|
|
84
88
|
`createFurniturePush(rules?)` is the logic of pushing a heavy thing on foot: `begin({ massKg, material })`, then `update(dt, { walk, isFree })` every frame answers the step and says the `phase` (`grip` while the hold timer fills, `push`, `strain`), the `progress` of the timer and the `block` (`too_heavy`, `obstacle`). The host answers `isFree` by sweeping the volume of the piece and draws the rest. `gripSecondsFor`, `pushSpeedFor` and `canPush` give the numbers; the force of the legs, the friction by material, the times and the speeds are all in `FurniturePushRules` (`FURNITURE_PUSH_DEFAULTS`).
|
package/dist/index.d.ts
CHANGED
|
@@ -262,4 +262,30 @@ declare function drawBackOf(plan: HandsPlan): readonly {
|
|
|
262
262
|
readonly weapon: string;
|
|
263
263
|
}[];
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Draws a body that moves in fixed steps between two of them: remember the last two step poses, blend by the scheduler's `alpha` (CLAUDE.md §15).
|
|
267
|
+
* Drawn at the step pose, a body moves 0, 1 or 2 steps per frame at a display that is not the step's rate: it stutters.
|
|
268
|
+
*/
|
|
269
|
+
type StepPosition = {
|
|
270
|
+
readonly x: number;
|
|
271
|
+
readonly y: number;
|
|
272
|
+
readonly z: number;
|
|
273
|
+
};
|
|
274
|
+
type StepPoseOptions = {
|
|
275
|
+
/** A step longer than this (metres) is a teleport (a respawn, a placed body): drawn at the new pose at once, never swept across. Default 3. */
|
|
276
|
+
readonly teleportDistance?: number;
|
|
277
|
+
};
|
|
278
|
+
type StepPose = {
|
|
279
|
+
/** The body's pose after a fixed step. */
|
|
280
|
+
record(position: StepPosition): void;
|
|
281
|
+
/** Puts both poses on `position`: nothing is blended from where the body was. */
|
|
282
|
+
reset(position: StepPosition): void;
|
|
283
|
+
/** The pose to draw: `alpha` in [0, 1] is how far the frame is into the next step. */
|
|
284
|
+
blend(alpha: number): StepPosition;
|
|
285
|
+
};
|
|
286
|
+
declare const STEP_POSE_DEFAULTS: {
|
|
287
|
+
readonly teleportDistance: 3;
|
|
288
|
+
};
|
|
289
|
+
declare function createStepPose(start: StepPosition, options?: StepPoseOptions): StepPose;
|
|
290
|
+
|
|
291
|
+
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, STEP_POSE_DEFAULTS, type StepPose, type StepPoseOptions, type StepPosition, canPush, createDoorUse, createFurniturePush, createRng, createStepPose, dragMarkFor, drawBackOf, frictionFor, gripSecondsFor, interactionHandsFor, planHands, playerTextOf, pushAccelerationFor, pushSpeedFor, slipsOnTop, swingSecondsFor };
|
package/dist/index.global.js
CHANGED
|
@@ -28,12 +28,14 @@ var GamePlayer = (() => {
|
|
|
28
28
|
HANDS_DEFAULTS: () => HANDS_DEFAULTS,
|
|
29
29
|
PLAYER_DEFAULTS: () => PLAYER_DEFAULTS,
|
|
30
30
|
PLAYER_TEXT: () => PLAYER_TEXT,
|
|
31
|
+
STEP_POSE_DEFAULTS: () => STEP_POSE_DEFAULTS,
|
|
31
32
|
canPush: () => canPush,
|
|
32
33
|
createDoorUse: () => createDoorUse,
|
|
33
34
|
createFurniturePush: () => createFurniturePush,
|
|
34
35
|
createPlayer: () => createPlayer,
|
|
35
36
|
createPlayerTestModule: () => createPlayerTestModule,
|
|
36
37
|
createRng: () => createRng,
|
|
38
|
+
createStepPose: () => createStepPose,
|
|
37
39
|
deriveVitals: () => deriveVitals,
|
|
38
40
|
dragMarkFor: () => dragMarkFor,
|
|
39
41
|
drawBackOf: () => drawBackOf,
|
|
@@ -1589,6 +1591,29 @@ var GamePlayer = (() => {
|
|
|
1589
1591
|
function drawBackOf(plan) {
|
|
1590
1592
|
return plan.moves.filter((move) => move.move === "holster").map((move) => ({ hand: move.hand, weapon: move.weapon }));
|
|
1591
1593
|
}
|
|
1594
|
+
|
|
1595
|
+
// src/step-pose.ts
|
|
1596
|
+
var STEP_POSE_DEFAULTS = { teleportDistance: 3 };
|
|
1597
|
+
function createStepPose(start, options = {}) {
|
|
1598
|
+
const teleportDistance = options.teleportDistance ?? STEP_POSE_DEFAULTS.teleportDistance;
|
|
1599
|
+
let previous = { x: start.x, y: start.y, z: start.z };
|
|
1600
|
+
let current = { x: start.x, y: start.y, z: start.z };
|
|
1601
|
+
return {
|
|
1602
|
+
record(position) {
|
|
1603
|
+
previous = current;
|
|
1604
|
+
current = { x: position.x, y: position.y, z: position.z };
|
|
1605
|
+
if (Math.hypot(current.x - previous.x, current.y - previous.y, current.z - previous.z) > teleportDistance) previous = current;
|
|
1606
|
+
},
|
|
1607
|
+
reset(position) {
|
|
1608
|
+
previous = { x: position.x, y: position.y, z: position.z };
|
|
1609
|
+
current = previous;
|
|
1610
|
+
},
|
|
1611
|
+
blend(alpha) {
|
|
1612
|
+
const k = Math.min(1, Math.max(0, alpha));
|
|
1613
|
+
return { x: previous.x + (current.x - previous.x) * k, y: previous.y + (current.y - previous.y) * k, z: previous.z + (current.z - previous.z) * k };
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1592
1617
|
return __toCommonJS(index_exports);
|
|
1593
1618
|
})();
|
|
1594
1619
|
//# sourceMappingURL=index.global.js.map
|