@quake2ts/test-utils 0.0.828 → 0.0.830

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,
@@ -982,7 +985,10 @@ var createMockGame = (seed = 12345) => {
982
985
  }),
983
986
  damage: import_vitest3.vi.fn((amount) => {
984
987
  hooks.onDamage({}, null, null, amount, 0, 0);
985
- })
988
+ }),
989
+ entities: {
990
+ spawnRegistry
991
+ }
986
992
  };
987
993
  return { game, spawnRegistry };
988
994
  };
@@ -998,7 +1004,10 @@ function createTestContext(options) {
998
1004
  );
999
1005
  const entityList = options?.initialEntities ? [...options.initialEntities] : [];
1000
1006
  const hooks = game.hooks;
1001
- let currentSpawnRegistry;
1007
+ let currentSpawnRegistry = spawnRegistry;
1008
+ const findByTargetName = (targetname) => {
1009
+ return entityList.filter((e) => e.targetname === targetname && e.inUse);
1010
+ };
1002
1011
  const entities = {
1003
1012
  spawn: import_vitest3.vi.fn(() => {
1004
1013
  const ent = new import_game2.Entity(entityList.length + 1);
@@ -1053,9 +1062,20 @@ function createTestContext(options) {
1053
1062
  }),
1054
1063
  soundIndex: import_vitest3.vi.fn((sound) => engine.soundIndex(sound)),
1055
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];
1056
1078
  }),
1057
- findByTargetName: import_vitest3.vi.fn(() => []),
1058
- pickTarget: import_vitest3.vi.fn(() => null),
1059
1079
  killBox: import_vitest3.vi.fn(),
1060
1080
  rng: (0, import_shared5.createRandomGenerator)({ seed }),
1061
1081
  imports: {
@@ -1077,7 +1097,7 @@ function createTestContext(options) {
1077
1097
  return entityList.find(predicate);
1078
1098
  }),
1079
1099
  findByClassname: import_vitest3.vi.fn((classname) => {
1080
- return entityList.find((e) => e.classname === classname);
1100
+ return entityList.filter((e) => e.classname === classname);
1081
1101
  }),
1082
1102
  beginFrame: import_vitest3.vi.fn((timeSeconds) => {
1083
1103
  entities.timeSeconds = timeSeconds;
@@ -1098,6 +1118,7 @@ function createTestContext(options) {
1098
1118
  activeCount: entityList.length,
1099
1119
  world: entityList.find((e) => e.classname === "worldspawn") || new import_game2.Entity(0)
1100
1120
  };
1121
+ game.entities = entities;
1101
1122
  return {
1102
1123
  keyValues: {},
1103
1124
  entities,
@@ -1197,15 +1218,41 @@ function createMockGameExports(overrides = {}) {
1197
1218
  };
1198
1219
  }
1199
1220
 
1200
- // src/game/helpers/physics.ts
1221
+ // src/game/helpers/spawn.ts
1201
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");
1202
1249
  var import_shared6 = require("@quake2ts/shared");
1203
1250
  function createPhysicsTestScenario(scenarioType, context) {
1204
1251
  const walls = [];
1205
1252
  const ground = context.entities.spawn();
1206
1253
  ground.classname = "func_wall";
1207
- ground.solid = import_game3.Solid.Bsp;
1208
- ground.movetype = import_game3.MoveType.Push;
1254
+ ground.solid = import_game4.Solid.Bsp;
1255
+ ground.movetype = import_game4.MoveType.Push;
1209
1256
  ground.origin = { x: 0, y: 0, z: -10 };
1210
1257
  ground.mins = { x: -1e3, y: -1e3, z: -10 };
1211
1258
  ground.maxs = { x: 1e3, y: 1e3, z: 0 };
@@ -1214,7 +1261,7 @@ function createPhysicsTestScenario(scenarioType, context) {
1214
1261
  for (let i = 0; i < 5; i++) {
1215
1262
  const step = context.entities.spawn();
1216
1263
  step.classname = "func_wall";
1217
- step.solid = import_game3.Solid.Bsp;
1264
+ step.solid = import_game4.Solid.Bsp;
1218
1265
  step.origin = { x: 100 + i * 32, y: 0, z: i * 16 };
1219
1266
  step.mins = { x: 0, y: -64, z: 0 };
1220
1267
  step.maxs = { x: 32, y: 64, z: 16 };
@@ -1225,7 +1272,7 @@ function createPhysicsTestScenario(scenarioType, context) {
1225
1272
  const setupLadder = () => {
1226
1273
  const ladder = context.entities.spawn();
1227
1274
  ladder.classname = "func_wall";
1228
- ladder.solid = import_game3.Solid.Bsp;
1275
+ ladder.solid = import_game4.Solid.Bsp;
1229
1276
  ladder.origin = { x: 100, y: 0, z: 0 };
1230
1277
  ladder.mins = { x: 0, y: -32, z: 0 };
1231
1278
  ladder.maxs = { x: 10, y: 32, z: 200 };
@@ -1236,8 +1283,8 @@ function createPhysicsTestScenario(scenarioType, context) {
1236
1283
  const setupPlatform = () => {
1237
1284
  const plat = context.entities.spawn();
1238
1285
  plat.classname = "func_plat";
1239
- plat.solid = import_game3.Solid.Bsp;
1240
- plat.movetype = import_game3.MoveType.Push;
1286
+ plat.solid = import_game4.Solid.Bsp;
1287
+ plat.movetype = import_game4.MoveType.Push;
1241
1288
  plat.origin = { x: 0, y: 0, z: 0 };
1242
1289
  plat.mins = { x: -64, y: -64, z: 0 };
1243
1290
  plat.maxs = { x: 64, y: 64, z: 10 };
@@ -1491,11 +1538,11 @@ function createMockMonsterMove(first, last, think, action) {
1491
1538
 
1492
1539
  // src/game/mocks/combat.ts
1493
1540
  var import_vitest5 = require("vitest");
1494
- var import_game4 = require("@quake2ts/game");
1541
+ var import_game5 = require("@quake2ts/game");
1495
1542
  function createMockDamageInfo(overrides = {}) {
1496
1543
  return {
1497
1544
  damage: 10,
1498
- mod: import_game4.DamageMod.UNKNOWN,
1545
+ mod: import_game5.DamageMod.UNKNOWN,
1499
1546
  knockback: 0,
1500
1547
  attacker: null,
1501
1548
  inflictor: null,
@@ -1554,10 +1601,10 @@ function createPowerArmorState(partial = {}) {
1554
1601
  }
1555
1602
 
1556
1603
  // src/game/mocks/items.ts
1557
- var import_game5 = require("@quake2ts/game");
1558
1604
  var import_game6 = require("@quake2ts/game");
1605
+ var import_game7 = require("@quake2ts/game");
1559
1606
  function createMockInventory(overrides = {}) {
1560
- const defaultInventory = (0, import_game5.createPlayerInventory)();
1607
+ const defaultInventory = (0, import_game6.createPlayerInventory)();
1561
1608
  const inventory = {
1562
1609
  ...defaultInventory,
1563
1610
  ...overrides
@@ -1566,7 +1613,7 @@ function createMockInventory(overrides = {}) {
1566
1613
  }
1567
1614
  function createMockItem(id, overrides = {}) {
1568
1615
  let base;
1569
- 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];
1570
1617
  if (!base) {
1571
1618
  base = {
1572
1619
  id,
@@ -1579,7 +1626,7 @@ function createMockItem(id, overrides = {}) {
1579
1626
  };
1580
1627
  }
1581
1628
  function createMockWeaponItem(weaponId, overrides = {}) {
1582
- 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);
1583
1630
  const base = found ? { ...found } : {
1584
1631
  type: "weapon",
1585
1632
  id: `weapon_${weaponId}`,
@@ -1612,7 +1659,7 @@ function createMockArmorItem(amount, overrides = {}) {
1612
1659
  };
1613
1660
  }
1614
1661
  function createMockAmmoItem(ammoItemId, overrides = {}) {
1615
- const def = (0, import_game6.getAmmoItemDefinition)(ammoItemId);
1662
+ const def = (0, import_game7.getAmmoItemDefinition)(ammoItemId);
1616
1663
  if (!def) {
1617
1664
  throw new Error(`Unknown ammo item id: ${ammoItemId}`);
1618
1665
  }
@@ -1626,7 +1673,7 @@ function createMockAmmoItem(ammoItemId, overrides = {}) {
1626
1673
  };
1627
1674
  }
1628
1675
  function createMockPowerupItem(id, duration, overrides = {}) {
1629
- const found = import_game6.POWERUP_ITEMS[id];
1676
+ const found = import_game7.POWERUP_ITEMS[id];
1630
1677
  const base = found ? { ...found } : {
1631
1678
  type: "powerup",
1632
1679
  id,
@@ -5982,6 +6029,7 @@ function createVisualTestScenario(sceneName) {
5982
6029
  createSaveGameSnapshot,
5983
6030
  createServerSnapshot,
5984
6031
  createSolidTexture,
6032
+ createSpawnRegistry,
5985
6033
  createSpawnTestContext,
5986
6034
  createStorageTestScenario,
5987
6035
  createSurfaceMock,
@@ -6019,6 +6067,7 @@ function createVisualTestScenario(sceneName) {
6019
6067
  mockMonsterAttacks,
6020
6068
  parseProtocolPlayerState,
6021
6069
  randomVector3,
6070
+ registerTestSpawn,
6022
6071
  renderAndCapture,
6023
6072
  renderAndCaptureWebGL,
6024
6073
  renderAndCaptureWebGLPlaywright,
@@ -6051,6 +6100,7 @@ function createVisualTestScenario(sceneName) {
6051
6100
  simulateServerTick,
6052
6101
  simulateSnapshotDelivery,
6053
6102
  spawnEntity,
6103
+ spawnTestEntity,
6054
6104
  stairTrace,
6055
6105
  takeScreenshot,
6056
6106
  teardownBrowserEnvironment,