@shipload/sdk 1.0.0-next.26 → 1.0.0-next.27

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.
@@ -35,6 +35,8 @@ import {
35
35
  } from '../types'
36
36
  import {getItem} from '../data/catalog'
37
37
  import {hasSystem} from '../utils/system'
38
+ import * as scheduleModel from '../scheduling/schedule'
39
+ import type {ScheduleData} from '../scheduling/schedule'
38
40
 
39
41
  export function calc_orbital_altitude(mass: number): number {
40
42
  if (mass <= BASE_ORBITAL_MASS) {
@@ -112,14 +114,15 @@ export function getInterpolatedPosition(
112
114
  taskIndex: number,
113
115
  taskProgress: number
114
116
  ): FloatPosition {
115
- if (!entity.schedule || entity.schedule.tasks.length === 0) {
117
+ const tasks = mobilityTasks(entity)
118
+ if (tasks.length === 0) {
116
119
  return {x: Number(entity.coordinates.x), y: Number(entity.coordinates.y)}
117
120
  }
118
121
  if (taskIndex < 0) {
119
- const settled = getFlightOrigin(entity, entity.schedule.tasks.length)
122
+ const settled = getFlightOrigin(entity, tasks.length)
120
123
  return {x: Number(settled.x), y: Number(settled.y)}
121
124
  }
122
- const task = entity.schedule.tasks[taskIndex]
125
+ const task = tasks[taskIndex]
123
126
  if (!task.type.equals(TaskType.TRAVEL) || !task.coordinates) {
124
127
  const origin = getFlightOrigin(entity, taskIndex)
125
128
  return {x: Number(origin.x), y: Number(origin.y)}
@@ -427,20 +430,22 @@ export interface TransferEntity {
427
430
  }
428
431
  }
429
432
 
430
- export interface HasScheduleAndLocation {
433
+ export interface HasScheduleAndLocation extends ScheduleData {
431
434
  coordinates: ServerContract.ActionParams.Type.coordinates
432
- schedule?: ServerContract.Types.schedule
435
+ }
436
+
437
+ function mobilityTasks(entity: HasScheduleAndLocation): ServerContract.Types.task[] {
438
+ return scheduleModel.mobilityLane(entity)?.schedule.tasks ?? []
433
439
  }
434
440
 
435
441
  export function getFlightOrigin(
436
442
  entity: HasScheduleAndLocation,
437
443
  flightTaskIndex: number
438
444
  ): ServerContract.ActionParams.Type.coordinates {
439
- if (!entity.schedule) return entity.coordinates
440
-
445
+ const tasks = mobilityTasks(entity)
441
446
  let origin = entity.coordinates
442
- for (let i = 0; i < flightTaskIndex && i < entity.schedule.tasks.length; i++) {
443
- const task = entity.schedule.tasks[i]
447
+ for (let i = 0; i < flightTaskIndex && i < tasks.length; i++) {
448
+ const task = tasks[i]
444
449
  if (task.type.equals(TaskType.TRAVEL) && task.coordinates) {
445
450
  origin = task.coordinates
446
451
  }
@@ -451,10 +456,9 @@ export function getFlightOrigin(
451
456
  export function getDestinationLocation(
452
457
  entity: HasScheduleAndLocation
453
458
  ): ServerContract.ActionParams.Type.coordinates | undefined {
454
- if (!entity.schedule) return undefined
455
-
456
- for (let i = entity.schedule.tasks.length - 1; i >= 0; i--) {
457
- const task = entity.schedule.tasks[i]
459
+ const tasks = mobilityTasks(entity)
460
+ for (let i = tasks.length - 1; i >= 0; i--) {
461
+ const task = tasks[i]
458
462
  if (task.type.equals(TaskType.TRAVEL) && task.coordinates) {
459
463
  return task.coordinates
460
464
  }
@@ -468,14 +472,15 @@ export function getPositionAt(
468
472
  taskIndex: number,
469
473
  taskProgress: number
470
474
  ): ServerContract.ActionParams.Type.coordinates {
471
- if (!entity.schedule || entity.schedule.tasks.length === 0) {
475
+ const tasks = mobilityTasks(entity)
476
+ if (tasks.length === 0) {
472
477
  return entity.coordinates
473
478
  }
474
479
  if (taskIndex < 0) {
475
- return getFlightOrigin(entity, entity.schedule.tasks.length)
480
+ return getFlightOrigin(entity, tasks.length)
476
481
  }
477
482
 
478
- const task = entity.schedule.tasks[taskIndex]
483
+ const task = tasks[taskIndex]
479
484
 
480
485
  if (!task.type.equals(TaskType.TRAVEL) || !task.coordinates) {
481
486
  return getFlightOrigin(entity, taskIndex)
@@ -29,6 +29,7 @@ export interface MassCapability {
29
29
  }
30
30
 
31
31
  export interface ScheduleCapability {
32
+ lanes?: ServerContract.Types.lane[]
32
33
  schedule?: ServerContract.Types.schedule
33
34
  }
34
35