@adatechnology/game-test-room 0.22.0 → 0.24.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.d.ts +7 -0
- package/dist/index.global.js +350 -179
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +33 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/room.ts
|
|
2
2
|
import { createDestruction, JOINT_DEFAULTS, resolveStrings as resolveDestructionStrings } from "@adatechnology/game-destruction";
|
|
3
|
-
import { createAudioEngine, createAudioSink, loadKitSamples } from "@adatechnology/game-audio";
|
|
3
|
+
import { createAudioEngine, createAudioSink, loadKitSamples, loadUserSamples } from "@adatechnology/game-audio";
|
|
4
4
|
import { createDestructionRenderer, createDestructionSound, dragSoundKey, impactKey, impactSoundKeys, specFromObject3D } from "@adatechnology/game-destruction-three";
|
|
5
5
|
import { bodyMass, KNOCK_CHEST, knockOf, surfaceOfMaterial } from "@adatechnology/game-contracts";
|
|
6
6
|
|
|
@@ -2147,6 +2147,7 @@ var LOOK = 22e-4;
|
|
|
2147
2147
|
var LYING_EYE = 0.3;
|
|
2148
2148
|
var LYING_PITCH = 1.05;
|
|
2149
2149
|
var LYING_ROLL = 0.35;
|
|
2150
|
+
var LYING_PITCH_FACE_DOWN = -1.05;
|
|
2150
2151
|
function createPlayer(THREE, o) {
|
|
2151
2152
|
const cam = o.camera;
|
|
2152
2153
|
let yaw = 0;
|
|
@@ -2185,11 +2186,12 @@ function createPlayer(THREE, o) {
|
|
|
2185
2186
|
floorLevel += Math.max(-reach, Math.min(reach, gap));
|
|
2186
2187
|
};
|
|
2187
2188
|
let knocked = null;
|
|
2189
|
+
let knockedForward = false;
|
|
2188
2190
|
let rollSide = 1;
|
|
2189
2191
|
const apply = () => {
|
|
2190
2192
|
const lying = knocked?.lying ?? 0;
|
|
2191
2193
|
const fallen = lying * lying * (3 - 2 * lying);
|
|
2192
|
-
euler.set(pitch + (LYING_PITCH - pitch) * fallen, yaw, LYING_ROLL * rollSide * fallen, "YXZ");
|
|
2194
|
+
euler.set(pitch + ((knockedForward ? LYING_PITCH_FACE_DOWN : LYING_PITCH) - pitch) * fallen, yaw, LYING_ROLL * rollSide * fallen, "YXZ");
|
|
2193
2195
|
cam.quaternion.setFromEuler(euler);
|
|
2194
2196
|
const standing = eye - CROUCH_DROP * crouch - bend;
|
|
2195
2197
|
cam.position.set(px.x, floorLevel + y + standing + (LYING_EYE - standing) * fallen, px.z);
|
|
@@ -2467,6 +2469,7 @@ function createPlayer(THREE, o) {
|
|
|
2467
2469
|
if (next.down) {
|
|
2468
2470
|
const right = Math.cos(yaw) * next.velocity[0] - Math.sin(yaw) * next.velocity[2];
|
|
2469
2471
|
rollSide = right >= 0 ? -1 : 1;
|
|
2472
|
+
knockedForward = -Math.sin(yaw) * next.velocity[0] - Math.cos(yaw) * next.velocity[2] > 0;
|
|
2470
2473
|
crouchLatched = false;
|
|
2471
2474
|
}
|
|
2472
2475
|
if (knocked.airborne) vy = Math.max(vy, knocked.velocity[1]);
|
|
@@ -2474,6 +2477,9 @@ function createPlayer(THREE, o) {
|
|
|
2474
2477
|
get knocked() {
|
|
2475
2478
|
return knocked;
|
|
2476
2479
|
},
|
|
2480
|
+
get knockedForward() {
|
|
2481
|
+
return knockedForward;
|
|
2482
|
+
},
|
|
2477
2483
|
update(dt) {
|
|
2478
2484
|
if (knocked) {
|
|
2479
2485
|
stepKnocked(dt);
|
|
@@ -5372,7 +5378,11 @@ function createTestRoom(options) {
|
|
|
5372
5378
|
const audio = options.audio === false ? null : options.audio ?? createAudioEngine({ deferredStart: {} });
|
|
5373
5379
|
const destructionSound = audio ? createDestructionSound(audio) : null;
|
|
5374
5380
|
if (audio && options.samplesBaseUrl !== null) {
|
|
5375
|
-
void loadKitSamples(audio, { baseUrl: options.samplesBaseUrl ?? "./sfx/" }).then((bank) => {
|
|
5381
|
+
void loadKitSamples(audio, { baseUrl: options.samplesBaseUrl ?? "./sfx/" }).then(async (bank) => {
|
|
5382
|
+
if (options.userSamplesBaseUrl !== null) {
|
|
5383
|
+
const own = await loadUserSamples(audio, { baseUrl: options.userSamplesBaseUrl ?? "./sfx-local/" });
|
|
5384
|
+
if (own) log.add({ channel: "event", type: "user_sounds", text: `sons do dono: ${own.playing.length} tocando, ${own.behindKit.length} atr\xE1s do SDK`, data: { playing: own.playing, behindKit: own.behindKit } });
|
|
5385
|
+
}
|
|
5376
5386
|
if (!bank || typeof window === "undefined") return;
|
|
5377
5387
|
const preload = () => {
|
|
5378
5388
|
window.removeEventListener("keydown", preload, true);
|
|
@@ -6194,6 +6204,7 @@ function createTestRoom(options) {
|
|
|
6194
6204
|
explosives.clear();
|
|
6195
6205
|
fireZones.length = 0;
|
|
6196
6206
|
burningStains.length = 0;
|
|
6207
|
+
destructionSound?.reset();
|
|
6197
6208
|
terrain.setLayout(defaultGround);
|
|
6198
6209
|
for (const id of [...entries.keys()]) if (!entries.get(id)?.arena) removeEntry(id);
|
|
6199
6210
|
clearLoose();
|
|
@@ -6361,6 +6372,7 @@ function createTestRoom(options) {
|
|
|
6361
6372
|
avatarState.running = !player.crouching && (player.keys.has("ShiftLeft") || player.keys.has("ShiftRight"));
|
|
6362
6373
|
avatarState.crouch = crouchForced || player.crouching || push.isBent;
|
|
6363
6374
|
avatarState.down = downForced || Boolean(player.knocked?.down || (player.knocked?.lying ?? 0) > 0.5);
|
|
6375
|
+
avatarState.fallForward = downForced ? void 0 : player.knockedForward;
|
|
6364
6376
|
avatarState.armed = armedForced ?? tool.def.action.kind === "firearm";
|
|
6365
6377
|
avatarState.pitch = player.pitch;
|
|
6366
6378
|
avatarState.holding = heldPiece !== null;
|
|
@@ -6560,6 +6572,15 @@ function createTestRoom(options) {
|
|
|
6560
6572
|
};
|
|
6561
6573
|
const fireZones = [];
|
|
6562
6574
|
const burningStains = [];
|
|
6575
|
+
const poolFire = (point, burning) => playSound(burning ? "burn_loop" : "burn_end", point, 0.5, { fuel: "liquid" });
|
|
6576
|
+
const dropZone = (i) => {
|
|
6577
|
+
const [zone] = fireZones.splice(i, 1);
|
|
6578
|
+
if (zone) poolFire(zone.point, false);
|
|
6579
|
+
};
|
|
6580
|
+
const dropStain = (i) => {
|
|
6581
|
+
const [stain] = burningStains.splice(i, 1);
|
|
6582
|
+
if (stain) poolFire(stain.center, false);
|
|
6583
|
+
};
|
|
6563
6584
|
const stainRadius = (s) => {
|
|
6564
6585
|
let sum = 0;
|
|
6565
6586
|
for (const r of s.front) sum += r;
|
|
@@ -6576,6 +6597,7 @@ function createTestRoom(options) {
|
|
|
6576
6597
|
if (stainBurning(s)) continue;
|
|
6577
6598
|
const seconds = Math.max(3, Math.min(20, 4 + s.liters * 30 + stainRadius(s) * 6));
|
|
6578
6599
|
burningStains.push({ center: [s.center[0], s.center[1], s.center[2]], remaining: seconds, acc: 0 });
|
|
6600
|
+
poolFire([s.center[0], s.center[1], s.center[2]], true);
|
|
6579
6601
|
lit = true;
|
|
6580
6602
|
log.add({
|
|
6581
6603
|
channel: "event",
|
|
@@ -6606,7 +6628,7 @@ function createTestRoom(options) {
|
|
|
6606
6628
|
const a = rnd() * Math.PI * 2;
|
|
6607
6629
|
const r = Math.sqrt(rnd()) * z.radius;
|
|
6608
6630
|
renderer.emit("fire", [z.point[0] + Math.cos(a) * r, z.point[1] + 0.05, z.point[2] + Math.sin(a) * r], [0, 1, 0], 2, 1.5);
|
|
6609
|
-
if (z.remaining <= 0)
|
|
6631
|
+
if (z.remaining <= 0) dropZone(i);
|
|
6610
6632
|
}
|
|
6611
6633
|
if (burningStains.length) {
|
|
6612
6634
|
const stains = fluids.stains();
|
|
@@ -6627,7 +6649,7 @@ function createTestRoom(options) {
|
|
|
6627
6649
|
if (b.remaining <= 0 || !st) {
|
|
6628
6650
|
fluids.clearStains(b.center, r + 0.1);
|
|
6629
6651
|
log.add({ channel: "event", type: "stain_burned", text: t("ev.stain_burned"), data: { point: b.center } });
|
|
6630
|
-
|
|
6652
|
+
dropStain(i);
|
|
6631
6653
|
}
|
|
6632
6654
|
}
|
|
6633
6655
|
}
|
|
@@ -6964,8 +6986,8 @@ function createTestRoom(options) {
|
|
|
6964
6986
|
hit.add(r.object);
|
|
6965
6987
|
world.extinguish(r.object, void 0, u.coolC * Math.max(u.duration, 0.05) * 6);
|
|
6966
6988
|
fluids.clearStains(r.point, 0.5);
|
|
6967
|
-
for (let i = burningStains.length - 1; i >= 0; i--) if (Math.hypot(burningStains[i].center[0] - r.point[0], burningStains[i].center[2] - r.point[2]) < 1.2)
|
|
6968
|
-
for (let i = fireZones.length - 1; i >= 0; i--) if (Math.hypot(fireZones[i].point[0] - r.point[0], fireZones[i].point[2] - r.point[2]) < 1.5)
|
|
6989
|
+
for (let i = burningStains.length - 1; i >= 0; i--) if (Math.hypot(burningStains[i].center[0] - r.point[0], burningStains[i].center[2] - r.point[2]) < 1.2) dropStain(i);
|
|
6990
|
+
for (let i = fireZones.length - 1; i >= 0; i--) if (Math.hypot(fireZones[i].point[0] - r.point[0], fireZones[i].point[2] - r.point[2]) < 1.5) dropZone(i);
|
|
6969
6991
|
}
|
|
6970
6992
|
});
|
|
6971
6993
|
log.coalesce(
|
|
@@ -6976,7 +6998,9 @@ function createTestRoom(options) {
|
|
|
6976
6998
|
};
|
|
6977
6999
|
const startFire = (weapon, at, fire2, impact) => {
|
|
6978
7000
|
fluids.splash("fuel", [at[0], Math.max(at[1], groundAt(at[0], at[2])), at[2]], 0.5);
|
|
6979
|
-
|
|
7001
|
+
const zone = { point: [at[0], Math.max(0.02, groundAt(at[0], at[2])), at[2]], radius: fire2.radius, temperature: fire2.temperature, remaining: fire2.seconds, acc: 0 };
|
|
7002
|
+
fireZones.push(zone);
|
|
7003
|
+
poolFire(zone.point, true);
|
|
6980
7004
|
renderer.emit("fire", at, [0, 1, 0], 24, 3);
|
|
6981
7005
|
action("molotov_fire", t("act.molotov_fire", { weapon: toolName(weapon), seconds: num(fire2.seconds, 0), radius: num(fire2.radius, 1) }), { data: { weapon, impact } });
|
|
6982
7006
|
};
|
|
@@ -8114,6 +8138,7 @@ function createTestRoom(options) {
|
|
|
8114
8138
|
loading,
|
|
8115
8139
|
addView: (view) => moduleViews.add(view),
|
|
8116
8140
|
setViewCamera: (view) => moduleViews.setMain(view ?? null),
|
|
8141
|
+
holdPlayer: (held) => player.setWalkHeld(held),
|
|
8117
8142
|
...options.blastShove ? { blastShove: options.blastShove } : {},
|
|
8118
8143
|
blastReach: (point, target, ignore) => world.blastReach(point, target, ignore ? { ignore } : {}),
|
|
8119
8144
|
tool: () => ({
|