Class: AdjacencySpace<G>
Abstract base class for all adjacency spaces
Type parameters
Name | Type |
---|---|
G | extends BaseGame |
Hierarchy
-
default
<G
>↳
AdjacencySpace
↳↳
PieceGrid
Adjacency
isAdjacentTo
▸ isAdjacentTo(element
): boolean
If this element is adjacent to some other element, using the nearest containing space that has an adjacency map.
Parameters
Name | Type |
---|---|
element | GameElement <BaseGame , BasePlayer > |
Returns
boolean
Inherited from
SingleLayout.isAdjacentTo
Defined in
boardzilla-core/src/board/element.ts:540
distanceTo
▸ distanceTo(element
): number
Finds the shortest distance between two spaces
Parameters
Name | Type | Description |
---|---|---|
element | GameElement <BaseGame , BasePlayer > | element to measure distance to |
Returns
number
Inherited from
SingleLayout.distanceTo
Defined in
boardzilla-core/src/board/element.ts:552
adjacencies
▸ adjacencies<F
>(className
, ...finders
): ElementCollection
<F
>
Find all elements adjacent based on row/column placement or based on this element having connections created by Space#connectTo. Uses the same parameters as GameElement#all
Type parameters
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
className | ElementClass <F > |
...finders | ElementFinder <F >[] |
Returns
Inherited from
SingleLayout.adjacencies
Defined in
boardzilla-core/src/board/element.ts:564
withinDistance
▸ withinDistance<F
>(distance
, className
, ...finders
): ElementCollection
<F
>
Finds all spaces connected to this space by a distance no more than
distance
Type parameters
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
distance | number |
className | ElementClass <F > |
...finders | ElementFinder <F >[] |
Returns
Inherited from
SingleLayout.withinDistance
Defined in
boardzilla-core/src/board/element.ts:578
setShape
▸ setShape(...shape
): void
Set an irregular shape for this element. This is only meaningful for the purposes of finding specifically adjacent cells when placed into a PieceGrid. See PieceGrid#adjacenciesByCell. When rendered in a PieceGrid, the element will have a size large enough to fill the appropriate number of spaces in the grid, but it's appearance is otherwise unaffected and will be based on appearance. When not rendered in a PieceGrid, the element will take up a single cell but will be scaled relatively to other elements with a shape in the same layout.
Parameters
Name | Type | Description |
---|---|---|
...shape | string [] | A set of single characters used as labels for each cell. The cell label characters are provided as an array of strings, with each string being one row of cell labels, with spaces used to indicate empty "holes" in the shape. Each row must be the same length. The specific non-space characters used are used for labelling the adjacencies in PieceGrid#adjacenciesByCell but are otherwise unimportant. |
Returns
void
Example
domino12.setShape(
'12'
);
tetrisPiece.setShape(
'XX ',
' XX'
);
Inherited from
SingleLayout.setShape
Defined in
boardzilla-core/src/board/element.ts:902
setEdges
▸ setEdges(edges
): void
Set the edge labels for this element. These are only meaningful for the purposes of finding specifically adjacent edges when placed into a PieceGrid. See PieceGrid#adjacenciesByEdge.
Parameters
Name | Type | Description |
---|---|---|
edges | Partial <Record <Direction , string >> | Record <string , Partial <Record <Direction , string >>> | A set of edge labels for each cell label provided by setShape. For simple 1-celled shapes, the edges can be provided without cell labels. |
Returns
void
Example
// a bridge tile with a road leading from left to right and a river leading
// from top to bottom.
simpleTile.setEdge(
up: 'river',
down: 'river',
left: 'road'
right: 'road'
});
// A tetris-shaped tile with sockets coming out either "end"
tetrisPiece.setShape(
'AX ',
' XB'
);
tetrisPiece.setEdge({
A: {
left: 'socket'
},
B: {
right: 'socket'
}
});
Inherited from
SingleLayout.setEdges
Defined in
boardzilla-core/src/board/element.ts:947
Other
layoutAsDrawer
▸ layoutAsDrawer(applyTo
, attributes
): void
Creates a collapsible drawer layout for a Space within this Element. This is like GameElement#layout except for one specific Space, with additional parameters that set the behaviour/appearance of the drawer. A tab will be attached the drawer that will allow it be opened/closed.
Parameters
Name | Type | Description |
---|---|---|
applyTo | string | Space <G , NonNullable <G ["player" ]>> | The Space for the drawer. Either the Space itself or its name. |
attributes | Object | - |
attributes.area? | Box | - |
attributes.openDirection | "left" | "right" | "up" | "down" | - |
attributes.tab? | ReactNode | - |
attributes.closedTab? | ReactNode | - |
attributes.openIf? | (actions : { name : string ; args : Record <string , Argument > }[]) => boolean | - |
attributes.closeIf? | (actions : { name : string ; args : Record <string , Argument > }[]) => boolean | - |
Returns
void
Inherited from
SingleLayout.layoutAsDrawer
Defined in
boardzilla-core/src/board/element.ts:1157
layoutAsTabs
▸ layoutAsTabs(tabs
, attributes
): void
Creates a tabbed layout for a set of Space's within this Element. This is like GameElement#layout except for a set of Spaces, with additional parameters that set the behaviour/appearance of the tabs. Each Space will be laid out into the same area, with a set of tabs attached to allow the Player or the game rules to select which tab is shown.
Parameters
Name | Type | Description |
---|---|---|
tabs | Record <string , string | Space <G , NonNullable <G ["player" ]>>> | JSX for the appearance of the tabs as a set of key-value pairs |
attributes | Object | - |
attributes.area? | Box | - |
attributes.tabDirection | "left" | "right" | "up" | "down" | - |
attributes.tabs? | Record <string , ReactNode > | - |
attributes.setTabTo? | (actions : { name : string ; args : Record <string , Argument > }[]) => string | - |
Returns
void
Inherited from
SingleLayout.layoutAsTabs
Defined in
boardzilla-core/src/board/element.ts:1185
layoutAsPopout
▸ layoutAsPopout(applyTo
, attributes
): void
Hides a Space within this element and replaces it with popout button. Clicking on the button opens this Space in a full-board modal. This is like GameElement#layout except for one Space, with additional parameters that set the behaviour/appearance of the popout modal.
Parameters
Name | Type | Description |
---|---|---|
applyTo | string | Space <G , NonNullable <G ["player" ]>> | The Space for the popout. Either a Space or the name of a Space. |
attributes | Object | - |
attributes.area? | Box | - |
attributes.button | ReactNode | - |
attributes.popoutMargin? | number | { top : number ; bottom : number ; left : number ; right : number } | - |
Returns
void
Inherited from
SingleLayout.layoutAsPopout
Defined in
boardzilla-core/src/board/element.ts:1213
Queries
name
• name: string
Element name, used to distinguish elements. Elements with the same name are generally considered indistibuishable. Names are also used for easy searching of elements.
Inherited from
SingleLayout.name
Defined in
boardzilla-core/src/board/element.ts:241
player
• Optional
player: NonNullable
<G
["player"
]>
Player with which this element is identified. This does not affect
behaviour but will mark the element as mine
in queries in the context of
this player (during an action taken by a player or while the game is
viewed by a given player.).
Inherited from
SingleLayout.player
Defined in
boardzilla-core/src/board/element.ts:250
all
▸ all<F
>(className
, ...finders
): ElementCollection
<F
>
Finds all elements within this element recursively that match the arguments provided.
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.
Inherited from
SingleLayout.all
Defined in
boardzilla-core/src/board/element.ts:379
first
▸ first<F
>(className
, ...finders
): undefined
| F
Finds the first element within this element 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
Inherited from
SingleLayout.first
Defined in
boardzilla-core/src/board/element.ts:391
firstN
▸ firstN<F
>(n
, className
, ...finders
): ElementCollection
<F
>
Finds the first n
elements within this element 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.
Inherited from
SingleLayout.firstN