Skip to main content

Class: ElementCollection<T>

Operations that return groups of GameElement's return this Array-like class.

Type parameters

NameType
Textends GameElement = GameElement

Hierarchy

  • Array<T>

    ElementCollection

Queries

all

all<F>(className, ...finders): ElementCollection<F>

As GameElement#all, but finds all elements within this collection and its contained elements recursively.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
classNameElementClass<F>Optionally provide a class as the first argument as a class filter. This will only match elements which are instances of the provided class
...findersElementFinder<F>[]All other parameters are filters. See ElementFinder for more information.

Returns

ElementCollection<F>

An ElementCollection of as many matching elements as can be found. The collection is typed to ElementCollection<className> if one was provided.

Defined in

boardzilla-core/src/board/element-collection.ts:75


first

first<F>(className, ...finders): undefined | F

As GameElement#first, except finds the first element within this collection and its contained elements recursively that matches the arguments provided. See GameElement#all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

A matching element, if found

Defined in

boardzilla-core/src/board/element-collection.ts:147


firstN

firstN<F>(n, className, ...finders): ElementCollection<F>

As GameElement#firstn, except finds the first n elements within this collection and its contained elements recursively that match the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
nnumbernumber of matches
classNameElementClass<F>-
...findersElementFinder<F>[]-

Returns

ElementCollection<F>

An ElementCollection of as many matching elements as can be found, up to n. The collection is typed to ElementCollection<className> if one was provided.

Defined in

boardzilla-core/src/board/element-collection.ts:168


last

last<F>(className, ...finders): undefined | F

As GameElement#last, expect finds the last element within this collection and its contained elements recursively that matches the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

A matching element, if found

Defined in

boardzilla-core/src/board/element-collection.ts:186


lastN

lastN<F>(n, className, ...finders): ElementCollection<F>

As GameElement#lastn, expect finds the last n elements within this collection and its contained elements recursively that match the arguments provided. See all for parameter details.

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameTypeDescription
nnumbernumber of matches
classNameElementClass<F>-
...findersElementFinder<F>[]-

Returns

ElementCollection<F>

An ElementCollection of as many matching elements as can be found, up to n. The collection is typed to ElementCollection<className> if one was provided.

Defined in

boardzilla-core/src/board/element-collection.ts:207


top

top<F>(className, ...finders): undefined | F

Alias for first

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

Defined in

boardzilla-core/src/board/element-collection.ts:222


topN

topN<F>(n, className, ...finders): ElementCollection<F>

Alias for firstN

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
nnumber
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

ElementCollection<F>

Defined in

boardzilla-core/src/board/element-collection.ts:236


bottom

bottom<F>(className, ...finders): undefined | F

Alias for last

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

undefined | F

Defined in

boardzilla-core/src/board/element-collection.ts:251


bottomN

bottomN<F>(n, className, ...finders): ElementCollection<F>

Alias for lastN

Type parameters

NameType
Fextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
nnumber
classNameElementClass<F>
...findersElementFinder<F>[]

Returns

ElementCollection<F>

Defined in

boardzilla-core/src/board/element-collection.ts:265


sum

sum(key): number

Returns the sum of all elements in this collection measured by a provided key

Parameters

NameType
keykeyof T | (e: T) => number

Returns

number

Example

deck.create(Card, '2', { pips: 2 });
deck.create(Card, '3', { pips: 3 });
deck.all(Card).sum('pips'); // => 5

Defined in

boardzilla-core/src/board/element-collection.ts:385


withHighest

withHighest(...attributes): undefined | T

Returns the element in this collection with the highest value of the provided key(s).

Parameters

NameTypeDescription
...attributesSorter<T>[]any number of Sorter's used for comparing. If multiple are provided, subsequent ones are used to break ties on earlier ones.

Returns

undefined | T

Example

army.create(Soldier, 'a', { strength: 2, initiative: 3 });
army.create(Soldier, 'b', { strength: 3, initiative: 1 });
army.create(Soldier, 'c', { strength: 3, initiative: 2 });
army.all(Solider).withHighest('strength', 'initiative'); // => Soldier 'c'

Defined in

boardzilla-core/src/board/element-collection.ts:404


withLowest

withLowest(...attributes): undefined | T

Returns the element in this collection with the lowest value of the provided key(s).

Parameters

NameTypeDescription
...attributesSorter<T>[]any number of Sorter's used for comparing. If multiple are provided, subsequent ones are used to break ties on earlier ones.

Returns

undefined | T

Example

army.create(Soldier, 'a', { strength: 2, initiative: 3 });
army.create(Soldier, 'b', { strength: 3, initiative: 1 });
army.create(Soldier, 'c', { strength: 2, initiative: 2 });
army.all(Solider).withLowest('strength', 'initiative'); // => Soldier 'c'

Defined in

boardzilla-core/src/board/element-collection.ts:423


max

max<K>(key): undefined | K

Returns the highest value of the provided key(s) found on any element in this collection.

Type parameters

NameType
Kextends string | number

Parameters

NameTypeDescription
key{ [K2 in string | number | symbol]: T[K2] extends K ? K2 : never }[keyof T] | (t: T) => Ka Sorter's used for comparing and extracting the max.

Returns

undefined | K

Example

army.create(Soldier, 'a', { strength: 2, initiative: 3 });
army.create(Soldier, 'b', { strength: 3, initiative: 1 });
army.create(Soldier, 'c', { strength: 2, initiative: 2 });
army.all(Solider).max('strength'); // => 3

Defined in

boardzilla-core/src/board/element-collection.ts:441


min

min<K>(key): undefined | K

Returns the lowest value of the provided key(s) found on any element in this collection.

Type parameters

NameType
Kextends string | number

Parameters

NameTypeDescription
key{ [K2 in string | number | symbol]: T[K2] extends K ? K2 : never }[keyof T] | (t: T) => Ka Sorter's used for comparing and extracting the minimum.

Returns

undefined | K

Example

army.create(Soldier, 'a', { strength: 2, initiative: 3 });
army.create(Soldier, 'b', { strength: 3, initiative: 1 });
army.create(Soldier, 'c', { strength: 2, initiative: 2 });
army.all(Solider).min('initiative'); // => 1

Defined in

boardzilla-core/src/board/element-collection.ts:461


areAllEqual

areAllEqual(key): boolean

Returns whether all elements in this collection have the same value for key.

Parameters

NameType
keykeyof T

Returns

boolean

Defined in

boardzilla-core/src/board/element-collection.ts:471

Structure

sortBy

sortBy<E>(key, direction?): ElementCollection<T>

Sorts this collection by some Sorter.

Type parameters

NameType
Eextends GameElement<BaseGame, BasePlayer>

Parameters

NameType
keySorter<E> | Sorter<E>[]
direction?"desc" | "asc"

Returns

ElementCollection<T>

Defined in

boardzilla-core/src/board/element-collection.ts:353


sortedBy

sortedBy(key, direction?): ElementCollection<T>

Returns a copy of this collection sorted by some Sorter.

Parameters

NameTypeDefault value
keySorter<T> | Sorter<T>[]undefined
direction"desc" | "asc""asc"

Returns

ElementCollection<T>

Defined in

boardzilla-core/src/board/element-collection.ts:372


remove

remove(): void

Remove all elements in this collection from the playing area and place them into Game#pile

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:481


putInto

putInto(to, options?): void

Move all pieces in this collection into another element. See Piece#putInto.

Parameters

NameType
toGameElement<BaseGame, BasePlayer>
options?Object
options.position?number
options.fromTop?number
options.fromBottom?number

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:492

UI

layout

layout(applyTo, attributes): void

Apply a layout to some of the elements directly contained within the elements in this collection. See GameElement#layout

Parameters

NameType
applyToT["_ui"]["layouts"][number]["applyTo"]
attributesPartial<LayoutAttributes>

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:507


configureLayout

configureLayout(attributes): void

Configure the layout for all elements contained within this collection. See GameElement#configureLayout

Parameters

NameType
attributesPartial<LayoutAttributes>

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:520


appearance

appearance(appearance): void

Define the appearance of the elements in this collection. Any values provided override previous ones. See GameElement#appearance.

Parameters

NameType
appearanceObject
appearance.className?string
appearance.render?false | (el: T) => null | Element
appearance.aspectRatio?number
appearance.effects?{ trigger: (element: T, oldAttributes: Partial<Pick<T, "name" | "player" | "row" | "column" | "rotation" | { [K in string | number | symbol]: K extends keyof GameElement<BaseGame, BasePlayer> ? never : T[K] extends Function ? never : K }[keyof T]>>) => boolean ; name: string }[]
appearance.info?boolean | (el: T) => null | boolean | Element
appearance.connections?Object
appearance.connections.thickness?number
appearance.connections.style?"double" | "solid"
appearance.connections.color?string
appearance.connections.fill?string
appearance.connections.label?(__namedParameters: { distance: number ; to: Space<Game<BaseGame, BasePlayer>, BasePlayer> ; from: Space<Game<BaseGame, BasePlayer>, BasePlayer> }) => ReactNode
appearance.connections.labelScale?number

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:531

Visibility

showToAll

showToAll(this): void

Show these elements to all players

Parameters

NameType
thisElementCollection<Piece<BaseGame, BasePlayer>>

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:280


showOnlyTo

showOnlyTo(this, player): void

Show these elements only to the given player

Parameters

NameType
thisElementCollection<Piece<BaseGame, BasePlayer>>
playernumber | Player<BaseGame, BasePlayer>

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:290


showTo

showTo(this, ...player): void

Show these elements to the given players without changing it's visibility to any other players.

Parameters

NameType
thisElementCollection<Piece<BaseGame, BasePlayer>>
...playernumber[] | Player<BaseGame, BasePlayer>[]

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:305


hideFromAll

hideFromAll(this): void

Hide this element from all players

Parameters

NameType
thisElementCollection<Piece<BaseGame, BasePlayer>>

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:322


hideFrom

hideFrom(this, ...player): void

Hide these elements from the given players without changing it's visibility to any other players.

Parameters

NameType
thisElementCollection<Piece<BaseGame, BasePlayer>>
...playernumber[] | Player<BaseGame, BasePlayer>[]

Returns

void

Defined in

boardzilla-core/src/board/element-collection.ts:333