@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.
@@ -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 || taskIndex < 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
 
package/src/types.ts CHANGED
@@ -51,6 +51,9 @@ export enum TaskType {
51
51
  DEPLOY = 8,
52
52
  WRAP = 9,
53
53
  UNWRAP = 10,
54
+ UNDEPLOY = 11,
55
+ WRAP_ENTITY = 12,
56
+ DEMOLISH = 13,
54
57
  }
55
58
 
56
59
  export enum LocationType {