Class: State<V>
Type parameters
Name | Type |
---|---|
V | extends Record <string , unknown > = Record <string , unknown > |
Hierarchy
Entity
<Record
<string
,unknown
>>Mixin
↳
State
Constructors
constructor
• new State<V
>()
Type parameters
Name | Type |
---|---|
V | extends Record <string , unknown > = Record <string , unknown > |
Overrides
LabelTrait Properties
name
• name: string
Other Properties
childAdded
• childAdded: ChildAddedHandler
childRemoved
• childRemoved: ChildRemovedHandler
clients
• clients: ArraySchema
<GameClient
>
Data of clients who are connected to the room. A "client" is someone who just stopped by in this room and not necessarily someone who is playing the game.
Bots will also be reflected here, but not as direct references to them.
Read-only. Writing to it may break things.
currentPlayerIdx
• currentPlayerIdx: number
= 0
id
• Readonly
id: number
isGameOver
• isGameOver: boolean
= false
isGameStarted
• isGameStarted: boolean
= false
playerViewPosition
• playerViewPosition: PlayerViewPosition
A construct describing how should player's "focused" items be positioned in their view. Containers of other players will not follow these rules. Default is: center/bottom.
players
• players: ArraySchema
<Player
>
List of players - game participants, after the game starts.
TODO: Make players have idx
if you ever need them to change order mid-game
round
• round: number
= 0
Current round number. Increased using NextRound
command.
tableHeight
• tableHeight: number
= 60
tableWidth
• tableWidth: number
= 60
turnBased
• turnBased: boolean
= true
Games are turn-based by default. Each player takes their turns one by one.
Set this to false
to allow simultaneous play.
Don't rely on currentPlayer
value for non turn-based games.
type
• type: string
= "state"
ui
• ui: MapSchema
<string
, string
>
Describes which client-side UI component to reveal to which player. KEY = uiElement, VALUE = clientID
NOTE: It's a very simple example, for more advanced use (eg. UI element visible for multiple certain players) feel free to create your own ui handler in your State
variantData
• variantData: V
Current game's variant data.
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
Accessors
currentPlayer
• get
currentPlayer(): Player
Returns
Methods
addChild
▸ addChild(entity
): void
Adds new item.
Parameters
Name | Type |
---|---|
entity | ChildTrait |
Returns
void
▸ addChild(entity
, prepend
): void
Adds new item.
Parameters
Name | Type |
---|---|
entity | ChildTrait |
prepend | boolean |
Returns
void
▸ addChild(entity
, atIndex
): void
Adds new item.
Parameters
Name | Type | Description |
---|---|---|
entity | ChildTrait | |
atIndex | number | squeeze into desired spot, moving other children away. |
Returns
void
▸ addChild(entity
, arg1
): void
Adds new item.
Parameters
Name | Type |
---|---|
entity | ChildTrait |
arg1 | number | boolean |
Returns
void
addChildren
▸ addChildren(entities
): void
Parameters
Name | Type |
---|---|
entities | ChildTrait [] |
Returns
void
countChildren
▸ countChildren(): number
Number of child elements
Returns
number
create
▸ create(state
, options?
): void
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
options | Partial <Record <string , unknown >> |
Returns
void
Inherited from
getBottom
▸ getBottom<T
>(): T
Get the element with the lowest 'idx' value
Type parameters
Name | Type |
---|---|
T | extends ChildTrait <T > |
Returns
T
getChild
▸ getChild<T
>(idx
): T
Get one direct child of parent
by its idx
Type parameters
Name | Type |
---|---|
T | extends ChildTrait <T > |
Parameters
Name | Type |
---|---|
idx | number |
Returns
T
getChildren
▸ getChildren<T
>(): T
[]
Gets all direct children in array form, "sorted" by idx
Type parameters
Name | Type |
---|---|
T | extends ChildTrait <T > |
Returns
T
[]
getClosestEmptySpot
▸ getClosestEmptySpot(index
): number
unused?
Parameters
Name | Type |
---|---|
index | number |
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
Name | Type |
---|---|
T | extends 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
Name | Type |
---|---|
index | number |
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
Name | Type | Description |
---|---|---|
where | number | direction and range. (+1) - one up, (-2) - two in direction of array start |
start | number | left-most child to manipulate |
end? | number | rightmost 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
Name | Type | Description |
---|---|---|
from | number | index of child to move |
to | number | desired target position |
Returns
void
populateVariantData
▸ populateVariantData(variantDefaults
, variantData
): void
Parameters
Name | Type |
---|---|
variantDefaults | Required <V > |
variantData | V |
Returns
void
query
▸ query<T
>(props
): T
Find one item matching props.
Type parameters
Name | Type |
---|---|
T | extends ChildTrait <T > |
Parameters
Name | Type |
---|---|
props | QuerableProps |
Returns
T
queryAll
▸ queryAll<T
>(props
): T
[]
Looks for every matching entity here and deeper
Type parameters
Name | Type |
---|---|
T | extends ChildTrait <T > |
Parameters
Name | Type |
---|---|
props | QuerableProps |
Returns
T
[]
removeChild
▸ removeChild(child
): boolean
Parameters
Name | Type |
---|---|
child | ChildTrait |
Returns
boolean
removeChildAt
▸ removeChildAt(idx
): boolean
Parameters
Name | Type |
---|---|
idx | number |
Returns
boolean