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
|
@@ -3055,6 +3055,7 @@ var EngineHost = class {
|
|
|
3055
3055
|
this.game = game;
|
|
3056
3056
|
this.client = client;
|
|
3057
3057
|
this.started = false;
|
|
3058
|
+
this.paused_ = false;
|
|
3058
3059
|
this.commands = new CommandRegistry();
|
|
3059
3060
|
this.cvars = new CvarRegistry();
|
|
3060
3061
|
this.stepSimulation = (step) => {
|
|
@@ -3093,6 +3094,7 @@ var EngineHost = class {
|
|
|
3093
3094
|
throw error;
|
|
3094
3095
|
}
|
|
3095
3096
|
this.started = true;
|
|
3097
|
+
this.paused_ = false;
|
|
3096
3098
|
this.loop.start();
|
|
3097
3099
|
}
|
|
3098
3100
|
stop() {
|
|
@@ -3103,6 +3105,18 @@ var EngineHost = class {
|
|
|
3103
3105
|
this.previousFrame = void 0;
|
|
3104
3106
|
this.latestFrame = void 0;
|
|
3105
3107
|
this.started = false;
|
|
3108
|
+
this.paused_ = false;
|
|
3109
|
+
}
|
|
3110
|
+
setPaused(paused) {
|
|
3111
|
+
this.paused_ = paused;
|
|
3112
|
+
if (paused) {
|
|
3113
|
+
this.loop.stop();
|
|
3114
|
+
} else if (this.started) {
|
|
3115
|
+
this.loop.start();
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
get paused() {
|
|
3119
|
+
return this.paused_;
|
|
3106
3120
|
}
|
|
3107
3121
|
pump(elapsedMs) {
|
|
3108
3122
|
this.loop.pump(elapsedMs);
|
|
@@ -9902,6 +9916,9 @@ function axisComponent(vec, axis) {
|
|
|
9902
9916
|
function degToRad(degrees) {
|
|
9903
9917
|
return degrees * DEG2RAD_FACTOR2;
|
|
9904
9918
|
}
|
|
9919
|
+
function radToDeg(radians) {
|
|
9920
|
+
return radians * RAD2DEG_FACTOR2;
|
|
9921
|
+
}
|
|
9905
9922
|
function angleMod(angle2) {
|
|
9906
9923
|
const value = angle2 % 360;
|
|
9907
9924
|
return value < 0 ? 360 + value : value;
|
|
@@ -9933,6 +9950,31 @@ function angleVectors(angles) {
|
|
|
9933
9950
|
};
|
|
9934
9951
|
return { forward, right, up };
|
|
9935
9952
|
}
|
|
9953
|
+
function vectorToAngles(vec) {
|
|
9954
|
+
const x = vec.x;
|
|
9955
|
+
const y = vec.y;
|
|
9956
|
+
const z = vec.z;
|
|
9957
|
+
if (y === 0 && x === 0) {
|
|
9958
|
+
return { x: z > 0 ? -90 : -270, y: 0, z: 0 };
|
|
9959
|
+
}
|
|
9960
|
+
let yaw;
|
|
9961
|
+
if (x) {
|
|
9962
|
+
yaw = radToDeg(Math.atan2(y, x));
|
|
9963
|
+
} else if (y > 0) {
|
|
9964
|
+
yaw = 90;
|
|
9965
|
+
} else {
|
|
9966
|
+
yaw = 270;
|
|
9967
|
+
}
|
|
9968
|
+
if (yaw < 0) {
|
|
9969
|
+
yaw += 360;
|
|
9970
|
+
}
|
|
9971
|
+
const forward = Math.sqrt(x * x + y * y);
|
|
9972
|
+
let pitch = radToDeg(Math.atan2(z, forward));
|
|
9973
|
+
if (pitch < 0) {
|
|
9974
|
+
pitch += 360;
|
|
9975
|
+
}
|
|
9976
|
+
return { x: -pitch, y: yaw, z: 0 };
|
|
9977
|
+
}
|
|
9936
9978
|
var ANORMS2 = [
|
|
9937
9979
|
[-0.525731, 0, 0.850651],
|
|
9938
9980
|
[-0.442863, 0.238856, 0.864188],
|
|
@@ -14532,6 +14574,22 @@ var InputController = class {
|
|
|
14532
14574
|
setTouchState(state) {
|
|
14533
14575
|
this.pendingTouchState = state;
|
|
14534
14576
|
}
|
|
14577
|
+
bindInputSource(source) {
|
|
14578
|
+
source.on("keydown", (code) => this.handleKeyDown(code));
|
|
14579
|
+
source.on("keyup", (code) => this.handleKeyUp(code));
|
|
14580
|
+
source.on("mousedown", (button) => this.handleMouseButtonDown(button));
|
|
14581
|
+
source.on("mouseup", (button) => this.handleMouseButtonUp(button));
|
|
14582
|
+
source.on("mousemove", (dx, dy) => this.handleMouseMove(dx, dy));
|
|
14583
|
+
}
|
|
14584
|
+
setKeyBinding(action, keys) {
|
|
14585
|
+
const normalizedAction = normalizeCommand(action);
|
|
14586
|
+
for (const key of keys) {
|
|
14587
|
+
this.bindings.bind(normalizeInputCode(key), normalizedAction);
|
|
14588
|
+
}
|
|
14589
|
+
}
|
|
14590
|
+
getDefaultBindings() {
|
|
14591
|
+
return this.bindings;
|
|
14592
|
+
}
|
|
14535
14593
|
buildCommand(frameMsec, now = nowMs(), serverFrame) {
|
|
14536
14594
|
this.pollGamepads(now);
|
|
14537
14595
|
this.applyTouchState(now);
|
|
@@ -14615,7 +14673,7 @@ var InputController = class {
|
|
|
14615
14673
|
}
|
|
14616
14674
|
this.anyPressed = false;
|
|
14617
14675
|
this.sequence++;
|
|
14618
|
-
|
|
14676
|
+
const command = {
|
|
14619
14677
|
msec,
|
|
14620
14678
|
buttons,
|
|
14621
14679
|
angles: { ...this.viewAngles },
|
|
@@ -14627,6 +14685,10 @@ var InputController = class {
|
|
|
14627
14685
|
lightlevel: 0,
|
|
14628
14686
|
impulse: 0
|
|
14629
14687
|
};
|
|
14688
|
+
if (this.onInputCommand) {
|
|
14689
|
+
this.onInputCommand(command);
|
|
14690
|
+
}
|
|
14691
|
+
return command;
|
|
14630
14692
|
}
|
|
14631
14693
|
consumeConsoleCommands() {
|
|
14632
14694
|
const commands = this.commandQueue;
|
|
@@ -14818,6 +14880,7 @@ var GameSession = class {
|
|
|
14818
14880
|
this.client = null;
|
|
14819
14881
|
this.game = null;
|
|
14820
14882
|
this.host = null;
|
|
14883
|
+
this.currentMapName = "";
|
|
14821
14884
|
this.options = options;
|
|
14822
14885
|
this.engine = options.engine;
|
|
14823
14886
|
}
|
|
@@ -14825,6 +14888,7 @@ var GameSession = class {
|
|
|
14825
14888
|
if (this.host) {
|
|
14826
14889
|
this.shutdown();
|
|
14827
14890
|
}
|
|
14891
|
+
this.currentMapName = mapName;
|
|
14828
14892
|
const gameOptions = {
|
|
14829
14893
|
gravity: { x: 0, y: 0, z: -800 },
|
|
14830
14894
|
// Default gravity
|
|
@@ -14925,6 +14989,7 @@ var GameSession = class {
|
|
|
14925
14989
|
this.shutdown();
|
|
14926
14990
|
}
|
|
14927
14991
|
const mapName = saveData.map;
|
|
14992
|
+
this.currentMapName = mapName;
|
|
14928
14993
|
const skill = saveData.difficulty;
|
|
14929
14994
|
const gameOptions = {
|
|
14930
14995
|
gravity: { x: 0, y: 0, z: -800 },
|
|
@@ -15037,6 +15102,47 @@ var GameSession = class {
|
|
|
15037
15102
|
getHost() {
|
|
15038
15103
|
return this.host;
|
|
15039
15104
|
}
|
|
15105
|
+
// Section 4.1.3: Game State Queries
|
|
15106
|
+
getPlayerState() {
|
|
15107
|
+
if (this.client && this.client.lastRendered) {
|
|
15108
|
+
return this.client.lastRendered;
|
|
15109
|
+
}
|
|
15110
|
+
return null;
|
|
15111
|
+
}
|
|
15112
|
+
getGameTime() {
|
|
15113
|
+
if (this.game) {
|
|
15114
|
+
return this.game.time;
|
|
15115
|
+
}
|
|
15116
|
+
if (this.client && this.client.lastRendered) {
|
|
15117
|
+
return 0;
|
|
15118
|
+
}
|
|
15119
|
+
return 0;
|
|
15120
|
+
}
|
|
15121
|
+
isPaused() {
|
|
15122
|
+
if (this.host) {
|
|
15123
|
+
return this.host.paused;
|
|
15124
|
+
}
|
|
15125
|
+
return false;
|
|
15126
|
+
}
|
|
15127
|
+
getSkillLevel() {
|
|
15128
|
+
if (this.game) {
|
|
15129
|
+
return this.game.skill;
|
|
15130
|
+
}
|
|
15131
|
+
return this.options.skill ?? 1;
|
|
15132
|
+
}
|
|
15133
|
+
getMapName() {
|
|
15134
|
+
if (this.game && this.game.entities && this.game.entities.level && this.game.entities.level.mapname) {
|
|
15135
|
+
return this.game.entities.level.mapname;
|
|
15136
|
+
}
|
|
15137
|
+
return this.currentMapName;
|
|
15138
|
+
}
|
|
15139
|
+
getGameMode() {
|
|
15140
|
+
if (this.game) {
|
|
15141
|
+
if (this.game.deathmatch) return "deathmatch";
|
|
15142
|
+
if (this.game.coop) return "coop";
|
|
15143
|
+
}
|
|
15144
|
+
return "single";
|
|
15145
|
+
}
|
|
15040
15146
|
};
|
|
15041
15147
|
function createSession(options) {
|
|
15042
15148
|
return new GameSession(options);
|
|
@@ -15641,6 +15747,12 @@ function createClient(imports) {
|
|
|
15641
15747
|
const timeMs = sample.latest?.timeMs ?? 0;
|
|
15642
15748
|
this.DrawHUD(stats, timeMs);
|
|
15643
15749
|
}
|
|
15750
|
+
if (clientExports.onHudUpdate) {
|
|
15751
|
+
const hudData = clientExports.getHudData();
|
|
15752
|
+
if (hudData) {
|
|
15753
|
+
clientExports.onHudUpdate(hudData);
|
|
15754
|
+
}
|
|
15755
|
+
}
|
|
15644
15756
|
return command;
|
|
15645
15757
|
},
|
|
15646
15758
|
DrawHUD(stats, timeMs) {
|
|
@@ -15714,6 +15826,42 @@ function createClient(imports) {
|
|
|
15714
15826
|
errorDialog.render(imports.engine.renderer);
|
|
15715
15827
|
loadingScreen.render(imports.engine.renderer);
|
|
15716
15828
|
},
|
|
15829
|
+
getHudData() {
|
|
15830
|
+
if (!lastRendered) return null;
|
|
15831
|
+
const health = lastRendered.health ?? 0;
|
|
15832
|
+
const armor = lastRendered.armor ?? 0;
|
|
15833
|
+
const ammo = lastRendered.ammo ?? 0;
|
|
15834
|
+
const fps = 60;
|
|
15835
|
+
const damageIndicators = (lastRendered.damageIndicators ?? []).map((ind) => ({
|
|
15836
|
+
angle: vectorToAngles(ind.direction).y,
|
|
15837
|
+
alpha: ind.strength
|
|
15838
|
+
}));
|
|
15839
|
+
return {
|
|
15840
|
+
health,
|
|
15841
|
+
armor,
|
|
15842
|
+
ammo,
|
|
15843
|
+
inventory: [],
|
|
15844
|
+
// Todo
|
|
15845
|
+
damageIndicators,
|
|
15846
|
+
fps,
|
|
15847
|
+
pickupIcon: lastRendered.pickupIcon
|
|
15848
|
+
};
|
|
15849
|
+
},
|
|
15850
|
+
getStatusBar() {
|
|
15851
|
+
if (!lastRendered) return null;
|
|
15852
|
+
return {
|
|
15853
|
+
health: lastRendered.health ?? 0,
|
|
15854
|
+
armor: lastRendered.armor ?? 0,
|
|
15855
|
+
ammo: lastRendered.ammo ?? 0,
|
|
15856
|
+
selectedAmmoIndex: 0
|
|
15857
|
+
};
|
|
15858
|
+
},
|
|
15859
|
+
getCrosshairInfo() {
|
|
15860
|
+
return {
|
|
15861
|
+
index: 0,
|
|
15862
|
+
name: "default"
|
|
15863
|
+
};
|
|
15864
|
+
},
|
|
15717
15865
|
shutdown() {
|
|
15718
15866
|
this.Shutdown();
|
|
15719
15867
|
},
|