quake2ts 0.0.465 → 0.0.466
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/package.json +1 -1
- package/packages/client/dist/browser/index.global.js +14 -14
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs +149 -1
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +149 -1
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/client/dist/types/hud/data.d.ts +31 -0
- package/packages/client/dist/types/hud/data.d.ts.map +1 -0
- package/packages/client/dist/types/index.d.ts +5 -0
- package/packages/client/dist/types/index.d.ts.map +1 -1
- package/packages/client/dist/types/input/bindings.d.ts +1 -0
- package/packages/client/dist/types/input/bindings.d.ts.map +1 -1
- package/packages/client/dist/types/input/controller.d.ts +11 -0
- package/packages/client/dist/types/input/controller.d.ts.map +1 -1
- package/packages/client/dist/types/session.d.ts +8 -0
- package/packages/client/dist/types/session.d.ts.map +1 -1
- package/packages/engine/dist/browser/index.global.js +1 -1
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +14 -0
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +14 -0
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/types/host.d.ts +3 -0
- package/packages/engine/dist/types/host.d.ts.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -3090,6 +3090,7 @@ var EngineHost = class {
|
|
|
3090
3090
|
this.game = game;
|
|
3091
3091
|
this.client = client;
|
|
3092
3092
|
this.started = false;
|
|
3093
|
+
this.paused_ = false;
|
|
3093
3094
|
this.commands = new CommandRegistry();
|
|
3094
3095
|
this.cvars = new CvarRegistry();
|
|
3095
3096
|
this.stepSimulation = (step) => {
|
|
@@ -3128,6 +3129,7 @@ var EngineHost = class {
|
|
|
3128
3129
|
throw error;
|
|
3129
3130
|
}
|
|
3130
3131
|
this.started = true;
|
|
3132
|
+
this.paused_ = false;
|
|
3131
3133
|
this.loop.start();
|
|
3132
3134
|
}
|
|
3133
3135
|
stop() {
|
|
@@ -3138,6 +3140,18 @@ var EngineHost = class {
|
|
|
3138
3140
|
this.previousFrame = void 0;
|
|
3139
3141
|
this.latestFrame = void 0;
|
|
3140
3142
|
this.started = false;
|
|
3143
|
+
this.paused_ = false;
|
|
3144
|
+
}
|
|
3145
|
+
setPaused(paused) {
|
|
3146
|
+
this.paused_ = paused;
|
|
3147
|
+
if (paused) {
|
|
3148
|
+
this.loop.stop();
|
|
3149
|
+
} else if (this.started) {
|
|
3150
|
+
this.loop.start();
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
get paused() {
|
|
3154
|
+
return this.paused_;
|
|
3141
3155
|
}
|
|
3142
3156
|
pump(elapsedMs) {
|
|
3143
3157
|
this.loop.pump(elapsedMs);
|
|
@@ -9937,6 +9951,9 @@ function axisComponent(vec, axis) {
|
|
|
9937
9951
|
function degToRad(degrees) {
|
|
9938
9952
|
return degrees * DEG2RAD_FACTOR2;
|
|
9939
9953
|
}
|
|
9954
|
+
function radToDeg(radians) {
|
|
9955
|
+
return radians * RAD2DEG_FACTOR2;
|
|
9956
|
+
}
|
|
9940
9957
|
function angleMod(angle2) {
|
|
9941
9958
|
const value = angle2 % 360;
|
|
9942
9959
|
return value < 0 ? 360 + value : value;
|
|
@@ -9968,6 +9985,31 @@ function angleVectors(angles) {
|
|
|
9968
9985
|
};
|
|
9969
9986
|
return { forward, right, up };
|
|
9970
9987
|
}
|
|
9988
|
+
function vectorToAngles(vec) {
|
|
9989
|
+
const x = vec.x;
|
|
9990
|
+
const y = vec.y;
|
|
9991
|
+
const z = vec.z;
|
|
9992
|
+
if (y === 0 && x === 0) {
|
|
9993
|
+
return { x: z > 0 ? -90 : -270, y: 0, z: 0 };
|
|
9994
|
+
}
|
|
9995
|
+
let yaw;
|
|
9996
|
+
if (x) {
|
|
9997
|
+
yaw = radToDeg(Math.atan2(y, x));
|
|
9998
|
+
} else if (y > 0) {
|
|
9999
|
+
yaw = 90;
|
|
10000
|
+
} else {
|
|
10001
|
+
yaw = 270;
|
|
10002
|
+
}
|
|
10003
|
+
if (yaw < 0) {
|
|
10004
|
+
yaw += 360;
|
|
10005
|
+
}
|
|
10006
|
+
const forward = Math.sqrt(x * x + y * y);
|
|
10007
|
+
let pitch = radToDeg(Math.atan2(z, forward));
|
|
10008
|
+
if (pitch < 0) {
|
|
10009
|
+
pitch += 360;
|
|
10010
|
+
}
|
|
10011
|
+
return { x: -pitch, y: yaw, z: 0 };
|
|
10012
|
+
}
|
|
9971
10013
|
var ANORMS2 = [
|
|
9972
10014
|
[-0.525731, 0, 0.850651],
|
|
9973
10015
|
[-0.442863, 0.238856, 0.864188],
|
|
@@ -14567,6 +14609,22 @@ var InputController = class {
|
|
|
14567
14609
|
setTouchState(state) {
|
|
14568
14610
|
this.pendingTouchState = state;
|
|
14569
14611
|
}
|
|
14612
|
+
bindInputSource(source) {
|
|
14613
|
+
source.on("keydown", (code) => this.handleKeyDown(code));
|
|
14614
|
+
source.on("keyup", (code) => this.handleKeyUp(code));
|
|
14615
|
+
source.on("mousedown", (button) => this.handleMouseButtonDown(button));
|
|
14616
|
+
source.on("mouseup", (button) => this.handleMouseButtonUp(button));
|
|
14617
|
+
source.on("mousemove", (dx, dy) => this.handleMouseMove(dx, dy));
|
|
14618
|
+
}
|
|
14619
|
+
setKeyBinding(action, keys) {
|
|
14620
|
+
const normalizedAction = normalizeCommand(action);
|
|
14621
|
+
for (const key of keys) {
|
|
14622
|
+
this.bindings.bind(normalizeInputCode(key), normalizedAction);
|
|
14623
|
+
}
|
|
14624
|
+
}
|
|
14625
|
+
getDefaultBindings() {
|
|
14626
|
+
return this.bindings;
|
|
14627
|
+
}
|
|
14570
14628
|
buildCommand(frameMsec, now = nowMs(), serverFrame) {
|
|
14571
14629
|
this.pollGamepads(now);
|
|
14572
14630
|
this.applyTouchState(now);
|
|
@@ -14650,7 +14708,7 @@ var InputController = class {
|
|
|
14650
14708
|
}
|
|
14651
14709
|
this.anyPressed = false;
|
|
14652
14710
|
this.sequence++;
|
|
14653
|
-
|
|
14711
|
+
const command = {
|
|
14654
14712
|
msec,
|
|
14655
14713
|
buttons,
|
|
14656
14714
|
angles: { ...this.viewAngles },
|
|
@@ -14662,6 +14720,10 @@ var InputController = class {
|
|
|
14662
14720
|
lightlevel: 0,
|
|
14663
14721
|
impulse: 0
|
|
14664
14722
|
};
|
|
14723
|
+
if (this.onInputCommand) {
|
|
14724
|
+
this.onInputCommand(command);
|
|
14725
|
+
}
|
|
14726
|
+
return command;
|
|
14665
14727
|
}
|
|
14666
14728
|
consumeConsoleCommands() {
|
|
14667
14729
|
const commands = this.commandQueue;
|
|
@@ -14850,6 +14912,7 @@ var GameSession = class {
|
|
|
14850
14912
|
this.client = null;
|
|
14851
14913
|
this.game = null;
|
|
14852
14914
|
this.host = null;
|
|
14915
|
+
this.currentMapName = "";
|
|
14853
14916
|
this.options = options;
|
|
14854
14917
|
this.engine = options.engine;
|
|
14855
14918
|
}
|
|
@@ -14857,6 +14920,7 @@ var GameSession = class {
|
|
|
14857
14920
|
if (this.host) {
|
|
14858
14921
|
this.shutdown();
|
|
14859
14922
|
}
|
|
14923
|
+
this.currentMapName = mapName;
|
|
14860
14924
|
const gameOptions = {
|
|
14861
14925
|
gravity: { x: 0, y: 0, z: -800 },
|
|
14862
14926
|
// Default gravity
|
|
@@ -14957,6 +15021,7 @@ var GameSession = class {
|
|
|
14957
15021
|
this.shutdown();
|
|
14958
15022
|
}
|
|
14959
15023
|
const mapName = saveData.map;
|
|
15024
|
+
this.currentMapName = mapName;
|
|
14960
15025
|
const skill = saveData.difficulty;
|
|
14961
15026
|
const gameOptions = {
|
|
14962
15027
|
gravity: { x: 0, y: 0, z: -800 },
|
|
@@ -15069,6 +15134,47 @@ var GameSession = class {
|
|
|
15069
15134
|
getHost() {
|
|
15070
15135
|
return this.host;
|
|
15071
15136
|
}
|
|
15137
|
+
// Section 4.1.3: Game State Queries
|
|
15138
|
+
getPlayerState() {
|
|
15139
|
+
if (this.client && this.client.lastRendered) {
|
|
15140
|
+
return this.client.lastRendered;
|
|
15141
|
+
}
|
|
15142
|
+
return null;
|
|
15143
|
+
}
|
|
15144
|
+
getGameTime() {
|
|
15145
|
+
if (this.game) {
|
|
15146
|
+
return this.game.time;
|
|
15147
|
+
}
|
|
15148
|
+
if (this.client && this.client.lastRendered) {
|
|
15149
|
+
return 0;
|
|
15150
|
+
}
|
|
15151
|
+
return 0;
|
|
15152
|
+
}
|
|
15153
|
+
isPaused() {
|
|
15154
|
+
if (this.host) {
|
|
15155
|
+
return this.host.paused;
|
|
15156
|
+
}
|
|
15157
|
+
return false;
|
|
15158
|
+
}
|
|
15159
|
+
getSkillLevel() {
|
|
15160
|
+
if (this.game) {
|
|
15161
|
+
return this.game.skill;
|
|
15162
|
+
}
|
|
15163
|
+
return this.options.skill ?? 1;
|
|
15164
|
+
}
|
|
15165
|
+
getMapName() {
|
|
15166
|
+
if (this.game && this.game.entities && this.game.entities.level && this.game.entities.level.mapname) {
|
|
15167
|
+
return this.game.entities.level.mapname;
|
|
15168
|
+
}
|
|
15169
|
+
return this.currentMapName;
|
|
15170
|
+
}
|
|
15171
|
+
getGameMode() {
|
|
15172
|
+
if (this.game) {
|
|
15173
|
+
if (this.game.deathmatch) return "deathmatch";
|
|
15174
|
+
if (this.game.coop) return "coop";
|
|
15175
|
+
}
|
|
15176
|
+
return "single";
|
|
15177
|
+
}
|
|
15072
15178
|
};
|
|
15073
15179
|
function createSession(options) {
|
|
15074
15180
|
return new GameSession(options);
|
|
@@ -15673,6 +15779,12 @@ function createClient(imports) {
|
|
|
15673
15779
|
const timeMs = sample.latest?.timeMs ?? 0;
|
|
15674
15780
|
this.DrawHUD(stats, timeMs);
|
|
15675
15781
|
}
|
|
15782
|
+
if (clientExports.onHudUpdate) {
|
|
15783
|
+
const hudData = clientExports.getHudData();
|
|
15784
|
+
if (hudData) {
|
|
15785
|
+
clientExports.onHudUpdate(hudData);
|
|
15786
|
+
}
|
|
15787
|
+
}
|
|
15676
15788
|
return command;
|
|
15677
15789
|
},
|
|
15678
15790
|
DrawHUD(stats, timeMs) {
|
|
@@ -15746,6 +15858,42 @@ function createClient(imports) {
|
|
|
15746
15858
|
errorDialog.render(imports.engine.renderer);
|
|
15747
15859
|
loadingScreen.render(imports.engine.renderer);
|
|
15748
15860
|
},
|
|
15861
|
+
getHudData() {
|
|
15862
|
+
if (!lastRendered) return null;
|
|
15863
|
+
const health = lastRendered.health ?? 0;
|
|
15864
|
+
const armor = lastRendered.armor ?? 0;
|
|
15865
|
+
const ammo = lastRendered.ammo ?? 0;
|
|
15866
|
+
const fps = 60;
|
|
15867
|
+
const damageIndicators = (lastRendered.damageIndicators ?? []).map((ind) => ({
|
|
15868
|
+
angle: vectorToAngles(ind.direction).y,
|
|
15869
|
+
alpha: ind.strength
|
|
15870
|
+
}));
|
|
15871
|
+
return {
|
|
15872
|
+
health,
|
|
15873
|
+
armor,
|
|
15874
|
+
ammo,
|
|
15875
|
+
inventory: [],
|
|
15876
|
+
// Todo
|
|
15877
|
+
damageIndicators,
|
|
15878
|
+
fps,
|
|
15879
|
+
pickupIcon: lastRendered.pickupIcon
|
|
15880
|
+
};
|
|
15881
|
+
},
|
|
15882
|
+
getStatusBar() {
|
|
15883
|
+
if (!lastRendered) return null;
|
|
15884
|
+
return {
|
|
15885
|
+
health: lastRendered.health ?? 0,
|
|
15886
|
+
armor: lastRendered.armor ?? 0,
|
|
15887
|
+
ammo: lastRendered.ammo ?? 0,
|
|
15888
|
+
selectedAmmoIndex: 0
|
|
15889
|
+
};
|
|
15890
|
+
},
|
|
15891
|
+
getCrosshairInfo() {
|
|
15892
|
+
return {
|
|
15893
|
+
index: 0,
|
|
15894
|
+
name: "default"
|
|
15895
|
+
};
|
|
15896
|
+
},
|
|
15749
15897
|
shutdown() {
|
|
15750
15898
|
this.Shutdown();
|
|
15751
15899
|
},
|