@shipload/sdk 1.0.0-next.4 → 1.0.0-next.5
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 +190 -91
- package/lib/shipload.js +568 -37
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +561 -37
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/contracts/server.ts +54 -1
- package/src/data/colors.ts +1 -0
- package/src/data/items.json +245 -0
- package/src/data/metadata.ts +44 -1
- package/src/derivation/resources.ts +27 -19
- package/src/entities/container.ts +15 -0
- package/src/entities/ship-deploy.ts +42 -6
- package/src/entities/ship.ts +17 -0
- package/src/entities/warehouse.ts +8 -0
- package/src/index-module.ts +23 -15
- package/src/managers/actions.ts +24 -1
- package/src/nft/description.ts +21 -2
- package/src/resolution/resolve-item.ts +9 -5
- package/src/scheduling/accessor.ts +4 -0
- package/src/scheduling/projection.ts +8 -0
- package/src/scheduling/schedule.ts +15 -1
- package/src/subscriptions/manager.ts +37 -1
- package/src/travel/travel.ts +58 -1
- package/src/types.ts +3 -0
package/src/travel/travel.ts
CHANGED
|
@@ -77,6 +77,59 @@ export function lerp(
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
export interface FloatPosition {
|
|
81
|
+
x: number
|
|
82
|
+
y: number
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function easeFlightProgress(t: number): number {
|
|
86
|
+
if (t <= 0) return 0
|
|
87
|
+
if (t >= 1) return 1
|
|
88
|
+
return t < 0.5 ? 2 * t * t : 1 - 2 * (1 - t) * (1 - t)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function flightSpeedFactor(t: number): number {
|
|
92
|
+
if (t <= 0 || t >= 1) return 0
|
|
93
|
+
return t < 0.5 ? 4 * t : 4 * (1 - t)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function interpolateFlightPosition(
|
|
97
|
+
origin: {x: Int64Type | number; y: Int64Type | number},
|
|
98
|
+
destination: {x: Int64Type | number; y: Int64Type | number},
|
|
99
|
+
taskProgress: number,
|
|
100
|
+
options?: {easing?: 'physics' | 'linear'}
|
|
101
|
+
): FloatPosition {
|
|
102
|
+
const t = options?.easing === 'linear' ? taskProgress : easeFlightProgress(taskProgress)
|
|
103
|
+
return {
|
|
104
|
+
x: (1 - t) * Number(origin.x) + t * Number(destination.x),
|
|
105
|
+
y: (1 - t) * Number(origin.y) + t * Number(destination.y),
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function getInterpolatedPosition(
|
|
110
|
+
entity: HasScheduleAndLocation,
|
|
111
|
+
taskIndex: number,
|
|
112
|
+
taskProgress: number
|
|
113
|
+
): FloatPosition {
|
|
114
|
+
if (!entity.schedule || entity.schedule.tasks.length === 0) {
|
|
115
|
+
return {x: Number(entity.coordinates.x), y: Number(entity.coordinates.y)}
|
|
116
|
+
}
|
|
117
|
+
if (taskIndex < 0) {
|
|
118
|
+
const settled = getFlightOrigin(entity, entity.schedule.tasks.length)
|
|
119
|
+
return {x: Number(settled.x), y: Number(settled.y)}
|
|
120
|
+
}
|
|
121
|
+
const task = entity.schedule.tasks[taskIndex]
|
|
122
|
+
if (!task.type.equals(TaskType.TRAVEL) || !task.coordinates) {
|
|
123
|
+
const origin = getFlightOrigin(entity, taskIndex)
|
|
124
|
+
return {x: Number(origin.x), y: Number(origin.y)}
|
|
125
|
+
}
|
|
126
|
+
return interpolateFlightPosition(
|
|
127
|
+
getFlightOrigin(entity, taskIndex),
|
|
128
|
+
task.coordinates,
|
|
129
|
+
taskProgress
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
80
133
|
export function rotation(
|
|
81
134
|
origin: ServerContract.ActionParams.Type.coordinates,
|
|
82
135
|
destination: ServerContract.ActionParams.Type.coordinates
|
|
@@ -408,14 +461,18 @@ export function getDestinationLocation(
|
|
|
408
461
|
return undefined
|
|
409
462
|
}
|
|
410
463
|
|
|
464
|
+
/** Returns chain-tile coordinates (rounded). For visual position use getInterpolatedPosition. */
|
|
411
465
|
export function getPositionAt(
|
|
412
466
|
entity: HasScheduleAndLocation,
|
|
413
467
|
taskIndex: number,
|
|
414
468
|
taskProgress: number
|
|
415
469
|
): ServerContract.ActionParams.Type.coordinates {
|
|
416
|
-
if (!entity.schedule || entity.schedule.tasks.length === 0
|
|
470
|
+
if (!entity.schedule || entity.schedule.tasks.length === 0) {
|
|
417
471
|
return entity.coordinates
|
|
418
472
|
}
|
|
473
|
+
if (taskIndex < 0) {
|
|
474
|
+
return getFlightOrigin(entity, entity.schedule.tasks.length)
|
|
475
|
+
}
|
|
419
476
|
|
|
420
477
|
const task = entity.schedule.tasks[taskIndex]
|
|
421
478
|
|