@adatechnology/game-items-three 0.13.0 → 0.14.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.
@@ -3,7 +3,7 @@ import { discardObject3D } from "@adatechnology/game-shapes-three";
3
3
  import { markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
4
4
  import { furnitureSpec } from "@adatechnology/game-floorplan-three";
5
5
  import { rng } from "@adatechnology/game-interactables";
6
- import { canCraft, craft, createFindsProvider, freshness, ITEM_CATEGORIES } from "@adatechnology/game-items";
6
+ import { canCraft, craft, createFindsProvider, freshness as freshness2, ITEM_CATEGORIES, itemFluid as itemFluid2 } from "@adatechnology/game-items";
7
7
 
8
8
  // src/area-layout.ts
9
9
  var SHELF_HEIGHT = 0.9;
@@ -69,6 +69,7 @@ function shelvesLayout(items, categories) {
69
69
 
70
70
  // src/build-item.ts
71
71
  import { markKitOrigin } from "@adatechnology/game-contracts";
72
+ import { itemFluid } from "@adatechnology/game-items";
72
73
 
73
74
  // src/destruction.ts
74
75
  import { LIQUIDS } from "@adatechnology/game-fluids";
@@ -156,7 +157,9 @@ var destruction_default = {
156
157
  "coconut_water",
157
158
  "cooking_oil",
158
159
  "alcohol_70",
159
- "fuel_jerrycan"
160
+ "fuel_jerrycan",
161
+ "shampoo",
162
+ "toothpaste"
160
163
  ],
161
164
  rule: {
162
165
  hollow: true,
@@ -291,6 +294,14 @@ var destruction_default = {
291
294
  condensed_milk: {
292
295
  liquid: "honey",
293
296
  fill: 0.9
297
+ },
298
+ shampoo: {
299
+ liquid: "shampoo",
300
+ fill: 0.9
301
+ },
302
+ toothpaste: {
303
+ liquid: "toothpaste",
304
+ fill: 0.85
294
305
  }
295
306
  },
296
307
  shapes: {
@@ -626,14 +637,15 @@ var SHELL_PART_ID = "shell";
626
637
  var WALL_SHARE = 0.9;
627
638
  var OPENING_RADIUS = 0.012;
628
639
  function itemContents(subject) {
629
- const contents = subject.model === void 0 ? void 0 : CONTENTS[subject.model];
640
+ const known = subject.model === void 0 ? void 0 : CONTENTS[subject.model];
641
+ const contents = known ?? (subject.fluid ? { liquid: subject.fluid.liquid, fill: 1, ...subject.box ? { box: true } : {} } : void 0);
630
642
  if (!contents) return void 0;
631
643
  const [width, height, depth] = subject.size;
632
644
  const radius = Math.min(width, depth) / 2;
633
645
  const innerLiters = (contents.box ? width * depth : Math.PI * radius * radius) * height * WALL_SHARE * 1e3;
634
646
  const density = LIQUIDS.find((liquid) => liquid.id === contents.liquid)?.density ?? 1e3;
635
647
  const heaviest = subject.weight === void 0 ? Infinity : subject.weight * 1e3 / density;
636
- const liters = Math.min(innerLiters * contents.fill, heaviest);
648
+ const liters = Math.min(known ? innerLiters * contents.fill : subject.fluid?.liters ?? 0, innerLiters, heaviest);
637
649
  const container = {
638
650
  capacity: innerLiters,
639
651
  liquid: contents.liquid,
@@ -644,6 +656,10 @@ function itemContents(subject) {
644
656
  };
645
657
  return { container, liquid: contents.liquid, liters };
646
658
  }
659
+ function containsOf(contents) {
660
+ const viscosity = LIQUIDS.find((liquid) => liquid.id === contents.liquid)?.viscosity ?? 1;
661
+ return { fluid: contents.liquid, liters: contents.liters, viscosity };
662
+ }
647
663
  var VESSEL_FLOORS = { cup: CUP_FLOOR_SHARE };
648
664
  function itemVessel(subject) {
649
665
  const capacity = subject.capacityLiters;
@@ -769,14 +785,23 @@ function tagForDestruction(root, options = {}) {
769
785
  if (powder) mesh.userData.destructionPowder = { color: powder.color };
770
786
  solid.push(mesh);
771
787
  });
772
- if (!rule?.welded || solid.length < 2) return;
773
- const anchor = solid.reduce((largest, mesh) => volumeOf(mesh) > volumeOf(largest) ? mesh : largest);
788
+ const largest = () => solid.reduce((big, mesh) => volumeOf(mesh) > volumeOf(big) ? mesh : big);
789
+ if (!rule?.welded || solid.length < 2) {
790
+ const held = options.fluid && size !== void 0 && solid.length > 0 ? itemContents({ size, ...weight === void 0 ? {} : { weight }, fluid: options.fluid }) : void 0;
791
+ if (!held) return;
792
+ const body2 = largest();
793
+ body2.userData.destructionPart = { id: SHELL_PART_ID };
794
+ body2.userData.hollow = true;
795
+ body2.userData.destructionContains = containsOf(held);
796
+ return;
797
+ }
798
+ const anchor = largest();
774
799
  solid.forEach((mesh, index) => {
775
800
  mesh.userData.destructionPart = mesh === anchor ? { id: SHELL_PART_ID } : { id: `shell_${index}`, parent: SHELL_PART_ID, kind: "weld" };
776
801
  if (rule.wall) mesh.userData.destructionThickness = mesh === anchor ? rule.wall.body : rule.wall.ends;
777
802
  });
778
803
  const contents = size === void 0 ? void 0 : itemContents({ ...modelId === void 0 ? {} : { model: modelId }, size, ...weight === void 0 ? {} : { weight } });
779
- if (contents) anchor.userData.destructionContains = { fluid: contents.liquid, liters: contents.liters };
804
+ if (contents) anchor.userData.destructionContains = containsOf(contents);
780
805
  }
781
806
 
782
807
  // src/kit.ts
@@ -3327,6 +3352,46 @@ var models_default = [
3327
3352
  ],
3328
3353
  scale: 0.092308
3329
3354
  },
3355
+ {
3356
+ id: "soap",
3357
+ teamId: "sabonete",
3358
+ teamBox: [
3359
+ 0.9,
3360
+ 0.3,
3361
+ 0.5
3362
+ ],
3363
+ scale: 0.1
3364
+ },
3365
+ {
3366
+ id: "shampoo",
3367
+ teamId: "shampoo",
3368
+ teamBox: [
3369
+ 0.6,
3370
+ 2,
3371
+ 0.4002
3372
+ ],
3373
+ scale: 0.1
3374
+ },
3375
+ {
3376
+ id: "toothpaste",
3377
+ teamId: "pasta_dente",
3378
+ teamBox: [
3379
+ 0.4,
3380
+ 1.8,
3381
+ 0.3
3382
+ ],
3383
+ scale: 0.1
3384
+ },
3385
+ {
3386
+ id: "toothbrush",
3387
+ teamId: "escova_dente",
3388
+ teamBox: [
3389
+ 0.2,
3390
+ 1.8,
3391
+ 0.2
3392
+ ],
3393
+ scale: 0.1
3394
+ },
3330
3395
  {
3331
3396
  id: "plunger",
3332
3397
  teamId: "desentupidor",
@@ -4518,6 +4583,61 @@ var alcohol70 = ({ mesh, cyl, lathe, G, glass, plastic, paper: paper2 }) => {
4518
4583
  return G(bottle2, label, stripe, cap, nozzle);
4519
4584
  };
4520
4585
 
4586
+ // src/models/shampoo.ts
4587
+ var shampoo = ({ mesh, cyl, lathe, G, plastic, paper: paper2 }) => {
4588
+ const oval = [1, 1, 0.667];
4589
+ const body = mesh(lathe([[0, -1], [0.24, -1], [0.28, -0.94], [0.28, 0.42], [0.25, 0.55], [0.15, 0.62], [0.15, 0.66], [0, 0.66]], 14), plastic(4885200), [0, 0, 0], [0, 0, 0], oval);
4590
+ const label = mesh(cyl(0.3, 0.3, 0.8, 16), paper2(15922680), [0, -0.35, 0], [0, 0, 0], oval);
4591
+ const cap = mesh(cyl(0.17, 0.17, 0.28, 12), plastic(15790320), [0, 0.8, 0], [0, 0, 0], oval);
4592
+ const lid = mesh(cyl(0.12, 0.17, 0.06, 12), plastic(14869218), [0, 0.97, 0], [0, 0, 0], oval);
4593
+ return G(body, label, cap, lid);
4594
+ };
4595
+
4596
+ // src/models/soap.ts
4597
+ var roundedRect = (width, depth, corner, steps = 4) => {
4598
+ const points = [];
4599
+ const centres = [
4600
+ [width / 2 - corner, depth / 2 - corner, 0],
4601
+ [-width / 2 + corner, depth / 2 - corner, Math.PI / 2],
4602
+ [-width / 2 + corner, -depth / 2 + corner, Math.PI],
4603
+ [width / 2 - corner, -depth / 2 + corner, 3 * Math.PI / 2]
4604
+ ];
4605
+ for (const [cx, cy, start] of centres) {
4606
+ for (let step = 0; step <= steps; step++) {
4607
+ const angle = start + step / steps * (Math.PI / 2);
4608
+ points.push([cx + Math.cos(angle) * corner, cy + Math.sin(angle) * corner]);
4609
+ }
4610
+ }
4611
+ return points;
4612
+ };
4613
+ var soap = ({ mesh, extrude, M, G }) => {
4614
+ const edge = 0.04;
4615
+ const bar = extrude(roundedRect(0.9 - 2 * edge, 0.5 - 2 * edge, 0.14), 0.3 - 2 * edge, edge);
4616
+ bar.center();
4617
+ return G(mesh(bar, M(15984338, "wax", { roughness: 0.55 }), [0, 0, 0], [Math.PI / 2, 0, 0]));
4618
+ };
4619
+
4620
+ // src/models/toothbrush.ts
4621
+ var toothbrush = ({ mesh, bx, G, plastic, M }) => {
4622
+ const handle = mesh(bx(0.16, 0.8, 0.1), plastic(3840720), [0, 0.75, -0.05]);
4623
+ const grip = mesh(bx(0.2, 0.35, 0.12), plastic(2912160), [0, 0.175, -0.05]);
4624
+ const neck = mesh(bx(0.08, 0.3, 0.08), plastic(3840720), [0, 1.3, -0.05]);
4625
+ const head = mesh(bx(0.14, 0.35, 0.06), plastic(3840720), [0, 1.625, -0.06]);
4626
+ const bristles = mesh(bx(0.12, 0.32, 0.12), M(16054008, "plastic", { roughness: 0.9 }), [0, 1.62, 0.03]);
4627
+ return G(handle, grip, neck, head, bristles);
4628
+ };
4629
+
4630
+ // src/models/toothpaste.ts
4631
+ var toothpaste = ({ mesh, cyl, bx, G, plastic }) => {
4632
+ const flat = [1, 1, 0.75];
4633
+ const cap = mesh(cyl(0.11, 0.12, 0.22, 12), plastic(2056104), [0, 0.11, 0]);
4634
+ const shoulder = mesh(cyl(0.2, 0.11, 0.08, 14), plastic(16053494), [0, 0.26, 0], [0, 0, 0], flat);
4635
+ const body = mesh(cyl(0.2, 0.2, 0.9, 14), plastic(16053494), [0, 0.75, 0], [0, 0, 0], flat);
4636
+ const taper = mesh(cyl(0.2, 0.2, 0.44, 14), plastic(16053494), [0, 1.41, 0], [0, 0, 0], [1, 1, 0.42]);
4637
+ const crimp = mesh(bx(0.4, 0.17, 0.04), plastic(15132394), [0, 1.715, 0]);
4638
+ return G(cap, shoulder, body, taper, crimp);
4639
+ };
4640
+
4521
4641
  // src/models/plunger.ts
4522
4642
  var plunger = ({ mesh, cyl, G, M, wood }) => {
4523
4643
  const rubber = M(11545120, "rubber", { roughness: 0.75 });
@@ -7205,6 +7325,10 @@ var BUILDERS = {
7205
7325
  watering_can: wateringCan,
7206
7326
  wheelbarrow,
7207
7327
  windup_alarm_clock: windupAlarmClock,
7328
+ soap,
7329
+ shampoo,
7330
+ toothpaste,
7331
+ toothbrush,
7208
7332
  plunger
7209
7333
  };
7210
7334
  var SHIPPED_MODELS = models_default.map((entry) => {
@@ -7238,6 +7362,13 @@ var hasItemModel = (id) => defaultItemModels().has(id);
7238
7362
  var listItemModels = () => defaultItemModels().list();
7239
7363
 
7240
7364
  // src/wear.ts
7365
+ import { freshness } from "@adatechnology/game-items";
7366
+ var wearOfFreshness = (state) => state === "fresh" ? 0 : state === "stale" ? 1 : 2;
7367
+ var AGED_IN = "ambient";
7368
+ function wearOfAge(item, ageDays, rules) {
7369
+ if (item.shelfLife === void 0 || ageDays <= 0) return 0;
7370
+ return wearOfFreshness(freshness(item, { ageDays, since: 0, storage: AGED_IN, storedAt: 0 }, 0, rules ? { rules } : {}));
7371
+ }
7241
7372
  var WEAR_TARGET = { food: 6122286, metal: 8011293, wood: 4141862, cloth: 4866099, plastic: 7038294, paper: 9075282, glass: 5591098, rubber: 4860452 };
7242
7373
  var WEAR_AMOUNT = [0, 0.3, 0.62];
7243
7374
  var hexToRgb = (hex2) => [(hex2 >> 16 & 255) / 255, (hex2 >> 8 & 255) / 255, (hex2 & 255) / 255];
@@ -7304,7 +7435,8 @@ function buildItem(T, item, options = {}) {
7304
7435
  const materials = kit.materials.slice(first);
7305
7436
  if (options.wear) setWear(materials, options.wear);
7306
7437
  root.userData.wear = options.wear ?? 0;
7307
- if (options.destructible) tagForDestruction(root, { ...kind === "model" && item.model !== void 0 ? { modelId: item.model } : {}, ...shape === void 0 ? {} : { shapeId: shape }, ...item.weight === void 0 ? {} : { weight: item.weight }, size: item.size, ...item.powder ? { powder: item.powder } : {}, ...item.parts ? { parts: item.parts } : {}, three: T });
7438
+ const held = itemFluid(item);
7439
+ if (options.destructible) tagForDestruction(root, { ...kind === "model" && item.model !== void 0 ? { modelId: item.model } : {}, ...shape === void 0 ? {} : { shapeId: shape }, ...item.weight === void 0 ? {} : { weight: item.weight }, size: item.size, ...item.powder ? { powder: item.powder } : {}, ...item.parts ? { parts: item.parts } : {}, ...held ? { fluid: held } : {}, three: T });
7308
7440
  markKitOrigin(root, { owner: "game-items-three", kind: "item", id: item.id, ...kind === "shape" ? { standIn: true } : {} });
7309
7441
  return { root, kind, ...shape ? { shape } : {}, size: item.size, materials };
7310
7442
  }
@@ -7715,9 +7847,8 @@ var fill = (template, vars) => template.replace(/\{(\w+)\}/g, (_, key2) => Strin
7715
7847
  var humanize = (id) => id.replace(/_/g, " ").replace(/^./, (c) => c.toUpperCase());
7716
7848
  var stageOf = (catalog, item, base, ageDays, storage, powered) => {
7717
7849
  if (item.shelfLife === void 0 || ageDays <= 0) return base;
7718
- const state = freshness(item, { ageDays: 0, since: 0, storage, storedAt: 0 }, ageDays, { powered, rules: catalog.rules });
7719
- const aged = state === "fresh" ? 0 : state === "stale" ? 1 : 2;
7720
- return Math.max(base, aged);
7850
+ const state = freshness2(item, { ageDays: 0, since: 0, storage, storedAt: 0 }, ageDays, { powered, rules: catalog.rules });
7851
+ return Math.max(base, wearOfFreshness(state));
7721
7852
  };
7722
7853
  var sizeOfModel = (modelSet, id) => {
7723
7854
  const entry = modelSet.entry(id);
@@ -7831,7 +7962,8 @@ function createItemsTestModule(options) {
7831
7962
  };
7832
7963
  const usesOf = (def) => {
7833
7964
  const use = options.itemUse?.(def);
7834
- const contents = fluidOf({ ...def.model === void 0 ? {} : { model: def.model }, size: def.size, weight: def.weight });
7965
+ const held = itemFluid2(def);
7966
+ const contents = fluidOf({ ...def.model === void 0 ? {} : { model: def.model }, size: def.size, weight: def.weight, ...held ? { fluid: held } : {} });
7835
7967
  const liquid = sealOf(def, contents.fluid ? contents : vesselOf(def));
7836
7968
  if (!use) return liquid;
7837
7969
  const edible = def.category === "food" || def.category === "drink";
@@ -8313,7 +8445,7 @@ function scenariosOf(module, catalog, text, provider, modelSet) {
8313
8445
  run: ({ expect }) => {
8314
8446
  const food = catalog.list().find((item) => item.shelfLife !== void 0 && item.shelfLife > 0);
8315
8447
  if (!food) return expect(false, "the catalog has a food that spoils");
8316
- const at = (storage, days2) => freshness(food, { ageDays: 0, since: 0, storage, storedAt: 0 }, days2, { rules: catalog.rules });
8448
+ const at = (storage, days2) => freshness2(food, { ageDays: 0, since: 0, storage, storedAt: 0 }, days2, { rules: catalog.rules });
8317
8449
  const days = food.shelfLife * 1.2;
8318
8450
  expect(at("ambient", days) !== "fresh", "at room temperature it is past its best", { food: food.id });
8319
8451
  if ("fridge" in catalog.rules.storage) expect(at("fridge", days) !== at("ambient", days) || at("fridge", days) === "fresh", "in the fridge it keeps better", { food: food.id });
@@ -8338,6 +8470,8 @@ function scenariosOf(module, catalog, text, provider, modelSet) {
8338
8470
  export {
8339
8471
  WEAR_TAGS,
8340
8472
  createItemKit,
8473
+ wearOfFreshness,
8474
+ wearOfAge,
8341
8475
  WEAR_TARGET,
8342
8476
  WEAR_AMOUNT,
8343
8477
  wearableMaterials,
@@ -8408,4 +8542,4 @@ export {
8408
8542
  HUMAN_HEIGHT,
8409
8543
  createItemsTestModule
8410
8544
  };
8411
- //# sourceMappingURL=chunk-FCEKW7F6.js.map
8545
+ //# sourceMappingURL=chunk-PAQ3Q5I2.js.map