@quake2ts/test-utils 0.0.825 → 0.0.829

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.cjs CHANGED
@@ -223,6 +223,7 @@ __export(index_exports, {
223
223
  createSaveGameSnapshot: () => createSaveGameSnapshot,
224
224
  createServerSnapshot: () => createServerSnapshot,
225
225
  createSolidTexture: () => createSolidTexture,
226
+ createSpawnRegistry: () => createSpawnRegistry,
226
227
  createSpawnTestContext: () => createSpawnTestContext,
227
228
  createStorageTestScenario: () => createStorageTestScenario,
228
229
  createSurfaceMock: () => createSurfaceMock,
@@ -260,6 +261,7 @@ __export(index_exports, {
260
261
  mockMonsterAttacks: () => mockMonsterAttacks,
261
262
  parseProtocolPlayerState: () => parseProtocolPlayerState,
262
263
  randomVector3: () => randomVector3,
264
+ registerTestSpawn: () => registerTestSpawn,
263
265
  renderAndCapture: () => renderAndCapture,
264
266
  renderAndCaptureWebGL: () => renderAndCaptureWebGL,
265
267
  renderAndCaptureWebGLPlaywright: () => renderAndCaptureWebGLPlaywright,
@@ -292,6 +294,7 @@ __export(index_exports, {
292
294
  simulateServerTick: () => simulateServerTick,
293
295
  simulateSnapshotDelivery: () => simulateSnapshotDelivery,
294
296
  spawnEntity: () => spawnEntity,
297
+ spawnTestEntity: () => spawnTestEntity,
295
298
  stairTrace: () => import_shared3.stairTrace,
296
299
  takeScreenshot: () => takeScreenshot,
297
300
  teardownBrowserEnvironment: () => teardownBrowserEnvironment,
@@ -588,7 +591,8 @@ function createTestBspMap(options = {}) {
588
591
  mins: [-1e3, -1e3, -1e3],
589
592
  maxs: [1e3, 1e3, 1e3],
590
593
  origin: [0, 0, 0],
591
- headNode: 0,
594
+ headNode: -1,
595
+ // -1 points to Leaf 0 (implied, assuming simple map)
592
596
  firstFace: 0,
593
597
  numFaces: faces.length
594
598
  }];
@@ -981,7 +985,10 @@ var createMockGame = (seed = 12345) => {
981
985
  }),
982
986
  damage: import_vitest3.vi.fn((amount) => {
983
987
  hooks.onDamage({}, null, null, amount, 0, 0);
984
- })
988
+ }),
989
+ entities: {
990
+ spawnRegistry
991
+ }
985
992
  };
986
993
  return { game, spawnRegistry };
987
994
  };
@@ -997,7 +1004,10 @@ function createTestContext(options) {
997
1004
  );
998
1005
  const entityList = options?.initialEntities ? [...options.initialEntities] : [];
999
1006
  const hooks = game.hooks;
1000
- let currentSpawnRegistry;
1007
+ let currentSpawnRegistry = spawnRegistry;
1008
+ const findByTargetName = (targetname) => {
1009
+ return entityList.filter((e) => e.targetname === targetname && e.inUse);
1010
+ };
1001
1011
  const entities = {
1002
1012
  spawn: import_vitest3.vi.fn(() => {
1003
1013
  const ent = new import_game2.Entity(entityList.length + 1);
@@ -1052,9 +1062,20 @@ function createTestContext(options) {
1052
1062
  }),
1053
1063
  soundIndex: import_vitest3.vi.fn((sound) => engine.soundIndex(sound)),
1054
1064
  useTargets: import_vitest3.vi.fn((entity, activator) => {
1065
+ if (entity.target) {
1066
+ const targets = findByTargetName(entity.target);
1067
+ for (const t of targets) {
1068
+ t.use?.(t, entity, activator);
1069
+ }
1070
+ }
1071
+ }),
1072
+ findByTargetName: import_vitest3.vi.fn(findByTargetName),
1073
+ pickTarget: import_vitest3.vi.fn((targetname) => {
1074
+ if (!targetname) return null;
1075
+ const matches = findByTargetName(targetname);
1076
+ if (matches.length === 0) return null;
1077
+ return matches[0];
1055
1078
  }),
1056
- findByTargetName: import_vitest3.vi.fn(() => []),
1057
- pickTarget: import_vitest3.vi.fn(() => null),
1058
1079
  killBox: import_vitest3.vi.fn(),
1059
1080
  rng: (0, import_shared5.createRandomGenerator)({ seed }),
1060
1081
  imports: {
@@ -1076,7 +1097,7 @@ function createTestContext(options) {
1076
1097
  return entityList.find(predicate);
1077
1098
  }),
1078
1099
  findByClassname: import_vitest3.vi.fn((classname) => {
1079
- return entityList.find((e) => e.classname === classname);
1100
+ return entityList.filter((e) => e.classname === classname);
1080
1101
  }),
1081
1102
  beginFrame: import_vitest3.vi.fn((timeSeconds) => {
1082
1103
  entities.timeSeconds = timeSeconds;
@@ -1097,6 +1118,7 @@ function createTestContext(options) {
1097
1118
  activeCount: entityList.length,
1098
1119
  world: entityList.find((e) => e.classname === "worldspawn") || new import_game2.Entity(0)
1099
1120
  };
1121
+ game.entities = entities;
1100
1122
  return {
1101
1123
  keyValues: {},
1102
1124
  entities,
@@ -1196,15 +1218,41 @@ function createMockGameExports(overrides = {}) {
1196
1218
  };
1197
1219
  }
1198
1220
 
1199
- // src/game/helpers/physics.ts
1221
+ // src/game/helpers/spawn.ts
1200
1222
  var import_game3 = require("@quake2ts/game");
1223
+ function createSpawnRegistry(game) {
1224
+ const gameMock = game || {};
1225
+ return (0, import_game3.createDefaultSpawnRegistry)(gameMock);
1226
+ }
1227
+ function registerTestSpawn(registry, classname, spawnFunc) {
1228
+ registry.register(classname, spawnFunc);
1229
+ }
1230
+ function spawnTestEntity(context, options) {
1231
+ const registry = options.registry || context.game?.entities?.spawnRegistry;
1232
+ if (!registry) {
1233
+ throw new Error("No spawn registry provided and none found on context.game.entities");
1234
+ }
1235
+ const keyValues = {
1236
+ classname: options.classname,
1237
+ ...options.keyValues || {}
1238
+ };
1239
+ const spawnOptions = {
1240
+ registry,
1241
+ entities: context.entities,
1242
+ onWarning: options.onWarning
1243
+ };
1244
+ return (0, import_game3.spawnEntityFromDictionary)(keyValues, spawnOptions);
1245
+ }
1246
+
1247
+ // src/game/helpers/physics.ts
1248
+ var import_game4 = require("@quake2ts/game");
1201
1249
  var import_shared6 = require("@quake2ts/shared");
1202
1250
  function createPhysicsTestScenario(scenarioType, context) {
1203
1251
  const walls = [];
1204
1252
  const ground = context.entities.spawn();
1205
1253
  ground.classname = "func_wall";
1206
- ground.solid = import_game3.Solid.Bsp;
1207
- ground.movetype = import_game3.MoveType.Push;
1254
+ ground.solid = import_game4.Solid.Bsp;
1255
+ ground.movetype = import_game4.MoveType.Push;
1208
1256
  ground.origin = { x: 0, y: 0, z: -10 };
1209
1257
  ground.mins = { x: -1e3, y: -1e3, z: -10 };
1210
1258
  ground.maxs = { x: 1e3, y: 1e3, z: 0 };
@@ -1213,7 +1261,7 @@ function createPhysicsTestScenario(scenarioType, context) {
1213
1261
  for (let i = 0; i < 5; i++) {
1214
1262
  const step = context.entities.spawn();
1215
1263
  step.classname = "func_wall";
1216
- step.solid = import_game3.Solid.Bsp;
1264
+ step.solid = import_game4.Solid.Bsp;
1217
1265
  step.origin = { x: 100 + i * 32, y: 0, z: i * 16 };
1218
1266
  step.mins = { x: 0, y: -64, z: 0 };
1219
1267
  step.maxs = { x: 32, y: 64, z: 16 };
@@ -1224,7 +1272,7 @@ function createPhysicsTestScenario(scenarioType, context) {
1224
1272
  const setupLadder = () => {
1225
1273
  const ladder = context.entities.spawn();
1226
1274
  ladder.classname = "func_wall";
1227
- ladder.solid = import_game3.Solid.Bsp;
1275
+ ladder.solid = import_game4.Solid.Bsp;
1228
1276
  ladder.origin = { x: 100, y: 0, z: 0 };
1229
1277
  ladder.mins = { x: 0, y: -32, z: 0 };
1230
1278
  ladder.maxs = { x: 10, y: 32, z: 200 };
@@ -1235,8 +1283,8 @@ function createPhysicsTestScenario(scenarioType, context) {
1235
1283
  const setupPlatform = () => {
1236
1284
  const plat = context.entities.spawn();
1237
1285
  plat.classname = "func_plat";
1238
- plat.solid = import_game3.Solid.Bsp;
1239
- plat.movetype = import_game3.MoveType.Push;
1286
+ plat.solid = import_game4.Solid.Bsp;
1287
+ plat.movetype = import_game4.MoveType.Push;
1240
1288
  plat.origin = { x: 0, y: 0, z: 0 };
1241
1289
  plat.mins = { x: -64, y: -64, z: 0 };
1242
1290
  plat.maxs = { x: 64, y: 64, z: 10 };
@@ -1490,11 +1538,11 @@ function createMockMonsterMove(first, last, think, action) {
1490
1538
 
1491
1539
  // src/game/mocks/combat.ts
1492
1540
  var import_vitest5 = require("vitest");
1493
- var import_game4 = require("@quake2ts/game");
1541
+ var import_game5 = require("@quake2ts/game");
1494
1542
  function createMockDamageInfo(overrides = {}) {
1495
1543
  return {
1496
1544
  damage: 10,
1497
- mod: import_game4.DamageMod.UNKNOWN,
1545
+ mod: import_game5.DamageMod.UNKNOWN,
1498
1546
  knockback: 0,
1499
1547
  attacker: null,
1500
1548
  inflictor: null,
@@ -1553,10 +1601,10 @@ function createPowerArmorState(partial = {}) {
1553
1601
  }
1554
1602
 
1555
1603
  // src/game/mocks/items.ts
1556
- var import_game5 = require("@quake2ts/game");
1557
1604
  var import_game6 = require("@quake2ts/game");
1605
+ var import_game7 = require("@quake2ts/game");
1558
1606
  function createMockInventory(overrides = {}) {
1559
- const defaultInventory = (0, import_game5.createPlayerInventory)();
1607
+ const defaultInventory = (0, import_game6.createPlayerInventory)();
1560
1608
  const inventory = {
1561
1609
  ...defaultInventory,
1562
1610
  ...overrides
@@ -1565,7 +1613,7 @@ function createMockInventory(overrides = {}) {
1565
1613
  }
1566
1614
  function createMockItem(id, overrides = {}) {
1567
1615
  let base;
1568
- base = import_game6.WEAPON_ITEMS[id] || import_game6.HEALTH_ITEMS[id] || import_game6.ARMOR_ITEMS[id] || import_game6.POWERUP_ITEMS[id] || import_game6.POWER_ARMOR_ITEMS[id] || import_game6.KEY_ITEMS[id] || import_game6.FLAG_ITEMS[id];
1616
+ base = import_game7.WEAPON_ITEMS[id] || import_game7.HEALTH_ITEMS[id] || import_game7.ARMOR_ITEMS[id] || import_game7.POWERUP_ITEMS[id] || import_game7.POWER_ARMOR_ITEMS[id] || import_game7.KEY_ITEMS[id] || import_game7.FLAG_ITEMS[id];
1569
1617
  if (!base) {
1570
1618
  base = {
1571
1619
  id,
@@ -1578,7 +1626,7 @@ function createMockItem(id, overrides = {}) {
1578
1626
  };
1579
1627
  }
1580
1628
  function createMockWeaponItem(weaponId, overrides = {}) {
1581
- const found = Object.values(import_game6.WEAPON_ITEMS).find((w) => w.weaponId === weaponId);
1629
+ const found = Object.values(import_game7.WEAPON_ITEMS).find((w) => w.weaponId === weaponId);
1582
1630
  const base = found ? { ...found } : {
1583
1631
  type: "weapon",
1584
1632
  id: `weapon_${weaponId}`,
@@ -1611,7 +1659,7 @@ function createMockArmorItem(amount, overrides = {}) {
1611
1659
  };
1612
1660
  }
1613
1661
  function createMockAmmoItem(ammoItemId, overrides = {}) {
1614
- const def = (0, import_game6.getAmmoItemDefinition)(ammoItemId);
1662
+ const def = (0, import_game7.getAmmoItemDefinition)(ammoItemId);
1615
1663
  if (!def) {
1616
1664
  throw new Error(`Unknown ammo item id: ${ammoItemId}`);
1617
1665
  }
@@ -1625,7 +1673,7 @@ function createMockAmmoItem(ammoItemId, overrides = {}) {
1625
1673
  };
1626
1674
  }
1627
1675
  function createMockPowerupItem(id, duration, overrides = {}) {
1628
- const found = import_game6.POWERUP_ITEMS[id];
1676
+ const found = import_game7.POWERUP_ITEMS[id];
1629
1677
  const base = found ? { ...found } : {
1630
1678
  type: "powerup",
1631
1679
  id,
@@ -5981,6 +6029,7 @@ function createVisualTestScenario(sceneName) {
5981
6029
  createSaveGameSnapshot,
5982
6030
  createServerSnapshot,
5983
6031
  createSolidTexture,
6032
+ createSpawnRegistry,
5984
6033
  createSpawnTestContext,
5985
6034
  createStorageTestScenario,
5986
6035
  createSurfaceMock,
@@ -6018,6 +6067,7 @@ function createVisualTestScenario(sceneName) {
6018
6067
  mockMonsterAttacks,
6019
6068
  parseProtocolPlayerState,
6020
6069
  randomVector3,
6070
+ registerTestSpawn,
6021
6071
  renderAndCapture,
6022
6072
  renderAndCaptureWebGL,
6023
6073
  renderAndCaptureWebGLPlaywright,
@@ -6050,6 +6100,7 @@ function createVisualTestScenario(sceneName) {
6050
6100
  simulateServerTick,
6051
6101
  simulateSnapshotDelivery,
6052
6102
  spawnEntity,
6103
+ spawnTestEntity,
6053
6104
  stairTrace,
6054
6105
  takeScreenshot,
6055
6106
  teardownBrowserEnvironment,