@shipload/sdk 1.0.0-next.28 → 1.0.0-next.29
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/lib/shipload.d.ts +2 -1
- package/lib/shipload.js +15 -1
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +15 -2
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/capabilities/storage.ts +15 -0
- package/src/scheduling/projection.ts +2 -2
package/package.json
CHANGED
|
@@ -157,3 +157,18 @@ export function removeFromStacks(stacks: CargoStack[], remove: CargoStack): Carg
|
|
|
157
157
|
result[idx] = {...target, quantity: remaining}
|
|
158
158
|
return result
|
|
159
159
|
}
|
|
160
|
+
|
|
161
|
+
// Tolerant subtraction mirroring the contract's subtract_cargo (projection replay): missing or oversized removal clamps to zero, never throws.
|
|
162
|
+
export function subtractFromStacks(stacks: CargoStack[], remove: CargoStack): CargoStack[] {
|
|
163
|
+
const idx = stacks.findIndex((s) => stackIdentityEqual(s, remove))
|
|
164
|
+
if (idx === -1) {
|
|
165
|
+
return stacks
|
|
166
|
+
}
|
|
167
|
+
const target = stacks[idx]
|
|
168
|
+
if (target.quantity.lte(remove.quantity)) {
|
|
169
|
+
return [...stacks.slice(0, idx), ...stacks.slice(idx + 1)]
|
|
170
|
+
}
|
|
171
|
+
const result = stacks.slice()
|
|
172
|
+
result[idx] = {...target, quantity: UInt32.from(target.quantity.subtracting(remove.quantity))}
|
|
173
|
+
return result
|
|
174
|
+
}
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
cargoItemToStack,
|
|
27
27
|
type CargoStack,
|
|
28
28
|
mergeStacks,
|
|
29
|
-
|
|
29
|
+
subtractFromStacks,
|
|
30
30
|
stackToCargoItem,
|
|
31
31
|
} from '../capabilities/storage'
|
|
32
32
|
import * as schedule from './schedule'
|
|
@@ -244,7 +244,7 @@ function addCargoItem(projected: ProjectedEntity, item: ServerContract.Types.car
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
function removeCargoItem(projected: ProjectedEntity, item: ServerContract.Types.cargo_item): void {
|
|
247
|
-
projected.cargo =
|
|
247
|
+
projected.cargo = subtractFromStacks(projected.cargo, cargoItemToStack(item))
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
function applyAddCargoTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|