@adatechnology/game-vehicles-three 0.2.0 → 0.3.1

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.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/build.ts
2
+ import { markKitOrigin } from "@adatechnology/game-contracts";
2
3
  import { colorFromSeed, fleetDims, paintPalettes, paletteOf } from "@adatechnology/game-vehicles-fleet";
3
4
 
4
5
  // src/lite.ts
@@ -230,6 +231,7 @@ function createVehiclesThree(THREE, options) {
230
231
  const pivotMatrix = new THREE.Matrix4().makeTranslation(-cx, -bounds.min.y, -cz).multiply(rotation);
231
232
  const group = new THREE.Group();
232
233
  group.name = `vehicle:${key}`;
234
+ markKitOrigin(group, { owner: "game-vehicles-three", kind: "vehicle", id: key });
233
235
  const damageables = kit.damageables(c, pivotMatrix);
234
236
  let pruned = 0;
235
237
  if (quality === "high") {
@@ -321,6 +323,7 @@ var scenarioIds = [
321
323
  "vehicles_kill_battery",
322
324
  "vehicles_rollover",
323
325
  "vehicles_melt",
326
+ "vehicles_burnt_wreck",
324
327
  "vehicles_drive_arcade",
325
328
  "vehicles_drive_semi"
326
329
  ];
@@ -352,7 +355,7 @@ var TEXT = {
352
355
  en: {
353
356
  group: "Vehicles",
354
357
  name: "Vehicles area",
355
- items: { hatch: "Compact hatch", sedan: "Midsize sedan", pickup: "Midsize pickup", sport_bike: "Sport bike", box_truck: "Box truck", city_bus: "City bus", battle_tank: "Battle tank", attack_helicopter: "Attack helicopter" },
358
+ items: { hatch: "Compact hatch", sedan: "Midsize sedan", pickup: "Midsize pickup", sport_bike: "Sport bike", box_truck: "Box truck", city_bus: "City bus", battle_tank: "Battle tank", attack_helicopter: "Attack helicopter", sedan_burnt: "Burnt sedan", hatch_burnt: "Burnt hatch" },
356
359
  controls: { quality: "Quality", paint_by_seed: "Paint by seed", color_seed: "Colour seed", palette: "Palette", driving: "Driving", surface: "Surface" },
357
360
  hints: {
358
361
  quality: "High: the kit at full detail. Light: fewer segments and no interior (the light mode of the fleet); applies to the vehicles placed from now on",
@@ -385,7 +388,8 @@ var TEXT = {
385
388
  vehicles_rollover: "Vehicles: roll over",
386
389
  vehicles_melt: "Vehicles: melt (long fire burns the tyres)",
387
390
  vehicles_drive_arcade: "Vehicles: arcade driving down a lane that ends in a wall",
388
- vehicles_drive_semi: "Vehicles: semi-simulation braking on dry, wet and mud"
391
+ vehicles_drive_semi: "Vehicles: semi-simulation braking on dry, wet and mud",
392
+ vehicles_burnt_wreck: "Vehicles: the burnt sedan comes out of the kit burnt, with the glass gone"
389
393
  },
390
394
  checks: {
391
395
  windshield_holes: "Windshield: {0} hole(s), went through {1:b} (expected: 1, true)",
@@ -410,13 +414,15 @@ var TEXT = {
410
414
  arcade_bounce: "Arcade: the car bounces back at {0} m/s (expected: below 0)",
411
415
  arcade_noise: "Arcade: {0} engine noise(s) and {1} crash noise(s) (expected: 1 or more each)",
412
416
  semi_order: "Semi: braking from 80 km/h takes dry {0} m, wet {1} m, mud {2} m (expected: dry shorter than wet shorter than mud)",
413
- semi_mud: "Semi: a 2WD car on mud {0:on} (expected: bogged on, a bog event)"
417
+ semi_mud: "Semi: a 2WD car on mud {0:on} (expected: bogged on, a bog event)",
418
+ wreck_burnt: "Burnt sedan: burnt flag {0:b} (expected: yes)",
419
+ wreck_glass: "Burnt sedan: {0} glass zone(s), {1} still above 0 (expected: 1 or more, none above 0)"
414
420
  }
415
421
  },
416
422
  "pt-BR": {
417
423
  group: "Ve\xEDculos",
418
424
  name: "\xC1rea de ve\xEDculos",
419
- items: { hatch: "Hatch compacto", sedan: "Sed\xE3 m\xE9dio", pickup: "Picape m\xE9dia", sport_bike: "Moto esportiva", box_truck: "Caminh\xE3o ba\xFA", city_bus: "\xD4nibus urbano", battle_tank: "Tanque de guerra", attack_helicopter: "Helic\xF3ptero de ataque" },
425
+ items: { hatch: "Hatch compacto", sedan: "Sed\xE3 m\xE9dio", pickup: "Picape m\xE9dia", sport_bike: "Moto esportiva", box_truck: "Caminh\xE3o ba\xFA", city_bus: "\xD4nibus urbano", battle_tank: "Tanque de guerra", attack_helicopter: "Helic\xF3ptero de ataque", sedan_burnt: "Sed\xE3 queimado", hatch_burnt: "Hatch queimado" },
420
426
  controls: { quality: "Qualidade", paint_by_seed: "Pintar pela semente", color_seed: "Semente da cor", palette: "Paleta", driving: "Dire\xE7\xE3o", surface: "Piso" },
421
427
  hints: {
422
428
  quality: "Alta: o kit com todo o detalhe. Leve: menos segmentos e sem interior (o modo leve da frota); vale para os ve\xEDculos postos daqui em diante",
@@ -449,7 +455,8 @@ var TEXT = {
449
455
  vehicles_rollover: "Ve\xEDculos: capotar",
450
456
  vehicles_melt: "Ve\xEDculos: derreter (fogo longo queima os pneus)",
451
457
  vehicles_drive_arcade: "Ve\xEDculos: dire\xE7\xE3o arcade numa pista que acaba num muro",
452
- vehicles_drive_semi: "Ve\xEDculos: frenagem da semissimula\xE7\xE3o no seco, no molhado e na lama"
458
+ vehicles_drive_semi: "Ve\xEDculos: frenagem da semissimula\xE7\xE3o no seco, no molhado e na lama",
459
+ vehicles_burnt_wreck: "Ve\xEDculos: o sed\xE3 queimado sai do kit queimado, sem os vidros"
453
460
  },
454
461
  checks: {
455
462
  windshield_holes: "Para-brisa: {0} furo(s), atravessou {1:b} (esperado: 1, sim)",
@@ -474,7 +481,9 @@ var TEXT = {
474
481
  arcade_bounce: "Arcade: o carro volta a {0} m/s (esperado: abaixo de 0)",
475
482
  arcade_noise: "Arcade: {0} ru\xEDdo(s) de motor e {1} de batida (esperado: 1 ou mais de cada)",
476
483
  semi_order: "Semi: frear de 80 km/h leva no seco {0} m, no molhado {1} m, na lama {2} m (esperado: seco menor que molhado menor que lama)",
477
- semi_mud: "Semi: um carro 2WD na lama {0:on} (esperado: atolado, com evento de atolamento)"
484
+ semi_mud: "Semi: um carro 2WD na lama {0:on} (esperado: atolado, com evento de atolamento)",
485
+ wreck_burnt: "Sed\xE3 queimado: marca de queimado {0:b} (esperado: sim)",
486
+ wreck_glass: "Sed\xE3 queimado: {0} zona(s) de vidro, {1} ainda acima de 0 (esperado: 1 ou mais, nenhuma acima de 0)"
478
487
  }
479
488
  }
480
489
  };
@@ -633,6 +642,14 @@ var createScenarios = (deps) => {
633
642
  const t = part(room, v, "tyre_front_left");
634
643
  expect(events(room, "melt", v) >= 1 && (t.status === "melted" || t.melt > 0.5), say("tyre_melt", t.status, Math.round(t.melt * 100), events(room, "melt", v)));
635
644
  }),
645
+ // new in the kit: the burnt wreck comes ready from the kit (the fleet's `burnt` scenario built into the vehicle), no damage applied by the area
646
+ scenario("vehicles_burnt_wreck", ({ room, expect }) => {
647
+ const c = room.spawn("sedan_burnt", [0, 0, -7], 0).root.userData.vehicle;
648
+ expect(c.zoneState.flags.burnt === true, say("wreck_burnt", c.zoneState.flags.burnt === true));
649
+ const glass = c.zones.filter((z) => z.type === "glass");
650
+ const up = glass.filter((z) => (c.zoneState.health[z.id] ?? 100) > 0);
651
+ expect(glass.length >= 1 && up.length === 0, say("wreck_glass", glass.length, up.length));
652
+ }),
636
653
  // new in the kit: the drivers, headless (no vehicle is spawned)
637
654
  scenario("vehicles_drive_arcade", ({ expect }) => {
638
655
  const driver = createArcadeDriver();
@@ -698,6 +715,10 @@ var defaultEffectIds = {
698
715
  exhaust: "vehicle_exhaust"
699
716
  };
700
717
  var defaultSoundIds = { engine: "engine_saw", horn: "horn", crash: "sfx_impact" };
718
+ var DEFAULT_TEST_WRECKS = [
719
+ { key: "sedan_burnt", vehicle: "midsize_sedan", scenario: "burnt" },
720
+ { key: "hatch_burnt", vehicle: "compact_hatch", scenario: "burnt" }
721
+ ];
701
722
 
702
723
  // src/test-area/module.ts
703
724
  var VEHICLES_AREA_ID = "vehicles_area";
@@ -711,6 +732,8 @@ function createVehiclesTestModule(options = {}) {
711
732
  const locale = options.locale ?? "pt-BR";
712
733
  const text = TEXT[locale] ?? TEXT["pt-BR"];
713
734
  const keys = options.vehicles ?? DEFAULT_TEST_VEHICLES;
735
+ const wrecks = options.wrecks ?? DEFAULT_TEST_WRECKS;
736
+ const entries = [...keys.map((key) => ({ key, id: itemId(key) })), ...wrecks.map((w) => ({ key: w.vehicle, id: w.key, scenario: w.scenario }))];
714
737
  const effectIds = { ...defaultEffectIds, ...options.effects };
715
738
  const soundIds = { ...defaultSoundIds, ...options.sounds };
716
739
  const settings = { quality: "high", paint: false, seed: 1, palette: "auto", driving: "arcade", surface: "dry_asphalt" };
@@ -759,17 +782,17 @@ function createVehiclesTestModule(options = {}) {
759
782
  }
760
783
  entry.paint.color.set(color);
761
784
  };
762
- const item = (key) => ({
763
- id: itemId(key),
764
- name: text.items[itemId(key)] ?? key,
785
+ const item = ({ key, id: itemKey, scenario }) => ({
786
+ id: itemKey,
787
+ name: text.items[itemKey] ?? key,
765
788
  movable: false,
766
789
  // the first build of a vehicle takes most of a second
767
790
  slow: true,
768
791
  build: (THREE) => {
769
792
  const kit = kitFor(THREE);
770
- const built = buildVehicleItem(kit, key, { lod: settings.quality === "lite" });
793
+ const built = buildVehicleItem(kit, key, { lod: settings.quality === "lite", ...scenario ? { scenario } : {} });
771
794
  built.root.userData.kit = kit;
772
- const entry = { root: built.root, key, item: built, index: counter++, helpers: [] };
795
+ const entry = { root: built.root, key, ...scenario ? { scenario } : {}, item: built, index: counter++, helpers: [] };
773
796
  placed.set(built.root.uuid, entry);
774
797
  measure(entry);
775
798
  paintOf(entry);
@@ -778,7 +801,7 @@ function createVehiclesTestModule(options = {}) {
778
801
  impl: (root, id) => {
779
802
  const r = root;
780
803
  const kit = r.userData.kit;
781
- const d = createVehicleDestructible(kit, r.userData.vehicle, { id, frame: root, name: text.items[itemId(key)] ?? key });
804
+ const d = createVehicleDestructible(kit, r.userData.vehicle, { id, frame: root, name: text.items[itemKey] ?? key });
782
805
  tapEffects(d);
783
806
  r.userData.destructible = d;
784
807
  return d;
@@ -1052,7 +1075,7 @@ function createVehiclesTestModule(options = {}) {
1052
1075
  for (const entry of placed.values()) {
1053
1076
  const want = fleetDims2(entry.key);
1054
1077
  const got = entry.size;
1055
- if (!want || !got) continue;
1078
+ if (!want || !got || entry.scenario) continue;
1056
1079
  worst = Math.max(worst, Math.abs(got.length - want.length), Math.abs(got.width - want.width), Math.abs(got.height - want.height));
1057
1080
  }
1058
1081
  return Math.round(worst * 1e3);
@@ -1064,23 +1087,23 @@ function createVehiclesTestModule(options = {}) {
1064
1087
  get placed() {
1065
1088
  return placed;
1066
1089
  },
1067
- items: () => keys.map(item),
1090
+ items: () => entries.map(item),
1068
1091
  area: () => {
1069
1092
  const gap = 1.6;
1070
1093
  const WIDE = 6;
1071
1094
  const rowOf = (list, z) => {
1072
1095
  let cursor = 0;
1073
- const spots = list.map((key) => {
1074
- const width = fleetDims2(key)?.width ?? 2;
1096
+ const spots = list.map((entry) => {
1097
+ const width = fleetDims2(entry.key)?.width ?? 2;
1075
1098
  const x = cursor + width / 2;
1076
1099
  cursor += width + gap;
1077
- return { key, x };
1100
+ return { id: entry.id, x };
1078
1101
  });
1079
1102
  return { spots, z, width: Math.max(0, cursor - gap) };
1080
1103
  };
1081
- const front = rowOf(keys.filter((key) => (fleetDims2(key)?.width ?? 2) <= WIDE), 0);
1082
- const back = rowOf(keys.filter((key) => (fleetDims2(key)?.width ?? 2) > WIDE), -16);
1083
- const placements = [front, back].flatMap((row) => row.spots.map(({ key, x }) => ({ item: itemId(key), position: [x - row.width / 2, 0, row.z], rotationY: 0 })));
1104
+ const front = rowOf(entries.filter((e) => (fleetDims2(e.key)?.width ?? 2) <= WIDE), 0);
1105
+ const back = rowOf(entries.filter((e) => (fleetDims2(e.key)?.width ?? 2) > WIDE), -16);
1106
+ const placements = [front, back].flatMap((row) => row.spots.map(({ id, x }) => ({ item: id, position: [x - row.width / 2, 0, row.z], rotationY: 0 })));
1084
1107
  return { placements, view: { eye: [0, 5, Math.max(14, front.width * 0.6)], target: [0, 1, -2] } };
1085
1108
  },
1086
1109
  controls: () => {
@@ -1140,6 +1163,7 @@ function loadVehiclesTestModule(room, options = {}) {
1140
1163
  }
1141
1164
  export {
1142
1165
  DEFAULT_TEST_VEHICLES,
1166
+ DEFAULT_TEST_WRECKS,
1143
1167
  LITE_CLASSES,
1144
1168
  PAGE_ITEM_ALIASES,
1145
1169
  PAGE_SCENARIO_ALIASES,