@adatechnology/game-items-three 0.6.2 → 0.7.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.d.ts CHANGED
@@ -1,46 +1,8 @@
1
+ import { V as Vec3Tuple, I as ItemKit, a as ItemModelRegistry, b as ItemModelEntry, c as ItemModelBuilder } from './testing-CBYX7wTL.js';
2
+ export { F as FINDS_TABLE_ID, H as HUMAN_HEIGHT, d as HUMAN_ID, e as ITEM_PREFIX, f as ItemMaterialData, g as ItemsAreaState, h as ItemsTestModule, i as ItemsTestModuleOptions, L as LayoutItem, R as ROW_LIMIT, j as RULER_HEIGHT, k as RULER_ID, S as SHELF_HEIGHT, l as SHELF_PREFIX, m as SHOWCASE_PREFIX, n as SHOWCASE_STAND_ID, o as ScenarioLike, p as ShelfPlan, W as WEAR_TAGS, q as WearTag, r as createItemKit, s as createItemsTestModule, t as defaultItemModels, u as hasItemModel, v as itemModelBuilder, w as itemModelEntry, x as listItemModels, y as registerItemModel, z as shelvesLayout, A as unregisterItemModel } from './testing-CBYX7wTL.js';
1
3
  import * as THREE_NS from 'three';
2
- import { ContainerSpec, Thumbnail, Vec3, AreaPlacement, TestableModule } from '@adatechnology/game-contracts';
3
- import { FindStack, ItemsCatalog, FindsProvider } from '@adatechnology/game-items';
4
-
5
- type Three = typeof THREE_NS;
6
- /** The material tags the team's showcase wears: what `setWear` turns toward its spoiled colour. */
7
- declare const WEAR_TAGS: readonly ["metal", "wood", "cloth", "plastic", "paper", "food", "glass"];
8
- type WearTag = (typeof WEAR_TAGS)[number];
9
- /** What a material of the kit remembers so that `setWear` can go back to new: the colour it was made with (as three read it, and as sRGB floats), its tag and its roughness. */
10
- interface ItemMaterialData {
11
- base: THREE_NS.Color;
12
- baseRgb: readonly [number, number, number];
13
- tag: string;
14
- rough: number;
15
- }
16
- type Vec3Tuple = readonly [number, number, number];
17
- /**
18
- * The helpers the showcase page defines before its models (`M`, `mesh`, `cyl`, `bx`, `lathe`, `torus`, `extrude`, `G` and the seven material makers), so that the
19
- * builders ported from the page read the same as the originals. `T` is the three.js the kit was made with, with its box, cylinder, cone, sphere, plane, lathe, torus and
20
- * (straight-edged) extrude geometries made by game-shapes (`shapeGeometries`: the same bytes, the same classes, a template cache); `materials` lists every material it made,
21
- * in order.
22
- */
23
- interface ItemKit {
24
- readonly T: Three;
25
- readonly materials: THREE_NS.MeshStandardMaterial[];
26
- M(color: number, tag: string, options?: THREE_NS.MeshStandardMaterialParameters): THREE_NS.MeshStandardMaterial;
27
- mesh(geometry: THREE_NS.BufferGeometry, material: THREE_NS.Material, position?: Vec3Tuple, rotation?: Vec3Tuple, scale?: Vec3Tuple): THREE_NS.Mesh;
28
- cyl(radiusTop: number, radiusBottom: number, height: number, segments?: number): THREE_NS.CylinderGeometry;
29
- bx(width: number, height: number, depth: number): THREE_NS.BoxGeometry;
30
- lathe(points: ReadonlyArray<readonly [number, number]>, segments?: number): THREE_NS.LatheGeometry;
31
- torus(radius: number, tube: number, arc?: number): THREE_NS.TorusGeometry;
32
- extrude(points: ReadonlyArray<readonly [number, number]>, depth: number, bevel?: number): THREE_NS.ExtrudeGeometry;
33
- G(...children: THREE_NS.Object3D[]): THREE_NS.Group;
34
- metal(color: number): THREE_NS.MeshStandardMaterial;
35
- wood(color: number): THREE_NS.MeshStandardMaterial;
36
- cloth(color: number): THREE_NS.MeshStandardMaterial;
37
- plastic(color: number): THREE_NS.MeshStandardMaterial;
38
- paper(color: number): THREE_NS.MeshStandardMaterial;
39
- food(color: number): THREE_NS.MeshStandardMaterial;
40
- glass(color: number, opacity: number): THREE_NS.MeshStandardMaterial;
41
- }
42
- /** The helpers of the showcase page on a given three.js; every kit has its own list of materials. */
43
- declare function createItemKit(three: Three): ItemKit;
4
+ import { ContainerSpec, Thumbnail, DeepPartial } from '@adatechnology/game-contracts';
5
+ import '@adatechnology/game-items';
44
6
 
45
7
  /** 0 new, 1 used, 2 spoiled (the three stages of the showcase). */
46
8
  type WearStage = 0 | 1 | 2;
@@ -121,6 +83,8 @@ interface BuildItemOptions {
121
83
  destructible?: boolean;
122
84
  /** A kit to draw with (and to collect the materials in); default a new one. */
123
85
  kit?: ItemKit;
86
+ /** The models to draw with; default the shared set behind `registerItemModel` (`createItemModels` makes one of your own). */
87
+ models?: ItemModelRegistry;
124
88
  }
125
89
  /** What `buildItem` returns. */
126
90
  interface ItemModel {
@@ -270,6 +234,12 @@ declare function turnItem(root: THREE_NS.Object3D, modelId: string, state: {
270
234
  /** Shows how much is left in an opened item: the food inside the rim shrinks with `share` (0..1 of what it held) and is gone when it is eaten up. */
271
235
  declare function setOpeningContents(root: THREE_NS.Object3D, share: number): void;
272
236
 
237
+ /** The item models as a source a weapon or an explosive can draw with (`ItemModels` of game-weapons-three): a host lends it as `items`. */
238
+ declare const itemModels: {
239
+ readonly has: (id: string) => boolean;
240
+ readonly build: typeof buildItem;
241
+ };
242
+
273
243
  /**
274
244
  * The same item with its meshes joined by material: one mesh and one draw call per material instead of one per part (the "one material for all the items" of the page's
275
245
  * budget, as far as the materials of the kit allow). The materials are the same objects, so `setWear` still reaches them. The model's scale stays on the root.
@@ -339,28 +309,28 @@ interface ItemLod {
339
309
  */
340
310
  declare function buildItemLod(T: typeof THREE_NS, item: DrawableItem, options?: ItemLodOptions): ItemLod;
341
311
 
342
- /** One model of the showcase as `data/models.json` keeps it: the item it draws, the id the team gave it, the box it has in the units of the page and the scale to metres. */
343
- interface ItemModelEntry {
344
- /** Catalog id of the item (`canned_beans`). */
345
- readonly id: string;
346
- /** The id in the team's `MODELS` (`feijao_lata`). */
347
- readonly teamId: string;
348
- /** Box of the builder's group in the page's units (`Box3.setFromObject`), x y z. */
349
- readonly teamBox: readonly [number, number, number];
350
- /** Metres per unit of the page, from one real measure of the object. */
351
- readonly scale: number;
312
+ interface ItemModelRecord {
313
+ readonly entry: ItemModelEntry;
314
+ readonly builder: ItemModelBuilder;
315
+ }
316
+ interface ItemModelsOptions {
317
+ /** Models added to the shipped ones; one with the id of a shipped model replaces it. */
318
+ readonly packs?: readonly (readonly ItemModelRecord[])[];
319
+ /** Changes to an entry by item id (`scale`, `teamBox`), merged field by field. */
320
+ readonly patch?: Readonly<Record<string, DeepPartial<ItemModelEntry>>>;
321
+ /** Item ids whose model is taken out (the item then gets its simple shape). */
322
+ readonly remove?: readonly string[];
323
+ }
324
+ interface ItemModels extends ItemModelRegistry {
325
+ /** `buildItem` that reads this set of models. */
326
+ build(T: typeof THREE_NS, item: DrawableItem, options?: Omit<BuildItemOptions, 'models'>): ItemModel;
327
+ /** `buildItemLod` that reads this set of models. */
328
+ buildLod(T: typeof THREE_NS, item: DrawableItem, options?: Omit<ItemLodOptions, 'models'>): ItemLod;
329
+ /** `itemThumbnail` that asks this set whether the item has a model. */
330
+ thumbnail(item: DrawableItem): Thumbnail;
352
331
  }
353
- /** A builder of the showcase, ported as it is: it draws in the page's units and returns the group. */
354
- type ItemModelBuilder = (kit: ItemKit) => THREE_NS.Group;
355
- /** Adds (or replaces) the model of an item: `entry.id` is the catalog id the item's `model` field names. */
356
- declare function registerItemModel(entry: ItemModelEntry, builder: ItemModelBuilder): void;
357
- /** Takes a model out (a game that wants the simple shape instead). */
358
- declare function unregisterItemModel(id: string): void;
359
- declare const itemModelEntry: (id: string) => ItemModelEntry | undefined;
360
- declare const itemModelBuilder: (id: string) => ItemModelBuilder | undefined;
361
- declare const hasItemModel: (id: string) => boolean;
362
- /** The ids of the models registered, in the order of registration (the order of the showcase for the ones the kit ships). */
363
- declare const listItemModels: () => string[];
332
+ /** A set of item models of its own: the shipped ones plus `packs`, `patch` and `remove`. Nothing is shared with any other set on the page. */
333
+ declare function createItemModels(options?: ItemModelsOptions): ItemModels;
364
334
 
365
335
  /** The 24 models of the showcase in the page's order: the entry of `data/models.json` (generated by `tools/items-catalog`) and the builder ported from the page. */
366
336
  declare const SHIPPED_MODELS: ReadonlyArray<{
@@ -381,11 +351,11 @@ declare function shapeThumbnailSvg(shape: ShapeId, color?: number): string;
381
351
  * The picture of an item for catalogues and inventories: an item that has a 3D model asks the host to draw it (`render: true`), every other gets the SVG of its shape in
382
352
  * its colour.
383
353
  */
384
- declare function itemThumbnail(item: DrawableItem): Thumbnail;
354
+ declare function itemThumbnail(item: DrawableItem, models?: ItemModelRegistry): Thumbnail;
385
355
  /** The SVG of an item whatever it has: its shape in its colour (what a host with no renderer shows for a modeled item). */
386
356
  declare const itemThumbnailSvg: (item: DrawableItem) => string;
387
357
  /** `{ id: { thumbnail } }` for `createItems({ patch })`, so that a catalog carries its pictures. */
388
- declare function thumbnailPatch(items: Iterable<DrawableItem>): Record<string, {
358
+ declare function thumbnailPatch(items: Iterable<DrawableItem>, models?: ItemModelRegistry): Record<string, {
389
359
  thumbnail: Thumbnail;
390
360
  }>;
391
361
  interface ThumbnailRenderOptions {
@@ -397,6 +367,8 @@ interface ThumbnailRenderOptions {
397
367
  /** Multiplies the distance that just fits the item (default 1). */
398
368
  distance?: number;
399
369
  wear?: WearStage;
370
+ /** The models to draw with; default the shared set behind `registerItemModel`. */
371
+ models?: ItemModelRegistry;
400
372
  }
401
373
  interface ThumbnailScene {
402
374
  scene: THREE_NS.Scene;
@@ -413,113 +385,10 @@ interface ThumbnailRenderer {
413
385
  toDataURL(type?: string): string;
414
386
  };
415
387
  }
416
- /** Draws the item with the host's renderer and returns the PNG as a data URL (transparent background). */
417
- declare function renderItemThumbnail(T: typeof THREE_NS, renderer: ThumbnailRenderer, item: DrawableItem, options?: ThumbnailRenderOptions): string;
418
-
419
- /** What the layout needs of an item: its id, category and real size [width, height, depth] in metres. */
420
- interface LayoutItem {
421
- readonly id: string;
422
- readonly category: string;
423
- readonly size: readonly [number, number, number];
424
- }
425
- /** Height of the top of a shelf, metres. */
426
- declare const SHELF_HEIGHT = 0.9;
427
- /** Longest row of items on a shelf, metres. */
428
- declare const ROW_LIMIT = 5;
429
- /** One shelf: a category's items laid out in rows at real size, the shelf's footprint and where its items sit on its top. */
430
- interface ShelfPlan {
431
- category: string;
432
- /** Item id of the shelf in the module (`shelf_<category>`). */
433
- id: string;
434
- /** Footprint on the floor: length along x, depth along z. */
435
- length: number;
436
- depth: number;
437
- position: Vec3;
438
- /** Where each item sits, in world coordinates. */
439
- items: AreaPlacement[];
440
- }
441
- declare const SHELF_PREFIX = "shelf_";
442
- declare const ITEM_PREFIX = "item_";
443
- declare const SHOWCASE_PREFIX = "showcase_";
444
388
  /**
445
- * The shelves of the area: one per category, in the order the categories come, with every item of the category side by side at real size, wrapped in rows of at most
446
- * `ROW_LIMIT` metres. Shelves stand in a grid of four columns; an item that is longer than the row limit gets a row to itself. Pure: the same items always land in the same spots.
389
+ * Draws the item with the host's renderer and returns the PNG as a data URL (transparent background). The scene has lights of its own (the one allowlisted place for them, see `eslint.config.mjs`),
390
+ * so pass a renderer made for thumbnails, never the game's: its lights would link programs on the game's renderer, which `ProgramWarmup.linkedSince` shows.
447
391
  */
448
- declare function shelvesLayout(items: readonly LayoutItem[], categories: readonly string[]): ShelfPlan[];
449
-
450
- interface ItemsTestModuleOptions {
451
- /** The catalog to lay out (for example `createGoodsItems()` of `game-items-goods`). The module knows no content of its own. */
452
- catalog: ItemsCatalog;
453
- /** `en` or `pt-BR` (default). */
454
- locale?: string;
455
- /** Text of a key such as `item.canned_beans`, `place.house`, `category.food`, `container.fridge`, `recipe.stew` (the goods package has them in `goodsText`); without it the module falls back to the id. */
456
- translate?: (key: string, locale: string) => string | undefined;
457
- /** Seed of the finds roll (default 1). */
458
- seed?: number;
459
- /** Wear the items start with: `new` (default), `used` or `spoiled`. */
460
- wear?: string;
461
- /** The finds provider; default the one of `game-items` over `catalog`. A game gives its own (floorplan bindings, pools). */
462
- provider?: FindsProvider;
463
- /**
464
- * Draws a person of the kit to judge the scale by (for example a survivor of `createPersonBuilder` of `game-characters-three`); the module brings it to 1.80 m. Without it
465
- * the area shows the ruler alone.
466
- */
467
- person?: (THREE: unknown) => THREE_NS.Object3D;
468
- }
469
- declare const SHOWCASE_STAND_ID = "stand_models";
470
- declare const RULER_ID = "ruler_155";
471
- declare const HUMAN_ID = "human_180";
472
- declare const FINDS_TABLE_ID = "finds_table";
473
- declare const RULER_HEIGHT = 1.55;
474
- declare const HUMAN_HEIGHT = 1.8;
475
- /** What the scenarios of the area ask of the module (and what a host or a test may read). */
476
- interface ItemsAreaState {
477
- readonly category: string;
478
- readonly wear: string;
479
- readonly ageDays: number;
480
- readonly storage: string;
481
- readonly powered: boolean;
482
- readonly place: string;
483
- readonly container: string;
484
- readonly state: string;
485
- readonly day: number;
486
- readonly seed: number;
487
- readonly recipe: string;
488
- }
489
- interface ItemsTestModule extends TestableModule {
490
- /** Everything the module has put in the scene so far, with what was measured when it was drawn. */
491
- placed(): ReadonlyArray<{
492
- id: string;
493
- itemId: string;
494
- group: 'shelf' | 'showcase';
495
- kind: 'model' | 'shape';
496
- size: readonly [number, number, number];
497
- root: THREE_NS.Object3D;
498
- }>;
499
- /** The stacks now on the finds table. */
500
- finds(): readonly FindStack[];
501
- /** The shelves of the layout. */
502
- shelves(): readonly ShelfPlan[];
503
- readonly state: ItemsAreaState;
504
- /** The bench actions, callable without a host (what the buttons do). */
505
- rollFinds(): readonly FindStack[];
506
- craftSelected(): {
507
- ok: boolean;
508
- missing: readonly string[];
509
- };
510
- selectRecipe(id: string): void;
511
- /** The box of a drawn object, metres [x, y, z] (needs the host's three.js namespace: null before the module is attached or an item built). */
512
- measure(root: THREE_NS.Object3D): [number, number, number] | null;
513
- }
514
- /**
515
- * The items test area as a `TestableModule` of @adatechnology/game-contracts: every item of a catalog on shelves by category at real size (the real model of the team where there is
516
- * one, the simple shape of its category elsewhere), a stand where the 24 models turn, a ruler and a human figure to judge the scale, and a table where the finds of a container
517
- * and the result of a recipe are laid. The bench sets wear, age and storage, the place, container, state, outbreak day and seed of the finds, and the recipe.
518
- */
519
- declare function createItemsTestModule(options: ItemsTestModuleOptions): ItemsTestModule;
520
- /** What the scenarios use of the context the test room passes (`ScenarioContext`). */
521
- interface ScenarioLike {
522
- expect(condition: boolean, label: string, data?: Record<string, unknown>): void;
523
- }
392
+ declare function renderItemThumbnail(T: typeof THREE_NS, renderer: ThumbnailRenderer, item: DrawableItem, options?: ThumbnailRenderOptions): string;
524
393
 
525
- export { type BudgetReport, type BuildItemOptions, type ContentsSubject, DESTRUCTION_MATERIAL_BY_TAG, type DestructionTagOptions, type DrawableItem, FINDS_TABLE_ID, HUMAN_HEIGHT, HUMAN_ID, ITEM_BUDGETS, ITEM_FAMILIES, ITEM_PREFIX, type ItemBudgets, type ItemContents, type ItemDestruction, type ItemFamily, type ItemKit, type ItemLod, type ItemLodOptions, type ItemMaterialData, type ItemModel, type ItemModelBuilder, type ItemModelEntry, type ItemOpening, type ItemOpeningStyle, type ItemSizeClass, type ItemsAreaState, type ItemsTestModule, type ItemsTestModuleOptions, type LayoutItem, MODEL_BUDGET_DEVIATIONS, OPENING_NAME, ROW_LIMIT, RULER_HEIGHT, RULER_ID, SHAPES, SHELF_HEIGHT, SHELF_PREFIX, SHELL_PART_ID, SHIPPED_MODELS, SHOWCASE_PREFIX, SHOWCASE_STAND_ID, type ScenarioLike, type ShapeContext, type ShapeId, type ShapeSubject, type ShelfPlan, type ThumbnailRenderOptions, type ThumbnailRenderer, type ThumbnailScene, type Vec3Like, type Vec3Tuple, WEAR_AMOUNT, WEAR_TAGS, WEAR_TARGET, type WearStage, type WearTag, asLid, buildItem, buildItemLod, canonicalFrame, checkBudget, composeThumbnailScene, countDrawCalls, countTriangles, createItemKit, createItemsTestModule, cullDistanceOf, drawShape, hasItemModel, isShape, itemContents, itemDestruction, itemFamily, itemModelBuilder, itemModelEntry, itemOpening, itemThumbnail, itemThumbnailSvg, listItemModels, mergeItem, openItem, registerItemModel, renderItemThumbnail, setOpeningContents, setWear, shade, shapeDestruction, shapeOf, shapeThumbnailSvg, shelvesLayout, sizeClassOf, tagForDestruction, thumbnailPatch, triangleBudgetOf, turnItem, unregisterItemModel, wearableMaterials };
394
+ export { type BudgetReport, type BuildItemOptions, type ContentsSubject, DESTRUCTION_MATERIAL_BY_TAG, type DestructionTagOptions, type DrawableItem, ITEM_BUDGETS, ITEM_FAMILIES, type ItemBudgets, type ItemContents, type ItemDestruction, type ItemFamily, ItemKit, type ItemLod, type ItemLodOptions, type ItemModel, ItemModelBuilder, ItemModelEntry, type ItemModelRecord, ItemModelRegistry, type ItemModels, type ItemModelsOptions, type ItemOpening, type ItemOpeningStyle, type ItemSizeClass, MODEL_BUDGET_DEVIATIONS, OPENING_NAME, SHAPES, SHELL_PART_ID, SHIPPED_MODELS, type ShapeContext, type ShapeId, type ShapeSubject, type ThumbnailRenderOptions, type ThumbnailRenderer, type ThumbnailScene, type Vec3Like, Vec3Tuple, WEAR_AMOUNT, WEAR_TARGET, type WearStage, asLid, buildItem, buildItemLod, canonicalFrame, checkBudget, composeThumbnailScene, countDrawCalls, countTriangles, createItemModels, cullDistanceOf, drawShape, isShape, itemContents, itemDestruction, itemFamily, itemModels, itemOpening, itemThumbnail, itemThumbnailSvg, mergeItem, openItem, renderItemThumbnail, setOpeningContents, setWear, shade, shapeDestruction, shapeOf, shapeThumbnailSvg, sizeClassOf, tagForDestruction, thumbnailPatch, triangleBudgetOf, turnItem, wearableMaterials };