Skip to main content

Class: Container

entities.Container

Generic container with no special "looks" assigned to it.

Hierarchy

  • Entity<ContainerOptions>

  • Mixin

    Container

Constructors

constructor

new Container(state, options?)

Parameters

NameType
stateState<Record<string, unknown>>
optionsPartial<Partial<NonFunctionProperties<Mixin>>>

Inherited from

Entity.constructor

ChildTrait Properties

idx

idx: number


parent

parent: ParentTrait


LabelTrait Properties

name

name: string


type

type: string

Type should be unique to schema object! If you're extending this schema and adding new fields - set the new type string!


LocationTrait Properties

angle

angle: number

Rotation in degrees


x

x: number

X offset relative to entity's parent


y

y: number

Y offset relative to entity's parent


Other Properties

childAdded

childAdded: ChildAddedHandler


childRemoved

childRemoved: ChildRemovedHandler


id

Readonly id: number


OwnershipTrait Properties

ownerID

ownerID: string

ID of the player owning this entity. Synced with client-side and automatically parsed after changing entity.owner from the server-side.


ParentTrait Properties

childrenPointers

childrenPointers: Map<ChildTrait, string>

ChildTrait object -> its constructor's name Also good spot to count all children


collectionBehaviour

collectionBehaviour: "map" | "array"

How children and their indexes behave when added into or removed from this parent.

  • array: there can be no empty spots, children will always move to fill in the gaps
  • map: no automatic movement is performed, adding to first empty spot, otherwise you need to ensure given spot isn't occupied

Default

"array"

hijacksInteractionTarget

hijacksInteractionTarget: boolean

Used by ChildTrait.isInteractive.

If set to true, will prevent its direct children from getting interaction events.


maxChildren

maxChildren: number

Default

Infinity

ChildTrait Accessors

idxPath

get idxPath(): number[]

Returns

number[]

array of indexes for this entity access


OwnershipTrait Accessors

owner

get owner(): Player

Get the real owner of this thing, by traversing this.parent chain. Owner could be set on an element or container, meaning every element in such container belongs to one owner.

Returns

Player

Player or undefined if this container doesn't belong to anyone

set owner(newOwner): void

Parameters

NameType
newOwnerPlayer

Returns

void


ownersMainFocus

get ownersMainFocus(): boolean

Is this entity/container to be the main focus for this player? To be used by client-side implementation.

Returns

boolean

set ownersMainFocus(newValue): void

Parameters

NameType
newValueboolean

Returns

void

ChildTrait Methods

isInteractive

isInteractive(): boolean

Points out if this element can be target of any interaction

Returns

boolean


Other Methods

addChild

addChild(entity): void

Adds new item.

Parameters

NameType
entityChildTrait

Returns

void

addChild(entity, prepend): void

Adds new item.

Parameters

NameType
entityChildTrait
prependboolean

Returns

void

addChild(entity, atIndex): void

Adds new item.

Parameters

NameTypeDescription
entityChildTrait
atIndexnumbersqueeze into desired spot, moving other children away.

Returns

void

addChild(entity, arg1): void

Adds new item.

Parameters

NameType
entityChildTrait
arg1number | boolean

Returns

void


addChildren

addChildren(entities): void

Parameters

NameType
entitiesChildTrait[]

Returns

void


countChildren

countChildren(): number

Number of child elements

Returns

number


create

create(state, options?): void

Parameters

NameType
stateState<Record<string, unknown>>
optionsPartial<NonFunctionProperties<Mixin>>

Returns

void

Overrides

Entity.create


getBottom

getBottom<T>(): T

Get the element with the lowest 'idx' value

Type parameters

NameType
Textends ChildTrait<T>

Returns

T


getChild

getChild<T>(idx): T

Get one direct child of parent by its idx

Type parameters

NameType
Textends ChildTrait<T>

Parameters

NameType
idxnumber

Returns

T


getChildren

getChildren<T>(): T[]

Gets all direct children in array form, "sorted" by idx

Type parameters

NameType
Textends ChildTrait<T>

Returns

T[]


getClosestEmptySpot

getClosestEmptySpot(index): number

unused?

Parameters

NameType
indexnumber

Returns

number


getFirstEmptySpot

getFirstEmptySpot(): number

For map behaviour, seeks out first available spot, starting from index 0. Arrays don't have gaps, so first "available" spot is always after last child.

Returns

number

index of first vacant spot, or -1 if no spot is available


getLastEmptySpot

getLastEmptySpot(): number

unused?

Returns

number


getTop

getTop<T>(): T

Get the element with highest 'idx' value

Type parameters

NameType
Textends ChildTrait<T>

Returns

T


indexFits

indexFits(index): boolean

Does index fit in range of this container. Doesn't check if index is occupied. Considering maxChildren and if index is negative or otherwise invalid.

Parameters

NameType
indexnumber

Returns

boolean


move

Protected move(where, start, end?): IndexUpdate[]

Takes care of manipulating indexes, and updating every internal things related to children spot movements

Parameters

NameTypeDescription
wherenumberdirection and range. (+1) - one up, (-2) - two in direction of array start
startnumberleft-most child to manipulate
end?numberrightmost child, omit to have only one child moved

Returns

IndexUpdate[]


moveChildTo

moveChildTo(from, to): void

In array, moves child to target idx, rearranging everything between from and to. In map, swaps children at from and to (for now...)

Parameters

NameTypeDescription
fromnumberindex of child to move
tonumberdesired target position

Returns

void


query

query<T>(props): T

Find one item matching props.

Type parameters

NameType
Textends ChildTrait<T>

Parameters

NameType
propsQuerableProps

Returns

T


queryAll

queryAll<T>(props): T[]

Looks for every matching entity here and deeper

Type parameters

NameType
Textends ChildTrait<T>

Parameters

NameType
propsQuerableProps

Returns

T[]


removeChild

removeChild(child): boolean

Parameters

NameType
childChildTrait

Returns

boolean


removeChildAt

removeChildAt(idx): boolean

Parameters

NameType
idxnumber

Returns

boolean