@adatechnology/game-items-three 0.12.0 → 0.14.0
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/{chunk-DBIE2ZMX.js → chunk-XJG7IGO3.js} +1541 -1218
- package/dist/chunk-XJG7IGO3.js.map +1 -0
- package/dist/index.d.ts +51 -7
- package/dist/index.global.js +1101 -495
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/dist/{testing-Y05TqYH8.d.ts → testing-C96KjBjB.d.ts} +7 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +13 -13
- package/dist/chunk-DBIE2ZMX.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CUP_FLOOR_SHARE,
|
|
2
3
|
DESTRUCTION_MATERIAL_BY_TAG,
|
|
3
4
|
FINDS_TABLE_ID,
|
|
4
5
|
HUMAN_HEIGHT,
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
SHIPPED_MODELS,
|
|
19
20
|
SHOWCASE_PREFIX,
|
|
20
21
|
SHOWCASE_STAND_ID,
|
|
22
|
+
WASH_NAME,
|
|
21
23
|
WEAR_AMOUNT,
|
|
22
24
|
WEAR_TAGS,
|
|
23
25
|
WEAR_TARGET,
|
|
@@ -44,12 +46,15 @@ import {
|
|
|
44
46
|
itemOpening,
|
|
45
47
|
itemThumbnail,
|
|
46
48
|
itemThumbnailSvg,
|
|
49
|
+
itemVessel,
|
|
47
50
|
listItemModels,
|
|
48
51
|
makeupSpec,
|
|
49
52
|
openItem,
|
|
50
53
|
registerItemModel,
|
|
51
54
|
registryOver,
|
|
52
55
|
renderItemThumbnail,
|
|
56
|
+
setItemDirt,
|
|
57
|
+
setItemFoam,
|
|
53
58
|
setOpeningContents,
|
|
54
59
|
setWear,
|
|
55
60
|
shade,
|
|
@@ -64,18 +69,26 @@ import {
|
|
|
64
69
|
triangleBudgetOf,
|
|
65
70
|
turnItem,
|
|
66
71
|
unregisterItemModel,
|
|
72
|
+
wearOfAge,
|
|
73
|
+
wearOfFreshness,
|
|
67
74
|
wearableMaterials
|
|
68
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-XJG7IGO3.js";
|
|
69
76
|
|
|
70
77
|
// src/contained.ts
|
|
71
78
|
function createContainedItemModel(items, options = {}) {
|
|
79
|
+
const { rules, ...build } = options;
|
|
72
80
|
const byId = /* @__PURE__ */ new Map();
|
|
73
81
|
for (const item of items) byId.set(item.id, item);
|
|
74
82
|
return (stack, T) => {
|
|
75
83
|
const item = byId.get(stack.type);
|
|
76
84
|
if (!item) return null;
|
|
77
|
-
const
|
|
85
|
+
const ageDays = stack.data?.["ageDays"];
|
|
86
|
+
const aged = typeof ageDays === "number" ? wearOfAge(item, ageDays, rules) : 0;
|
|
87
|
+
const wear = Math.max(build.wear ?? 0, aged);
|
|
88
|
+
const model = buildItem(T, item, wear > 0 ? { ...build, wear } : build);
|
|
78
89
|
model.root.userData.item = { id: item.id, kind: model.kind };
|
|
90
|
+
const dirt = stack.data?.["dirt"];
|
|
91
|
+
if (typeof dirt === "number" && dirt > 0) setItemDirt(T, model.root, dirt);
|
|
79
92
|
return model.root;
|
|
80
93
|
};
|
|
81
94
|
}
|
|
@@ -130,6 +143,7 @@ function createItemModels(options = {}) {
|
|
|
130
143
|
return models;
|
|
131
144
|
}
|
|
132
145
|
export {
|
|
146
|
+
CUP_FLOOR_SHARE,
|
|
133
147
|
DESTRUCTION_MATERIAL_BY_TAG,
|
|
134
148
|
FINDS_TABLE_ID,
|
|
135
149
|
HUMAN_HEIGHT,
|
|
@@ -149,6 +163,7 @@ export {
|
|
|
149
163
|
SHIPPED_MODELS,
|
|
150
164
|
SHOWCASE_PREFIX,
|
|
151
165
|
SHOWCASE_STAND_ID,
|
|
166
|
+
WASH_NAME,
|
|
152
167
|
WEAR_AMOUNT,
|
|
153
168
|
WEAR_TAGS,
|
|
154
169
|
WEAR_TARGET,
|
|
@@ -179,12 +194,15 @@ export {
|
|
|
179
194
|
itemOpening,
|
|
180
195
|
itemThumbnail,
|
|
181
196
|
itemThumbnailSvg,
|
|
197
|
+
itemVessel,
|
|
182
198
|
listItemModels,
|
|
183
199
|
makeupSpec,
|
|
184
200
|
mergeItem,
|
|
185
201
|
openItem,
|
|
186
202
|
registerItemModel,
|
|
187
203
|
renderItemThumbnail,
|
|
204
|
+
setItemDirt,
|
|
205
|
+
setItemFoam,
|
|
188
206
|
setOpeningContents,
|
|
189
207
|
setWear,
|
|
190
208
|
shade,
|
|
@@ -199,6 +217,8 @@ export {
|
|
|
199
217
|
triangleBudgetOf,
|
|
200
218
|
turnItem,
|
|
201
219
|
unregisterItemModel,
|
|
220
|
+
wearOfAge,
|
|
221
|
+
wearOfFreshness,
|
|
202
222
|
wearableMaterials
|
|
203
223
|
};
|
|
204
224
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contained.ts","../src/item-models.ts","../src/merge.ts","../src/lod.ts","../src/models/instance.ts"],"sourcesContent":["import type * as THREE_NS from 'three'\n\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem } from './build-item'\n\n/** A stack held in a container (`ItemStack` of game-interactables): the item id and its free data. */\nexport interface ContainedStack {\n readonly type: string\n}\n\n/** What `createContainedItemModel` returns: the real model of a stack drawn with the caller's `THREE`, or null for an id the catalogue does not have. */\nexport type ContainedItemModel = (stack: ContainedStack, T: typeof THREE_NS) => THREE_NS.Object3D | null\n\n/**\n * The model of the items inside furniture, for `createContentsView` of game-interactables-three and `interactives.itemModel` of game-floorplan-three: each\n * stack is drawn by `buildItem` from the catalogue (the team's model where there is one, the item's own shape otherwise), never a stand-in. Every item gets its\n * own materials, so the view can discard it alone when it is taken. `root.userData.item` says what was drawn (`{ id, kind }`).\n */\nexport function createContainedItemModel(items: Iterable<DrawableItem>, options: Omit<BuildItemOptions, 'kit'> = {}): ContainedItemModel {\n const byId = new Map<string, DrawableItem>()\n for (const item of items) byId.set(item.id, item)\n return (stack, T) => {\n const item = byId.get(stack.type)\n if (!item) return null\n const model = buildItem(T, item, options)\n model.root.userData.item = { id: item.id, kind: model.kind }\n return model.root\n }\n}\n","import { buildItem } from './build-item'\nimport { hasItemModel } from './models/registry'\n\n/** 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`. */\nexport const itemModels = { has: hasItemModel, build: buildItem } as const\n","import { mergeByMaterial } from '@adatechnology/game-shapes-three'\nimport type * as THREE_NS from 'three'\n\nimport type { ItemModel } from './build-item'\n\n/**\n * 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\n * 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.\n */\nexport function mergeItem(T: typeof THREE_NS, model: ItemModel): ItemModel {\n model.root.updateMatrixWorld(true)\n const merged = new T.Group()\n merged.name = model.root.name\n merged.scale.copy(model.root.scale)\n merged.userData = { ...model.root.userData }\n // baked into the space of the root, which leaves the root's own scale out of the geometry\n merged.add(...mergeByMaterial(T, model.root, model.root))\n return { ...model, root: merged }\n}\n","import type * as THREE_NS from 'three'\n\nimport { ITEM_BUDGETS, cullDistanceOf } from './budgets'\nimport type { ItemBudgets } from './budgets'\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from './build-item'\nimport { createItemKit } from './kit'\nimport { mergeItem } from './merge'\n\nexport interface ItemLodOptions extends Omit<BuildItemOptions, 'simple' | 'detail' | 'kit'> {\n budgets?: ItemBudgets\n /** Join the meshes of each level by material (default true). */\n merge?: boolean\n /** Distance of the second level in metres; default a third of the distance at which the item disappears. */\n lod1Distance?: number\n}\n\nexport interface ItemLod {\n /** Add this to the scene and call `update(camera)` (or let the renderer do it). */\n readonly root: THREE_NS.LOD\n /** Full detail: the showcase model, or the shape at full segments. */\n readonly near: ItemModel\n /** The simple shape at half the segments. */\n readonly far: ItemModel\n /** Metres from the camera at which the item is no longer drawn. */\n readonly cullDistance: number\n readonly lod1Distance: number\n}\n\n/**\n * Three levels of an item: the model (or the shape) up close, the simple shape at half the segments from `lod1Distance`, and nothing from the distance of its class\n * (a small item goes at 30 m, a large one at 60 m).\n */\nexport function buildItemLod(T: typeof THREE_NS, item: DrawableItem, options: ItemLodOptions = {}): ItemLod {\n const budgets = options.budgets ?? ITEM_BUDGETS\n const cullDistance = cullDistanceOf(item.size, budgets)\n const lod1Distance = options.lod1Distance ?? cullDistance / 3\n const joined = (model: ItemModel): ItemModel => (options.merge === false ? model : mergeItem(T, model))\n const wear = { ...(options.wear === undefined ? {} : { wear: options.wear }), ...(options.models === undefined ? {} : { models: options.models }) }\n const near = joined(buildItem(T, item, { ...wear, kit: createItemKit(T) }))\n const far = joined(buildItem(T, item, { ...wear, simple: true, detail: budgets.lod1Ratio, kit: createItemKit(T) }))\n const root = new T.LOD()\n root.name = item.id\n root.addLevel(near.root, 0)\n root.addLevel(far.root, lod1Distance)\n root.addLevel(new T.Group(), cullDistance)\n root.userData.wear = options.wear ?? 0\n return { root, near, far, cullDistance, lod1Distance }\n}\n","import { applyPatches, mergeById, removeIds } from '@adatechnology/game-contracts'\nimport type { DeepPartial, Thumbnail } from '@adatechnology/game-contracts'\nimport type * as THREE_NS from 'three'\n\nimport { buildItem } from '../build-item'\nimport { buildItemLod } from '../lod'\nimport type { ItemLod, ItemLodOptions } from '../lod'\nimport { itemThumbnail } from '../thumbnails'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from '../build-item'\nimport { registryOver } from './registry'\nimport type { ItemModelBuilder, ItemModelEntry, ItemModelRegistry } from './registry'\nimport { SHIPPED_MODELS } from './shipped'\n\nexport interface ItemModelRecord {\n readonly entry: ItemModelEntry\n readonly builder: ItemModelBuilder\n}\n\nexport interface ItemModelsOptions {\n /** Models added to the shipped ones; one with the id of a shipped model replaces it. */\n readonly packs?: readonly (readonly ItemModelRecord[])[]\n /** Changes to an entry by item id (`scale`, `teamBox`), merged field by field. */\n readonly patch?: Readonly<Record<string, DeepPartial<ItemModelEntry>>>\n /** Item ids whose model is taken out (the item then gets its simple shape). */\n readonly remove?: readonly string[]\n}\n\nexport interface ItemModels extends ItemModelRegistry {\n /** `buildItem` that reads this set of models. */\n build(T: typeof THREE_NS, item: DrawableItem, options?: Omit<BuildItemOptions, 'models'>): ItemModel\n /** `buildItemLod` that reads this set of models. */\n buildLod(T: typeof THREE_NS, item: DrawableItem, options?: Omit<ItemLodOptions, 'models'>): ItemLod\n /** `itemThumbnail` that asks this set whether the item has a model. */\n thumbnail(item: DrawableItem): Thumbnail\n}\n\ntype Keyed = ItemModelRecord & { readonly id: string }\n\n/** 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. */\nexport function createItemModels(options: ItemModelsOptions = {}): ItemModels {\n const keyed = (record: ItemModelRecord): Keyed => ({ ...record, id: record.entry.id })\n const records = mergeById(SHIPPED_MODELS.map(keyed), (options.packs ?? []).flat().map(keyed))\n applyPatches(records, Object.fromEntries(Object.entries(options.patch ?? {}).map(([id, entry]) => [id, { entry }])) as Readonly<Record<string, DeepPartial<Keyed>>>)\n removeIds(records, options.remove)\n const registry = registryOver(new Map([...records].map(([id, record]) => [id, record.entry])), new Map([...records].map(([id, record]) => [id, record.builder])))\n const models: ItemModels = {\n ...registry,\n build: (T, item, buildOptions = {}) => buildItem(T, item, { ...buildOptions, models: registry }),\n buildLod: (T, item, lodOptions = {}) => buildItemLod(T, item, { ...lodOptions, models: registry }),\n thumbnail: (item) => itemThumbnail(item, registry),\n }\n return models\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,SAAS,yBAAyB,OAA+B,UAAyC,CAAC,GAAuB;AACvI,QAAM,OAAO,oBAAI,IAA0B;AAC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AAQ,SAAS,CAAC;AAAA,IAC/F,UAAU,CAAC,GAAG,MAAM,aAAa,CAAC,MAAM,aAAa,GAAG,MAAM,EAAE,GAAG,YAAY,QAAQ,SAAS,CAAC;AAAA,IACjG,WAAW,CAAC,SAAS,cAAc,MAAM,QAAQ;AAAA,EACnD;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/contained.ts","../src/item-models.ts","../src/merge.ts","../src/lod.ts","../src/models/instance.ts"],"sourcesContent":["import type * as THREE_NS from 'three'\n\nimport type { ItemRules } from '@adatechnology/game-items'\n\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem } from './build-item'\nimport { setItemDirt } from './wash'\nimport { wearOfAge } from './wear'\nimport type { WearStage } from './wear'\n\n/** A stack held in a container (`ItemStack` of game-interactables): the item id and its free data (a find's age, `ageDays`). */\nexport interface ContainedStack {\n readonly type: string\n /** The stack's free data: `ageDays` (the age a find is rolled with) wears the item by its freshness, `dirt` (0 clean to 1 caked) draws the food left on it (a plate left dirty in a sink). */\n readonly data?: Readonly<Record<string, unknown>>\n}\n\n/** How a contained item is drawn: `buildItem`'s options, and the rules its age is read by (the catalogue's; the default rules when left out). */\nexport type ContainedItemOptions = Omit<BuildItemOptions, 'kit'> & { readonly rules?: ItemRules }\n\n/** What `createContainedItemModel` returns: the real model of a stack drawn with the caller's `THREE`, or null for an id the catalogue does not have. */\nexport type ContainedItemModel = (stack: ContainedStack, T: typeof THREE_NS) => THREE_NS.Object3D | null\n\n/**\n * The model of the items inside furniture, for `createContentsView` of game-interactables-three and `interactives.itemModel` of game-floorplan-three: each\n * stack is drawn by `buildItem` from the catalogue (the team's model where there is one, the item's own shape otherwise), never a stand-in. Every item gets its\n * own materials, so the view can discard it alone when it is taken. `root.userData.item` says what was drawn (`{ id, kind }`). A stack with an age (`data.ageDays`)\n * shows the wear of its freshness, and one with `data.dirt` is drawn dirty (`setItemDirt`), the same as the item once it is in the world.\n */\nexport function createContainedItemModel(items: Iterable<DrawableItem & { readonly shelfLife?: number }>, options: ContainedItemOptions = {}): ContainedItemModel {\n const { rules, ...build } = options\n const byId = new Map<string, DrawableItem & { readonly shelfLife?: number }>()\n for (const item of items) byId.set(item.id, item)\n return (stack, T) => {\n const item = byId.get(stack.type)\n if (!item) return null\n const ageDays = stack.data?.['ageDays']\n const aged = typeof ageDays === 'number' ? wearOfAge(item, ageDays, rules) : 0\n const wear = Math.max(build.wear ?? 0, aged) as WearStage\n const model = buildItem(T, item, wear > 0 ? { ...build, wear } : build)\n model.root.userData.item = { id: item.id, kind: model.kind }\n const dirt = stack.data?.['dirt']\n if (typeof dirt === 'number' && dirt > 0) setItemDirt(T, model.root, dirt)\n return model.root\n }\n}\n","import { buildItem } from './build-item'\nimport { hasItemModel } from './models/registry'\n\n/** 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`. */\nexport const itemModels = { has: hasItemModel, build: buildItem } as const\n","import { mergeByMaterial } from '@adatechnology/game-shapes-three'\nimport type * as THREE_NS from 'three'\n\nimport type { ItemModel } from './build-item'\n\n/**\n * 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\n * 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.\n */\nexport function mergeItem(T: typeof THREE_NS, model: ItemModel): ItemModel {\n model.root.updateMatrixWorld(true)\n const merged = new T.Group()\n merged.name = model.root.name\n merged.scale.copy(model.root.scale)\n merged.userData = { ...model.root.userData }\n // baked into the space of the root, which leaves the root's own scale out of the geometry\n merged.add(...mergeByMaterial(T, model.root, model.root))\n return { ...model, root: merged }\n}\n","import type * as THREE_NS from 'three'\n\nimport { ITEM_BUDGETS, cullDistanceOf } from './budgets'\nimport type { ItemBudgets } from './budgets'\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from './build-item'\nimport { createItemKit } from './kit'\nimport { mergeItem } from './merge'\n\nexport interface ItemLodOptions extends Omit<BuildItemOptions, 'simple' | 'detail' | 'kit'> {\n budgets?: ItemBudgets\n /** Join the meshes of each level by material (default true). */\n merge?: boolean\n /** Distance of the second level in metres; default a third of the distance at which the item disappears. */\n lod1Distance?: number\n}\n\nexport interface ItemLod {\n /** Add this to the scene and call `update(camera)` (or let the renderer do it). */\n readonly root: THREE_NS.LOD\n /** Full detail: the showcase model, or the shape at full segments. */\n readonly near: ItemModel\n /** The simple shape at half the segments. */\n readonly far: ItemModel\n /** Metres from the camera at which the item is no longer drawn. */\n readonly cullDistance: number\n readonly lod1Distance: number\n}\n\n/**\n * Three levels of an item: the model (or the shape) up close, the simple shape at half the segments from `lod1Distance`, and nothing from the distance of its class\n * (a small item goes at 30 m, a large one at 60 m).\n */\nexport function buildItemLod(T: typeof THREE_NS, item: DrawableItem, options: ItemLodOptions = {}): ItemLod {\n const budgets = options.budgets ?? ITEM_BUDGETS\n const cullDistance = cullDistanceOf(item.size, budgets)\n const lod1Distance = options.lod1Distance ?? cullDistance / 3\n const joined = (model: ItemModel): ItemModel => (options.merge === false ? model : mergeItem(T, model))\n const wear = { ...(options.wear === undefined ? {} : { wear: options.wear }), ...(options.models === undefined ? {} : { models: options.models }) }\n const near = joined(buildItem(T, item, { ...wear, kit: createItemKit(T) }))\n const far = joined(buildItem(T, item, { ...wear, simple: true, detail: budgets.lod1Ratio, kit: createItemKit(T) }))\n const root = new T.LOD()\n root.name = item.id\n root.addLevel(near.root, 0)\n root.addLevel(far.root, lod1Distance)\n root.addLevel(new T.Group(), cullDistance)\n root.userData.wear = options.wear ?? 0\n return { root, near, far, cullDistance, lod1Distance }\n}\n","import { applyPatches, mergeById, removeIds } from '@adatechnology/game-contracts'\nimport type { DeepPartial, Thumbnail } from '@adatechnology/game-contracts'\nimport type * as THREE_NS from 'three'\n\nimport { buildItem } from '../build-item'\nimport { buildItemLod } from '../lod'\nimport type { ItemLod, ItemLodOptions } from '../lod'\nimport { itemThumbnail } from '../thumbnails'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from '../build-item'\nimport { registryOver } from './registry'\nimport type { ItemModelBuilder, ItemModelEntry, ItemModelRegistry } from './registry'\nimport { SHIPPED_MODELS } from './shipped'\n\nexport interface ItemModelRecord {\n readonly entry: ItemModelEntry\n readonly builder: ItemModelBuilder\n}\n\nexport interface ItemModelsOptions {\n /** Models added to the shipped ones; one with the id of a shipped model replaces it. */\n readonly packs?: readonly (readonly ItemModelRecord[])[]\n /** Changes to an entry by item id (`scale`, `teamBox`), merged field by field. */\n readonly patch?: Readonly<Record<string, DeepPartial<ItemModelEntry>>>\n /** Item ids whose model is taken out (the item then gets its simple shape). */\n readonly remove?: readonly string[]\n}\n\nexport interface ItemModels extends ItemModelRegistry {\n /** `buildItem` that reads this set of models. */\n build(T: typeof THREE_NS, item: DrawableItem, options?: Omit<BuildItemOptions, 'models'>): ItemModel\n /** `buildItemLod` that reads this set of models. */\n buildLod(T: typeof THREE_NS, item: DrawableItem, options?: Omit<ItemLodOptions, 'models'>): ItemLod\n /** `itemThumbnail` that asks this set whether the item has a model. */\n thumbnail(item: DrawableItem): Thumbnail\n}\n\ntype Keyed = ItemModelRecord & { readonly id: string }\n\n/** 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. */\nexport function createItemModels(options: ItemModelsOptions = {}): ItemModels {\n const keyed = (record: ItemModelRecord): Keyed => ({ ...record, id: record.entry.id })\n const records = mergeById(SHIPPED_MODELS.map(keyed), (options.packs ?? []).flat().map(keyed))\n applyPatches(records, Object.fromEntries(Object.entries(options.patch ?? {}).map(([id, entry]) => [id, { entry }])) as Readonly<Record<string, DeepPartial<Keyed>>>)\n removeIds(records, options.remove)\n const registry = registryOver(new Map([...records].map(([id, record]) => [id, record.entry])), new Map([...records].map(([id, record]) => [id, record.builder])))\n const models: ItemModels = {\n ...registry,\n build: (T, item, buildOptions = {}) => buildItem(T, item, { ...buildOptions, models: registry }),\n buildLod: (T, item, lodOptions = {}) => buildItemLod(T, item, { ...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K,EAAE,IAAI,KAAK,CAAC;AAC5F,eAAa,SAAS,OAAO,YAAY,OAAO,QAAQ,QAAQ,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAiD;AACnK,YAAU,SAAS,QAAQ,MAAM;AACjC,QAAM,WAAW,aAAa,IAAI,IAAI,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,CAAC,IAAI,OAAO,KAAK,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,CAAC,IAAI,OAAO,OAAO,CAAC,CAAC,CAAC;AAChK,QAAM,SAAqB;AAAA,IACzB,GAAG;AAAA,IACH,OAAO,CAAC,GAAG,MAAM,eAAe,CAAC,MAAM,UAAU,GAAG,MAAM,EAAE,GAAG,cAAc,QAAQ,SAAS,CAAC;AAAA,IAC/F,UAAU,CAAC,GAAG,MAAM,aAAa,CAAC,MAAM,aAAa,GAAG,MAAM,EAAE,GAAG,YAAY,QAAQ,SAAS,CAAC;AAAA,IACjG,WAAW,CAAC,SAAS,cAAc,MAAM,QAAQ;AAAA,EACnD;AACA,SAAO;AACT;","names":[]}
|
|
@@ -55,8 +55,12 @@ interface ItemModelEntry {
|
|
|
55
55
|
/** Metres per unit of the page, from one real measure of the object. */
|
|
56
56
|
readonly scale: number;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* A builder of the showcase, ported as it is: it draws in the page's units and returns the group.
|
|
60
|
+
* It lives apart from `registry.ts` because the registry imports every builder (`shipped.ts`): a builder that took its type from the registry closed a cycle (`registry` → `shipped` → builder → `registry`).
|
|
61
|
+
*/
|
|
59
62
|
type ItemModelBuilder = (kit: ItemKit) => THREE_NS.Group;
|
|
63
|
+
|
|
60
64
|
/** The models of one registry: what `buildItem` reads through its `models` option. */
|
|
61
65
|
interface ItemModelRegistry {
|
|
62
66
|
has(id: string): boolean;
|
|
@@ -140,6 +144,8 @@ interface ItemsTestModuleOptions {
|
|
|
140
144
|
models?: ItemModelRegistry;
|
|
141
145
|
/** What an item does in the hand (eaten, taken, applied: `goodsItemUse` of game-items-goods); without it the items have only the uses of their liquid. */
|
|
142
146
|
itemUse?: (item: ItemDef) => ModuleItemUse | undefined;
|
|
147
|
+
/** Items that get dirty and are washed at a sink (they draw food left on them and foam); default the `kitchen` items that are not food. */
|
|
148
|
+
washable?: (item: ItemDef) => boolean;
|
|
143
149
|
}
|
|
144
150
|
declare const SHOWCASE_STAND_ID = "stand_models";
|
|
145
151
|
declare const RULER_ID = "ruler_155";
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FINDS_TABLE_ID, H as HUMAN_HEIGHT, d as HUMAN_ID, g as ItemsAreaState, h as ItemsTestModule, i as ItemsTestModuleOptions, j as RULER_HEIGHT, k as RULER_ID, n as SHOWCASE_STAND_ID, o as ScenarioLike, s as createItemsTestModule } from './testing-
|
|
1
|
+
export { F as FINDS_TABLE_ID, H as HUMAN_HEIGHT, d as HUMAN_ID, g as ItemsAreaState, h as ItemsTestModule, i as ItemsTestModuleOptions, j as RULER_HEIGHT, k as RULER_ID, n as SHOWCASE_STAND_ID, o as ScenarioLike, s as createItemsTestModule } from './testing-C96KjBjB.js';
|
|
2
2
|
import 'three';
|
|
3
3
|
import '@adatechnology/game-contracts';
|
|
4
4
|
import '@adatechnology/game-items';
|
package/dist/testing.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adatechnology/game-items-three",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "three.js presentation for @adatechnology/game-items: the 24 models of the Itens do Vale Cinzento showcase at real size, simple shapes at real size for every other item, wear (new, used, spoiled) on the materials, merge by material, LOD and the draw budgets of the team.",
|
|
6
6
|
"keywords": [
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@adatechnology/game-
|
|
46
|
-
"@adatechnology/game-
|
|
47
|
-
"@adatechnology/game-fluids": "^0.
|
|
48
|
-
"@adatechnology/game-interactables": "^0.
|
|
49
|
-
"@adatechnology/game-items": "^0.
|
|
50
|
-
"@adatechnology/game-shapes-three": "^0.5.
|
|
45
|
+
"@adatechnology/game-floorplan-three": "^12.0.0",
|
|
46
|
+
"@adatechnology/game-contracts": "^0.51.0",
|
|
47
|
+
"@adatechnology/game-fluids": "^0.8.0",
|
|
48
|
+
"@adatechnology/game-interactables": "^0.14.0",
|
|
49
|
+
"@adatechnology/game-items": "^0.9.0",
|
|
50
|
+
"@adatechnology/game-shapes-three": "^0.5.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"three": "^0.160.0"
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"tsup": "^8.5.1",
|
|
61
61
|
"typescript": "^5.7.3",
|
|
62
62
|
"vitest": "^3.2.4",
|
|
63
|
-
"@adatechnology/game-destruction": "^0.
|
|
64
|
-
"@adatechnology/game-destruction-three": "^1.10.
|
|
65
|
-
"@adatechnology/game-interactables-household": "^0.
|
|
66
|
-
"@adatechnology/game-
|
|
67
|
-
"@adatechnology/game-
|
|
63
|
+
"@adatechnology/game-destruction": "^0.38.1",
|
|
64
|
+
"@adatechnology/game-destruction-three": "^1.10.2",
|
|
65
|
+
"@adatechnology/game-interactables-household": "^0.10.0",
|
|
66
|
+
"@adatechnology/game-items-goods": "^0.9.0",
|
|
67
|
+
"@adatechnology/game-interactables-three": "^0.8.0",
|
|
68
68
|
"@adatechnology/game-physics": "^0.11.2",
|
|
69
69
|
"@adatechnology/game-physics-jolt": "^0.7.8",
|
|
70
|
-
"@adatechnology/game-test-room": "^1.
|
|
70
|
+
"@adatechnology/game-test-room": "^1.12.1",
|
|
71
71
|
"@adatechnology/golden-tool": "^0.0.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|