@jgengine/shell 0.2.0 → 0.3.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/GamePlayerShell.js +34 -11
- package/package.json +4 -4
package/dist/GamePlayerShell.js
CHANGED
|
@@ -2,7 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { Canvas, useFrame, useLoader } from "@react-three/fiber";
|
|
3
3
|
import { Component, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import * as THREE from "three";
|
|
5
|
-
import { createActionStateTracker, toActionStateBindingMap, } from "@jgengine/core/input/actionBindings";
|
|
5
|
+
import { createActionStateTracker, hotbarSlotActionIndex, resolveActionCommand, toActionStateBindingMap, } from "@jgengine/core/input/actionBindings";
|
|
6
|
+
import { resolveActivePrompt } from "@jgengine/core/interaction/proximityPrompt";
|
|
6
7
|
import { advancePlayerMotion, createEmptyMovementKeys, createPlayerMotionState, resolveMovementIntent, } from "@jgengine/core/movement/movementModel";
|
|
7
8
|
import { createGameContext } from "@jgengine/core/runtime/gameContext";
|
|
8
9
|
import { useGameContext } from "@jgengine/react/provider";
|
|
@@ -25,10 +26,24 @@ function logRuntimeError(error, phase) {
|
|
|
25
26
|
console.error(`[jgengine:${phase}] ${diagnostic.message}`, error);
|
|
26
27
|
return diagnostic;
|
|
27
28
|
}
|
|
29
|
+
const RESERVED_INPUT_ACTIONS = new Set([
|
|
30
|
+
"moveForward",
|
|
31
|
+
"moveBack",
|
|
32
|
+
"moveLeft",
|
|
33
|
+
"moveRight",
|
|
34
|
+
"turnLeft",
|
|
35
|
+
"turnRight",
|
|
36
|
+
"sprint",
|
|
37
|
+
"jump",
|
|
38
|
+
"tabTarget",
|
|
39
|
+
"clearTarget",
|
|
40
|
+
"useAbility",
|
|
41
|
+
"interact",
|
|
42
|
+
]);
|
|
28
43
|
function findHotbarSlotActions(input) {
|
|
29
44
|
return Object.keys(input ?? {}).flatMap((action) => {
|
|
30
|
-
const
|
|
31
|
-
return
|
|
45
|
+
const slot = hotbarSlotActionIndex(action);
|
|
46
|
+
return slot === null ? [] : [{ action, slot }];
|
|
32
47
|
});
|
|
33
48
|
}
|
|
34
49
|
function hotbarIdFor(playable) {
|
|
@@ -164,15 +179,23 @@ function FrameDriver({ ctx, playable, tracker, yawRef, primaryClickRef, onRuntim
|
|
|
164
179
|
else
|
|
165
180
|
ctx.scene.entity.setTarget(playerId, null);
|
|
166
181
|
}
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
182
|
+
for (const action of Object.keys(playable.game.input ?? {})) {
|
|
183
|
+
if (!tracker.wasPressed(action))
|
|
184
|
+
continue;
|
|
185
|
+
if (action === "interact") {
|
|
186
|
+
const prompts = playable.prompts?.(ctx);
|
|
187
|
+
const focus = prompts === undefined ? null : ctx.scene.entity.get(playerId);
|
|
188
|
+
if (prompts !== undefined && focus !== null) {
|
|
189
|
+
const active = resolveActivePrompt({ x: focus.position[0], z: focus.position[2] }, prompts);
|
|
190
|
+
if (active !== null && active.prompt.invoke !== null) {
|
|
191
|
+
ctx.game.commands.run(active.prompt.invoke.name, active.prompt.invoke.input);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
continue;
|
|
175
195
|
}
|
|
196
|
+
const command = resolveActionCommand(action, (name) => ctx.game.commands.has(name), RESERVED_INPUT_ACTIONS);
|
|
197
|
+
if (command !== null)
|
|
198
|
+
ctx.game.commands.run(command, {});
|
|
176
199
|
}
|
|
177
200
|
if (hotbarId !== null) {
|
|
178
201
|
for (const { action, slot } of slotActions) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jgengine/shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Game player shell for JGengine: React Three Fiber canvas, orbit camera, input tracking, HUD mounting, GameUiPreview, and a demo game. Consumers supply a GameRegistry.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"test": "bun test src"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@jgengine/core": "^0.
|
|
27
|
-
"@jgengine/react": "^0.
|
|
28
|
-
"@jgengine/ws": "^0.
|
|
26
|
+
"@jgengine/core": "^0.3.0",
|
|
27
|
+
"@jgengine/react": "^0.3.0",
|
|
28
|
+
"@jgengine/ws": "^0.3.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@react-three/drei": "^10.0.0",
|