Home Reference Source
import {BeltPath} from 'shapez.io/js/game/belt_path.js'
public class | source

BeltPath

Extends:

BasicSerializableObject → BeltPath

Stores a path of belts, used for optimizing performance

Static Method Summary

Static Public Methods
public static

Creates a path from a serialized object

public static
public static

getSchema(): {"entityPath": *, "items": *, "spacingToFirstItem": *}

Constructor Summary

Public Constructor
public

constructor(root: GameRoot, entityPath: Array<Entity>)

Member Summary

Public Members
public
public
public

items: Array<[number, BaseItem]>

Stores the items sorted, and their distance to the previous item (or start) Layout: [distanceToNext, item]

public

How many items past the first item are compressed

public

root: *

public
public
public

Current bounds of this path

Method Summary

Public Methods
public

Returns whether this path can accept a new item

public

Checks if this belt path should render simplified

public

computeAcceptingEntityAndSlot(debug_Silent: boolean=): {entity: Entity, slot: number, direction?: enumDirection}

Finds the entity which accepts our items

public

Computes the tile bounds of the path

public

Computes a world space position from the given progress

public

Computes the total length of the path

public

debug_checkIntegrity(currentChange: string): *

Checks if this path is valid

public

debug_failIntegrity(change: string, reason: Array<any>)

Helper to throw an error on mismatch

public

Deletes the last entity

public

Splits this path at the given entity by removing it, and returning the new secondary paht

public

Deletes the entity of the start of the path

public

draw(parameters: DrawParameters)

Draws the path

public

drawDebug(parameters: DrawParameters)

public

extendByPath(otherPath: BeltPath)

Extends the path by the given other path

public

Extends the path with the given entity on the beginning

public

extendOnEnd(entity: Entity)

Extends the belt path by the given belt

public

SLOW / Tries to find the item closest to the given tile

public

init(computeSpacing: boolean)

Initializes the path by computing the properties which are not saved

public

Returns if the given entity is the end entity of the path

public

Returns if the given entity is the start entity of the path

public

Recomputes cache variables once the path was changed

public

Called by the belt system when the surroundings changed

public

Tries to accept the item

public

Tries to hand over the item to the end entity

public

update()

Performs one tick

Inherited Summary

From class BasicSerializableObject
public static
public static

getId()

public static

Should return the serialization schema

public static

verify(data: *): string | void

public

deserialize(data: any, root: import("./savegame_serializer").GameRoot): string | void

public

Static Public Methods

public static fromSerialized(root: GameRoot, data: Object): BeltPath | string source

Creates a path from a serialized object

Params:

NameTypeAttributeDescription
root GameRoot
data Object

Return:

BeltPath | string

public static getId(): string source

Override:

BasicSerializableObject#getId

Return:

string

public static getSchema(): {"entityPath": *, "items": *, "spacingToFirstItem": *} source

Should return the serialization schema

Override:

BasicSerializableObject#getSchema

Return:

{"entityPath": *, "items": *, "spacingToFirstItem": *}

Public Constructors

public constructor(root: GameRoot, entityPath: Array<Entity>) source

Fixes typeof DerivedComponent is not assignable to typeof Component, compiled out in non-dev builds

Override:

BasicSerializableObject#constructor

Params:

NameTypeAttributeDescription
root GameRoot
entityPath Array<Entity>

Public Members

public acceptorTarget: * source

public entityPath: * source

public items: Array<[number, BaseItem]> source

Stores the items sorted, and their distance to the previous item (or start) Layout: [distanceToNext, item]

public numCompressedItemsAfterFirstItem: number source

How many items past the first item are compressed

public root: * source

public spacingToFirstItem: * source

public totalLength: * source

public worldBounds: Rectangle source

Current bounds of this path

Public Methods

public canAcceptItem(): boolean source

Returns whether this path can accept a new item

Return:

boolean

public checkIsPotatoMode(): boolean source

Checks if this belt path should render simplified

Return:

boolean

public computeAcceptingEntityAndSlot(debug_Silent: boolean=): {entity: Entity, slot: number, direction?: enumDirection} source

Finds the entity which accepts our items

Params:

NameTypeAttributeDescription
debug_Silent boolean=

Whether debug output should be silent

Return:

{entity: Entity, slot: number, direction?: enumDirection}

public computeBounds(): Rectangle source

Computes the tile bounds of the path

Return:

Rectangle

public computePositionFromProgress(progress: number): Vector source

Computes a world space position from the given progress

Params:

NameTypeAttributeDescription
progress number

Return:

Vector

public computeTotalLength(): number source

Computes the total length of the path

Return:

number

public debug_checkIntegrity(currentChange: string): * source

Checks if this path is valid

Params:

NameTypeAttributeDescription
currentChange string
  • optional
  • default: change

Return:

*

public debug_failIntegrity(change: string, reason: Array<any>) source

Helper to throw an error on mismatch

Params:

NameTypeAttributeDescription
change string
reason Array<any>

public deleteEntityOnEnd(entity: Entity) source

Deletes the last entity

Params:

NameTypeAttributeDescription
entity Entity

public deleteEntityOnPathSplitIntoTwo(entity: Entity): BeltPath source

Splits this path at the given entity by removing it, and returning the new secondary paht

Params:

NameTypeAttributeDescription
entity Entity

Return:

BeltPath

public deleteEntityOnStart(entity: Entity) source

Deletes the entity of the start of the path

Params:

NameTypeAttributeDescription
entity Entity

See:

public draw(parameters: DrawParameters) source

Draws the path

Params:

NameTypeAttributeDescription
parameters DrawParameters

public drawDebug(parameters: DrawParameters) source

Params:

NameTypeAttributeDescription
parameters DrawParameters

public extendByPath(otherPath: BeltPath) source

Extends the path by the given other path

Params:

NameTypeAttributeDescription
otherPath BeltPath

public extendOnBeginning(entity: Entity) source

Extends the path with the given entity on the beginning

Params:

NameTypeAttributeDescription
entity Entity

public extendOnEnd(entity: Entity) source

Extends the belt path by the given belt

Params:

NameTypeAttributeDescription
entity Entity

public findItemAtTile(tile: Vector): BaseItem | null source

SLOW / Tries to find the item closest to the given tile

Params:

NameTypeAttributeDescription
tile Vector

Return:

BaseItem | null

public init(computeSpacing: boolean) source

Initializes the path by computing the properties which are not saved

Params:

NameTypeAttributeDescription
computeSpacing boolean

Whether to also compute the spacing

public isEndEntity(entity: Entity): boolean source

Returns if the given entity is the end entity of the path

Params:

NameTypeAttributeDescription
entity Entity

Return:

boolean

public isStartEntity(entity: Entity): boolean source

Returns if the given entity is the start entity of the path

Params:

NameTypeAttributeDescription
entity Entity

Return:

boolean

public onPathChanged() source

Recomputes cache variables once the path was changed

public onSurroundingsChanged() source

Called by the belt system when the surroundings changed

public tryAcceptItem(item: BaseItem): boolean source

Tries to accept the item

Params:

NameTypeAttributeDescription
item BaseItem

Return:

boolean

public tryHandOverItem(item: BaseItem): boolean source

Tries to hand over the item to the end entity

Params:

NameTypeAttributeDescription
item BaseItem

Return:

boolean

public update() source

Performs one tick