@operato/scene-storage 10.0.0-beta.41 → 10.0.0-beta.42

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/MIGRATION-plan-a-slot-api.md +266 -0
  3. package/PLAN-A-rack-as-slot-holder.md +164 -0
  4. package/dist/crane.js +1 -1
  5. package/dist/crane.js.map +1 -1
  6. package/dist/index.d.ts +3 -4
  7. package/dist/index.js +1 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/rack-grid-3d.d.ts +18 -7
  10. package/dist/rack-grid-3d.js +372 -69
  11. package/dist/rack-grid-3d.js.map +1 -1
  12. package/dist/rack-grid-cell.d.ts +21 -72
  13. package/dist/rack-grid-cell.js +147 -243
  14. package/dist/rack-grid-cell.js.map +1 -1
  15. package/dist/rack-grid.d.ts +277 -56
  16. package/dist/rack-grid.js +1230 -695
  17. package/dist/rack-grid.js.map +1 -1
  18. package/dist/rack-materials.d.ts +9 -0
  19. package/dist/rack-materials.js +55 -0
  20. package/dist/rack-materials.js.map +1 -0
  21. package/dist/storage-rack-3d.d.ts +15 -0
  22. package/dist/storage-rack-3d.js +131 -30
  23. package/dist/storage-rack-3d.js.map +1 -1
  24. package/dist/storage-rack.d.ts +242 -45
  25. package/dist/storage-rack.js +684 -106
  26. package/dist/storage-rack.js.map +1 -1
  27. package/package.json +3 -3
  28. package/src/crane.ts +1 -1
  29. package/src/index.ts +3 -4
  30. package/src/rack-grid-3d.ts +383 -80
  31. package/src/rack-grid-cell.ts +161 -305
  32. package/src/rack-grid.ts +1263 -762
  33. package/src/rack-materials.ts +61 -0
  34. package/src/storage-rack-3d.ts +144 -30
  35. package/src/storage-rack.ts +763 -111
  36. package/test/test-carrier-lifecycle.ts +361 -0
  37. package/test/test-coord-alignment.ts +201 -0
  38. package/test/test-external-to-rack.ts +461 -0
  39. package/test/test-mover-concurrent-bug.ts +304 -0
  40. package/test/test-mover-rollback.ts +290 -0
  41. package/test/test-r19-place-absorb.ts +174 -0
  42. package/test/test-rack-3d-attach-real.ts +301 -0
  43. package/test/test-rack-concurrent.ts +254 -0
  44. package/test/test-rack-edge-cases.ts +323 -0
  45. package/test/test-rack-grid-cell.ts +318 -0
  46. package/test/test-rack-grid-location.ts +657 -0
  47. package/test/test-real-3d-positioning.ts +158 -0
  48. package/test/test-slot-center-convention.ts +116 -0
  49. package/test/test-slot-target.ts +189 -0
  50. package/test/test-storage-rack-batched.ts +606 -0
  51. package/test/test-storage-rack-click.ts +329 -0
  52. package/test/test-storage-rack-slot-api.ts +357 -0
  53. package/test/test-toscene-convention.ts +162 -0
  54. package/test/test-user-scenario-sequential.ts +334 -0
  55. package/translations/en.json +2 -0
  56. package/translations/ja.json +2 -0
  57. package/translations/ko.json +2 -0
  58. package/translations/ms.json +2 -0
  59. package/translations/zh.json +2 -0
  60. package/tsconfig.tsbuildinfo +1 -1
  61. package/dist/rack-column.d.ts +0 -35
  62. package/dist/rack-column.js +0 -258
  63. package/dist/rack-column.js.map +0 -1
  64. package/dist/rack-grid-helpers.d.ts +0 -28
  65. package/dist/rack-grid-helpers.js +0 -71
  66. package/dist/rack-grid-helpers.js.map +0 -1
  67. package/dist/rack-grid-location.d.ts +0 -37
  68. package/dist/rack-grid-location.js +0 -227
  69. package/dist/rack-grid-location.js.map +0 -1
  70. package/dist/storage-cell-3d.d.ts +0 -25
  71. package/dist/storage-cell-3d.js +0 -88
  72. package/dist/storage-cell-3d.js.map +0 -1
  73. package/dist/storage-cell.d.ts +0 -73
  74. package/dist/storage-cell.js +0 -215
  75. package/dist/storage-cell.js.map +0 -1
  76. package/src/rack-column.ts +0 -340
  77. package/src/rack-grid-helpers.ts +0 -77
  78. package/src/rack-grid-location.ts +0 -286
  79. package/src/storage-cell-3d.ts +0 -101
  80. package/src/storage-cell.ts +0 -267
  81. package/test/test-cell-position.ts +0 -105
  82. package/test/test-rack-grid.ts +0 -77
@@ -1,286 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- *
4
- * RackGrid location management utilities.
5
- * Extracted from rack-table.ts for separation of concerns.
6
- */
7
-
8
- import type { RackGridCell } from './rack-grid-cell.js'
9
-
10
- /**
11
- * Classify cells by their row index.
12
- */
13
- export function classifyByRow(cells: RackGridCell[]): RackGridCell[][] {
14
- const classified: RackGridCell[][] = []
15
-
16
- cells.forEach(c => {
17
- const { row, column } = c.index
18
-
19
- if (!classified[row]) {
20
- classified[row] = []
21
- }
22
-
23
- classified[row][column] = c
24
- })
25
-
26
- return classified
27
- }
28
-
29
- /**
30
- * Find aisle rows (rows where all cells are empty).
31
- */
32
- export function findAisle(rows?: RackGridCell[][]): RackGridCell[][] {
33
- if (!rows) {
34
- return []
35
- }
36
-
37
- return rows.filter(r => {
38
- return r[0] && r[0].isAisle
39
- })
40
- }
41
-
42
- /**
43
- * Get indices of aisle rows.
44
- */
45
- export function getAisleRowIndices(rows: RackGridCell[][]): number[] {
46
- const aisles = findAisle(rows)
47
- const aisleRowIndices: number[] = []
48
-
49
- aisles.forEach(aisle => {
50
- aisleRowIndices.push(rows.indexOf(aisle))
51
- })
52
-
53
- return aisleRowIndices
54
- }
55
-
56
- /**
57
- * Classify rows into sections separated by aisle rows.
58
- */
59
- export function classifyCellsBySection(
60
- rows: RackGridCell[][],
61
- aisleRowIndices: number[]
62
- ): RackGridCell[][][] {
63
- const sections: RackGridCell[][][] = []
64
- let wasAisle = false
65
- let section!: RackGridCell[][]
66
-
67
- rows.forEach((row, i) => {
68
- const isAisle = aisleRowIndices.indexOf(i) > -1
69
-
70
- if (!(wasAisle || isAisle)) {
71
- section = []
72
- sections.push(section)
73
- }
74
-
75
- wasAisle = isAisle
76
-
77
- section.push(row)
78
- })
79
-
80
- return sections
81
- }
82
-
83
- /**
84
- * Rearrange cells by aisle direction pattern.
85
- */
86
- export function rearrangeByAisle(type: string, sections: RackGridCell[][][]): RackGridCell[][][] {
87
- const rearranged: RackGridCell[][][] = []
88
-
89
- switch (type.toLowerCase()) {
90
- case 'cw': {
91
- let reverse = false
92
- sections.forEach(rows => {
93
- const section: RackGridCell[][] = []
94
- rearranged.push(section)
95
- rows.forEach((r, i) => {
96
- if (reverse) r.reverse()
97
-
98
- if (i % 2 === 0) {
99
- section.push(r)
100
- reverse = !reverse
101
- }
102
- })
103
- })
104
- break
105
- }
106
- case 'ccw': {
107
- let reverse = true
108
- sections.forEach(rows => {
109
- const section: RackGridCell[][] = []
110
- rearranged.push(section)
111
- rows.forEach((r, i) => {
112
- if (reverse) r.reverse()
113
-
114
- if (i % 2 === 0) {
115
- section.push(r)
116
- reverse = !reverse
117
- }
118
- })
119
- })
120
- break
121
- }
122
- case 'zigzag':
123
- sections.forEach(rows => {
124
- const section: RackGridCell[][] = []
125
-
126
- rows.forEach((r, i) => {
127
- if (i % 2 === 0) {
128
- section.push(r)
129
- }
130
- })
131
-
132
- const sectionLength = section.length
133
- const tempRow: RackGridCell[] = []
134
- const tempSection: RackGridCell[][] = []
135
-
136
- section.forEach((row, rowIdx) => {
137
- row.forEach((cell, idx) => {
138
- tempRow[rowIdx + idx * section.length] = cell
139
- })
140
- })
141
-
142
- const chunkSize = tempRow.length / sectionLength
143
- for (let idx = 0; idx < sectionLength; idx++) {
144
- tempSection.push(tempRow.slice(idx * chunkSize, (idx + 1) * chunkSize))
145
- }
146
-
147
- rearranged.push(tempSection)
148
- })
149
- break
150
- case 'zigzag-reverse':
151
- sections.forEach(rows => {
152
- const section: RackGridCell[][] = []
153
-
154
- rows.forEach((r, i) => {
155
- if (i % 2 === 0) {
156
- r.reverse()
157
- section.push(r)
158
- }
159
- })
160
-
161
- const sectionLength = section.length
162
- const tempRow: RackGridCell[] = []
163
- const tempSection: RackGridCell[][] = []
164
-
165
- section.forEach((row, rowIdx) => {
166
- row.forEach((cell, idx) => {
167
- tempRow[rowIdx + idx * section.length] = cell
168
- })
169
- })
170
-
171
- const chunkSize = tempRow.length / sectionLength
172
- for (let idx = 0; idx < sectionLength; idx++) {
173
- tempSection.push(tempRow.slice(idx * chunkSize, (idx + 1) * chunkSize))
174
- }
175
-
176
- rearranged.push(tempSection)
177
- })
178
- break
179
- }
180
-
181
- return rearranged
182
- }
183
-
184
- /**
185
- * Remove empty cells from sections.
186
- */
187
- export function removeEmptyCells(sections: RackGridCell[][][]): RackGridCell[][][] {
188
- const newSections: RackGridCell[][][] = []
189
- sections.forEach(rows => {
190
- const newRows: RackGridCell[][] = []
191
- newSections.push(newRows)
192
- rows.forEach(row => {
193
- const newRow: RackGridCell[] = []
194
- newRows.push(newRow)
195
- row.forEach(c => {
196
- if (!c.isEmpty) newRow.push(c)
197
- })
198
- })
199
- })
200
-
201
- return newSections
202
- }
203
-
204
- /**
205
- * Merge section rows into flat arrays.
206
- */
207
- export function mergeRows(sections: RackGridCell[][][]): RackGridCell[][] {
208
- const merged: RackGridCell[][] = []
209
-
210
- sections.forEach(section => {
211
- let newSection: RackGridCell[] = []
212
-
213
- section.forEach(rows => {
214
- let mergedRow: RackGridCell[] = []
215
- rows.forEach(row => {
216
- mergedRow = mergedRow.concat(row)
217
- })
218
- newSection = newSection.concat(mergedRow)
219
- })
220
- merged.push(newSection)
221
- })
222
-
223
- return merged
224
- }
225
-
226
- /**
227
- * Set section/unit location on cells.
228
- */
229
- export function setLocations(
230
- sections: RackGridCell[][],
231
- startSection: number,
232
- startUnit: number,
233
- sectionDigits: number,
234
- unitDigits: number
235
- ) {
236
- let sectionNumber = Number(startSection) || 1
237
-
238
- sections.forEach(section => {
239
- let unitNumber = Number(startUnit) || 1
240
- section.forEach(c => {
241
- if (!c.isEmpty) {
242
- c.set('section', String(sectionNumber).padStart(sectionDigits, '0'))
243
- c.set('unit', String(unitNumber).padStart(unitDigits, '0'))
244
- } else {
245
- c.set('section', null)
246
- c.set('unit', null)
247
- }
248
- unitNumber++
249
- })
250
- sectionNumber++
251
- })
252
- }
253
-
254
- /**
255
- * Run the full location increase flow.
256
- */
257
- export function increaseLocation(
258
- selectedCells: RackGridCell[],
259
- type: string,
260
- skipNumbering: boolean,
261
- startSection: number,
262
- startUnit: number,
263
- sectionDigits: number,
264
- unitDigits: number
265
- ) {
266
- // step 1: classify cells by row
267
- const classified = classifyByRow(selectedCells)
268
-
269
- // step 2: find aisle row indices
270
- const aisleRowIndices = getAisleRowIndices(classified)
271
-
272
- // step 3: classify cells by section
273
- const sections = classifyCellsBySection(classified, aisleRowIndices)
274
-
275
- // step 4: rearrange by aisle
276
- let rearranged = rearrangeByAisle(type, sections)
277
-
278
- // step 5: if skip numbering, remove empty cells
279
- if (skipNumbering) rearranged = removeEmptyCells(rearranged)
280
-
281
- // step 6: merge rows
282
- const merged = mergeRows(rearranged)
283
-
284
- // step 7: set location
285
- setLocations(merged, startSection, startUnit, sectionDigits, unitDigits)
286
- }
@@ -1,101 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- *
4
- * RackCell 3D — invisible anchor group positioned at the cell's location
5
- * within the parent rack's 3D coordinate space.
6
- *
7
- * RackCell has no geometry of its own. Its sole 3D purpose is to provide
8
- * an Object3D that carriers can be attached to (via Three.js `.attach()`),
9
- * placed at the exact cell position within the rack. The position is derived
10
- * from the parent Rack's CellMap (by cellId), not from 2D state fields —
11
- * rack cells occupy 3D levels that have no 2D analogue.
12
- *
13
- * updateTransform() override: things-scene's standard updateTransform
14
- * reads `component.center` (2D) and flattens it to 3D. For rack cells this
15
- * is wrong — we need the 3D cell position (bay x, level y, row z) from the
16
- * parent rack. So we override and read it directly from the CellMap.
17
- */
18
-
19
- import * as THREE from 'three'
20
- import { RealObjectGroup } from '@hatiolab/things-scene'
21
-
22
- export class StorageCell3D extends RealObjectGroup {
23
- build() {
24
- super.build()
25
- this._repositionFromCellMap()
26
- }
27
-
28
- updateDimension() {
29
- // intentional no-op — size comes from the cell definition, not state
30
- }
31
-
32
- updateTransform() {
33
- this._repositionFromCellMap()
34
- }
35
-
36
- updateAlpha() {
37
- // invisible — no materials to update
38
- }
39
-
40
- /**
41
- * Position this group at the cell's localPosition within the rack's 3D space.
42
- *
43
- * CellMap.grid() places cell origins at:
44
- * x = b * bayWidth, y = l * levelHeight, z = r * rowDepth
45
- * (starting from 0,0,0 at the rack's bottom-left-front corner).
46
- *
47
- * The rack's object3d is centered: X spans [-width/2, +width/2],
48
- * Y spans [-depth/2, +depth/2], Z spans [-height/2, +height/2].
49
- *
50
- * So the cell centre in rack-local 3D space:
51
- * x3d = cellPos.x + bayWidth/2 - width/2
52
- * y3d = cellPos.y + levelHeight/2 - rackDepth/2
53
- * z3d = cellPos.z + rowDepth/2 - rackHeight/2
54
- */
55
- _repositionFromCellMap() {
56
- const rack = (this.component as any).parent
57
- if (!rack?.cellMap) return
58
-
59
- const cellId = this.component.state.cellId as string | undefined
60
- if (!cellId) return
61
-
62
- const cell = rack.cellMap.findById(cellId)
63
- if (!cell) return
64
-
65
- const rs = rack.state as any
66
- const rackWidth = (rs?.width as number) || 1000
67
- const rackDepth = (rs?.depth as number) || 3000 // Y dimension (floor→ceiling)
68
- const rackHeight = (rs?.height as number) || 600 // Z dimension (front→back, 2D height)
69
- const bays = Math.max(1, Math.floor(rs?.bays || 5))
70
- const levels = Math.max(1, Math.floor(rs?.levels || 4))
71
- const rows = 1
72
-
73
- const bayWidth = rackWidth / bays
74
- const levelHeight = rackDepth / levels
75
- const rowDepth = rackHeight / rows
76
-
77
- const x3d = cell.localPosition.x + bayWidth / 2 - rackWidth / 2
78
- const y3d = cell.localPosition.y + levelHeight / 2 - rackDepth / 2
79
- const z3d = cell.localPosition.z + rowDepth / 2 - rackHeight / 2
80
-
81
- this.object3d.position.set(x3d, y3d, z3d)
82
-
83
- // Optionally visualise cells in debug mode (outline box, very faint)
84
- if (process.env.NODE_ENV !== 'production' && (rack.state as any)?.debugCells) {
85
- this._addDebugBox(bayWidth, levelHeight, rowDepth)
86
- }
87
- }
88
-
89
- private _debugBox?: THREE.LineSegments
90
-
91
- private _addDebugBox(w: number, h: number, d: number) {
92
- if (this._debugBox) return
93
- const geo = new THREE.BoxGeometry(w * 0.98, h * 0.98, d * 0.98)
94
- const edges = new THREE.EdgesGeometry(geo)
95
- this._debugBox = new THREE.LineSegments(
96
- edges,
97
- new THREE.LineBasicMaterial({ color: 0x00ff88, transparent: true, opacity: 0.2 })
98
- )
99
- this.object3d.add(this._debugBox)
100
- }
101
- }
@@ -1,267 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- *
4
- * RackCell — a single storage slot within an Rack.
5
- *
6
- * A RackCell is a virtual component: it occupies a specific (bay, row, level)
7
- * coordinate within the parent rack and acts as a CarrierHolder for one carrier
8
- * (or several, depending on `cellType`).
9
- *
10
- * The crane (or any picker) navigates toward a RackCell as its `place()` destination —
11
- * because the rack cell is a discrete component, Mover.moveTo() can target it
12
- * directly and arrive at exactly the right bay × level position.
13
- *
14
- * Visual: invisible in 2D (no visible 2D footprint — rack cells don't make
15
- * sense as 2D top-down boxes). In 3D, each cell is an invisible Group
16
- * positioned within the rack's coordinate space (RackCell3D handles
17
- * this via updateTransform override).
18
- *
19
- * Lifecycle: Rack._buildCells() instantiates RackCell children.
20
- * Do not create RackCell components manually — they are managed by the rack.
21
- *
22
- * Domain aliases:
23
- * cell.store(carrier) ← cell.receive(carrier)
24
- * cell.retrieve(carrier, target) ← cell.dispatch(carrier, target)
25
- */
26
-
27
- import {
28
- Component,
29
- ComponentNature,
30
- ContainerAbstract,
31
- RealObject,
32
- TRANSFER_SLOT_KEY,
33
- sceneComponent
34
- } from '@hatiolab/things-scene'
35
- import type { State, Material3D } from '@hatiolab/things-scene'
36
- import { CarrierHolder, type AttachFrame } from '@operato/scene-base'
37
-
38
- import { StorageCell3D } from './storage-cell-3d.js'
39
-
40
- /**
41
- * How many carriers a cell can hold simultaneously.
42
- * - single: exactly 1 (typical pallet bay)
43
- * - multi: small stack (up to 4, e.g. a multi-deep tray)
44
- * - bulk: unlimited (e.g. a floor area measured in slots)
45
- */
46
- export type StorageCellType = 'single' | 'multi' | 'bulk'
47
-
48
- /** RackCell 컴포넌트 state */
49
- export interface StorageCellState extends State {
50
- // ── 식별 ──
51
- cellId?: string
52
- cellType?: StorageCellType
53
- /**
54
- * 자동 할당된 location ID — RackTable.assignLocations() 가 set. 외부 시스템
55
- * (WMS, picker 명령 등) 이 cell 을 지칭하는 사람-친화 ID. RackTable 없이
56
- * 단독으로 Rack 을 사용할 땐 unset.
57
- */
58
- locationId?: string
59
-
60
- // ── 3D 재질 ──
61
- material3d?: Material3D
62
- }
63
-
64
- const NATURE: ComponentNature = {
65
- mutable: false,
66
- resizable: false,
67
- rotatable: false,
68
- properties: [
69
- {
70
- type: 'string',
71
- label: 'cell-id',
72
- name: 'cellId',
73
- placeholder: 'e.g. 0-0-0'
74
- },
75
- {
76
- type: 'select',
77
- label: 'cell-type',
78
- name: 'cellType',
79
- property: {
80
- options: [
81
- { display: 'Single', value: 'single' },
82
- { display: 'Multi', value: 'multi' },
83
- { display: 'Bulk', value: 'bulk' }
84
- ]
85
- }
86
- }
87
- ],
88
- help: 'scene/component/storage-cell'
89
- }
90
-
91
- /**
92
- * RackCell — single-slot storage cell inside an Rack.
93
- *
94
- * Mixin chain: CarrierHolder(ContainerAbstract)
95
- * - CarrierHolder: publishes attachPointFor(), gates containable() to Carriables
96
- * - ContainerAbstract: manages child carrier components
97
- *
98
- * No Placeable mixin — RackCell3D self-positions from the parent rack's
99
- * CellMap (via updateTransform override), bypassing things-scene's standard
100
- * 2D→3D coordinate mapping which cannot express 3D levels.
101
- */
102
- @sceneComponent('storage-cell')
103
- export default class RackCell extends CarrierHolder(ContainerAbstract) {
104
- declare state: StorageCellState
105
-
106
- // ── Identification ────────────────────────────────────────────────────────
107
-
108
- get cellId(): string {
109
- return this.state.cellId ?? ''
110
- }
111
-
112
- get cellType(): StorageCellType {
113
- return this.state.cellType ?? 'single'
114
- }
115
-
116
- /** Maximum carrier count for this cell based on cellType. */
117
- get capacity(): number {
118
- switch (this.cellType) {
119
- case 'single': return 1
120
- case 'multi': return 4
121
- case 'bulk': return Infinity
122
- }
123
- }
124
-
125
- // ── Interface ─────────────────────────────────────────────────────────────
126
-
127
- get nature(): ComponentNature {
128
- return NATURE
129
- }
130
-
131
- get anchors(): [] {
132
- return []
133
- }
134
-
135
- // ── Transfer protocol ─────────────────────────────────────────────────────
136
-
137
- /** True when fewer carriers are currently held than capacity. */
138
- canReceive(_component?: any): boolean {
139
- const occupied = (this.components as Component[] | undefined)?.length ?? 0
140
- return occupied < this.capacity
141
- }
142
-
143
- /**
144
- * Accept a carrier into this cell.
145
- * Sets TRANSFER_SLOT_KEY = cellId on the carrier, then reparents.
146
- * Fires 'transfer-received' so monitors can react.
147
- */
148
- async receive(carrier: any, options: any = {}): Promise<void> {
149
- if (!this.canReceive(carrier)) {
150
- this.trigger('transfer-rejected', {
151
- type: 'transfer-rejected',
152
- component: carrier,
153
- container: this,
154
- reason: 'no-slot'
155
- })
156
- return
157
- }
158
- carrier[TRANSFER_SLOT_KEY] = this.cellId
159
- this.reparent(carrier, options)
160
-
161
- // carrier.state.left/top/zPos 을 *cell-local center* 로 명시. 이전 holder
162
- // 의 state (예: crane-local center) 가 그대로 남으면 *다음 pick 시
163
- // moveTo(carrier) 의 target.center 계산이 *잘못된 좌표* 로 → 엉뚱한 위치
164
- // 이동 결함. transient placement 'carried' 라 3D obj3d.position 영향 X,
165
- // 2D render 와 moveTo 의 center 계산에만 영향.
166
- const cw = numOr((this as any).state?.width, 0)
167
- const ch = numOr((this as any).state?.height, 0)
168
- const carrierW = numOr(carrier?.state?.width, 0)
169
- const carrierH = numOr(carrier?.state?.height, 0)
170
- carrier.setState?.({
171
- left: (cw - carrierW) / 2,
172
- top: (ch - carrierH) / 2,
173
- zPos: 0
174
- })
175
-
176
- this.trigger('transfer-received', {
177
- type: 'transfer-received',
178
- component: carrier,
179
- container: this,
180
- slotId: this.cellId
181
- })
182
- }
183
-
184
- /**
185
- * Release a carrier from this cell to `target`.
186
- * Delegates to `target.receive()` if available, otherwise `target.reparent()`.
187
- */
188
- async dispatch(carrier: any, target: any, options: any = {}): Promise<void> {
189
- if (target?.canReceive && !target.canReceive(carrier)) {
190
- this.trigger('transfer-rejected', {
191
- type: 'transfer-rejected',
192
- component: carrier,
193
- container: this,
194
- reason: 'target-full'
195
- })
196
- return
197
- }
198
- delete carrier[TRANSFER_SLOT_KEY]
199
- if (typeof target?.receive === 'function') {
200
- await target.receive(carrier, options)
201
- } else {
202
- ;(target as any).reparent?.(carrier, options)
203
- }
204
- this.trigger('transfer-dispatched', {
205
- type: 'transfer-dispatched',
206
- component: carrier,
207
- container: this,
208
- target
209
- })
210
- }
211
-
212
- // ── Domain aliases ────────────────────────────────────────────────────────
213
-
214
- /** Alias for receive() — semantic sugar for the storage domain. */
215
- store(carrier: any, options?: any): Promise<void> {
216
- return this.receive(carrier, options)
217
- }
218
-
219
- /** Alias for dispatch() — semantic sugar for the storage domain. */
220
- retrieve(carrier: any, target: any, options?: any): Promise<void> {
221
- return this.dispatch(carrier, target, options)
222
- }
223
-
224
- // ── 3D attach frame ───────────────────────────────────────────────────────
225
-
226
- /**
227
- * Return the 3D attach frame for carriers placed in this cell.
228
- *
229
- * Center-origin convention: cell 의 *local origin* 은 cell 의 center
230
- * (= levelHeight/2 above the shelf beam). carrier 의 *bottom face* 가 cell
231
- * 의 *bottom* (= local Y -cellDepth/2) 에 닿도록 carrier center =
232
- * -cellDepth/2 + carrierDepth/2.
233
- */
234
- attachPointFor(carrier: Component): AttachFrame | null {
235
- const root = this._realObject?.object3d
236
- if (!root) return null
237
- const carrierDepth = resolveCarrierDepth(carrier)
238
- const cellDepth = numOr((this as any).state?.depth, 0)
239
- return {
240
- attach: root,
241
- localPosition: { x: 0, y: -cellDepth / 2 + carrierDepth / 2, z: 0 }
242
- }
243
- }
244
-
245
- // ── 2D rendering ──────────────────────────────────────────────────────────
246
-
247
- /** RackCell has no 2D visual — the rack draws its own structure. */
248
- render(_ctx: CanvasRenderingContext2D) {
249
- // intentional no-op
250
- }
251
-
252
- // ── 3D ───────────────────────────────────────────────────────────────────
253
-
254
- buildRealObject(): RealObject | undefined {
255
- return new StorageCell3D(this)
256
- }
257
- }
258
-
259
- function resolveCarrierDepth(c: Component): number {
260
- const eff = (c as any)._realObject?.effectiveDepth
261
- if (typeof eff === 'number' && Number.isFinite(eff)) return eff
262
- return numOr((c as any)?.state?.depth, 0)
263
- }
264
-
265
- function numOr(v: unknown, dflt: number): number {
266
- return typeof v === 'number' && Number.isFinite(v) ? v : dflt
267
- }