Class: ElementCollection<T>
Operations that return groups of GameElement's return this Array-like class.
Type parameters
Name | Type |
---|---|
T | extends 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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type | Description |
---|---|---|
className | ElementClass <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 |
...finders | ElementFinder <F >[] | All other parameters are filters. See ElementFinder for more information. |
Returns
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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
className | ElementClass <F > |
...finders | ElementFinder <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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type | Description |
---|---|---|
n | number | number of matches |
className | ElementClass <F > | - |
...finders | ElementFinder <F >[] | - |
Returns
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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
className | ElementClass <F > |
...finders | ElementFinder <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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type | Description |
---|---|---|
n | number | number of matches |
className | ElementClass <F > | - |
...finders | ElementFinder <F >[] | - |
Returns
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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
className | ElementClass <F > |
...finders | ElementFinder <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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
n | number |
className | ElementClass <F > |
...finders | ElementFinder <F >[] |
Returns
Defined in
boardzilla-core/src/board/element-collection.ts:236
bottom
▸ bottom<F
>(className
, ...finders
): undefined
| F
Alias for last
Type parameters
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
className | ElementClass <F > |
...finders | ElementFinder <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
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
n | number |
className | ElementClass <F > |
...finders | ElementFinder <F >[] |
Returns
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
Name | Type |
---|---|
key | keyof 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
Name | Type | Description |
---|---|---|
...attributes | Sorter <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
Name | Type | Description |
---|---|---|
...attributes | Sorter <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
Name | Type |
---|---|
K | extends string | number |
Parameters
Name | Type | Description |
---|---|---|
key | { [K2 in string | number | symbol]: T[K2] extends K ? K2 : never }[keyof T ] | (t : T ) => K | a 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
Name | Type |
---|---|
K | extends string | number |
Parameters
Name | Type | Description |
---|---|---|
key | { [K2 in string | number | symbol]: T[K2] extends K ? K2 : never }[keyof T ] | (t : T ) => K | a 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
Name | Type |
---|---|
key | keyof 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
Name | Type |
---|---|
E | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
key | Sorter <E > | Sorter <E >[] |
direction? | "desc" | "asc" |
Returns
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
Name | Type | Default value |
---|---|---|
key | Sorter <T > | Sorter <T >[] | undefined |
direction | "desc" | "asc" | "asc" |
Returns
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
Name | Type |
---|---|
to | GameElement <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
Name | Type |
---|---|
applyTo | T ["_ui" ]["layouts" ][number ]["applyTo" ] |
attributes | Partial <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
Name | Type |
---|---|
attributes | Partial <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
Name | Type |
---|---|
appearance | Object |
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
Name | Type |
---|---|
this | ElementCollection <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
Name | Type |
---|---|
this | ElementCollection <Piece <BaseGame , BasePlayer >> |
player | number | 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
Name | Type |
---|---|
this | ElementCollection <Piece <BaseGame , BasePlayer >> |
...player | number [] | 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
Name | Type |
---|---|
this | ElementCollection <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
Name | Type |
---|---|
this | ElementCollection <Piece <BaseGame , BasePlayer >> |
...player | number [] | Player <BaseGame , BasePlayer >[] |
Returns
void