@cardsgame/server
Namespaces
Bot Classes
Other Classes
Other Interfaces
Room Interfaces
Action definitions Type Aliases
Other Type Aliases
- ActionTemplateCommand
- ActionTemplateConditions
- BaseAssertionTester
- BotActionsSet
- BotEntityAuxAssertionTester
- BotValueTester
- ClientMessageAssertionTester
- ClientMessageConditions
- ClientMessageContext
- CollectionContext
- ConditionErrorMessage
- IntegrationHookCallback
- IntegrationHookCallbackContext
- IntegrationHookData
- IntegrationHookNames
- IntegrationHooks
- QuerableProps
- RoomConstructor
- ServerPlayerMessage
- SortingFunction
- Target
- Targets
Action definitions Functions
Annotation Functions
Bot Functions
Other Functions
Room Functions
State Functions
- getAllBots
- getEntitiesAlongPath
- getNextPlayer
- getNextPlayerIdx
- getPlayerByName
- getPlayersIndex
- getPreviousPlayer
- getPreviousPlayerIdx
Utility Functions
Action definitions Type Aliases
EntityActionTemplateInteraction
Ƭ EntityActionTemplateInteraction<S
>: EntityActionTemplate
<S
>["interaction"
]
Type parameters
Name | Type |
---|---|
S | extends State |
Other Type Aliases
ActionTemplateCommand
Ƭ ActionTemplateCommand<S
>: BaseActionTemplate
<S
>["command"
]
Type parameters
Name | Type |
---|---|
S | extends State |
ActionTemplateConditions
Ƭ ActionTemplateConditions<S
>: BaseActionTemplate
<S
>["conditions"
]
Type parameters
Name | Type |
---|---|
S | extends State |
BaseAssertionTester
Ƭ BaseAssertionTester<S
>: Parameters
<ReturnType
<BaseConditions
<S
>>["test"
]>[0
]
Helper type for test().test(callback)
where you only need State
in the context.
Type parameters
Name | Type |
---|---|
S | extends State |
BotActionsSet
Ƭ BotActionsSet<S
>: Set
<BotNeuron
<S
>>
Type parameters
Name | Type |
---|---|
S | extends State |
BotEntityAuxAssertionTester
Ƭ BotEntityAuxAssertionTester<S
>: Parameters
<ReturnType
<BotEntityAuxConditions
<S
>>["test"
]>[0
]
Helper type for test().test(callback)
related to bot's "entitiesFilter".
Context will only contain state and entity for assertion.
Type parameters
Name | Type |
---|---|
S | extends State |
BotValueTester
Ƭ BotValueTester<S
>: BotNeuron
<S
>["value"
]
Helper type for test().test(callback)
related to bot's "entitiesFilter".
Context will only contain state and entity for assertion.
Type parameters
Name | Type |
---|---|
S | extends State |
ClientMessageAssertionTester
Ƭ ClientMessageAssertionTester<S
>: Parameters
<ReturnType
<ClientMessageConditions
<S
>>["test"
]>[0
]
Helper type for test().test(callback)
related to client message.
Brings context filled with interaction data.
Type parameters
Name | Type |
---|---|
S | extends State |
ClientMessageConditions
Ƭ ClientMessageConditions<S
>: Conditions
<ClientMessageContext
<S
>>
Type parameters
Name | Type |
---|---|
S | extends State |
ClientMessageContext
Ƭ ClientMessageContext<S
>: ClientMessageInitialSubjects
& ConditionsContextBase
<S
>
Type parameters
Name | Type |
---|---|
S | extends State |
CollectionContext
Ƭ CollectionContext<C
>: { aborted
: boolean
; pending
: boolean
} & C
Type parameters
Name | Type |
---|---|
C | extends Record <string , unknown > = Record <string , unknown > |
ConditionErrorMessage
Ƭ ConditionErrorMessage: Object
Type declaration
Name | Type | Description |
---|---|---|
internal | boolean | Is the message internal or provided by the game author? |
message | string | - |
IntegrationHookCallback
Ƭ IntegrationHookCallback<S
>: (state
: S
, context
: IntegrationHookCallbackContext
<S
>) => void
Type parameters
Name | Type |
---|---|
S | extends State |
Type declaration
▸ (state
, context
): void
Parameters
Name | Type |
---|---|
state | S |
context | IntegrationHookCallbackContext <S > |
Returns
void
IntegrationHookCallbackContext
Ƭ IntegrationHookCallbackContext<S
>: Object
Type parameters
Name | Type |
---|---|
S | extends State |
Type declaration
Name | Type |
---|---|
addBot | Room <S >["addBot" ] |
addClient | Room <S >["addClient" ] |
data | Readonly <Record <string , any >> |
IntegrationHookData
Ƭ IntegrationHookData: Record
<string
, any
>
Additional data persisting through the room.
Use it to hold some test-related flags,
eg. data.shuffle: false
to not shuffle Deck on game start.
Will be frozen.
IntegrationHookNames
Ƭ IntegrationHookNames: "init"
| "startPre"
| "startPost"
Depending on integration tests I might allow more hooks.
IntegrationHooks
Ƭ IntegrationHooks<S
>: Partial
<Record
<IntegrationHookNames
, IntegrationHookCallback
<S
>> & { data?
: IntegrationHookData
}>
Pass { test: "integrationTestName" }
options while creating the room.
Your integration test callbacks will be executed on init or start hooks.
Type parameters
Name | Type |
---|---|
S | extends State = State |
QuerableProps
Ƭ QuerableProps: HelperQuerableProps
& EntityQuerableProps
Interface used to search for an entity. An object of props, which appear in every kind of trait and entity, with an addition of:
parent
- describe the parent of an entity you're looking forselected
- query only for selected or not-selected itemsselectionIndex
- query by items selection index, if it was in fact selected
RoomConstructor
Ƭ RoomConstructor<S
, R
>: (presence?
: Presence
) => R
Type parameters
Name | Type |
---|---|
S | extends State |
R | extends Room <S > = Room <S > |
Type declaration
• (presence?
)
Parameters
Name | Type |
---|---|
presence? | Presence |
ServerPlayerMessage
Ƭ ServerPlayerMessage: ClientPlayerMessage
& { draggedEntity?
: unknown
; entities?
: unknown
[] ; entity?
: unknown
; player?
: Player
; timestamp
: number
}
SortingFunction
Ƭ SortingFunction: (childA
: ChildTrait
, childB
: ChildTrait
) => number
Type declaration
▸ (childA
, childB
): number
Parameters
Name | Type |
---|---|
childA | ChildTrait |
childB | ChildTrait |
Returns
number
Target
Ƭ Target<T
>: T
| () => T
Type parameters
Name |
---|
T |
Targets
Ƭ Targets<T
>: T
| T
[] | () => T
| T
[]
Type parameters
Name |
---|
T |
Variables
ALL_CARD_RANKS
• Const
ALL_CARD_RANKS: Rank
[]
All basic ranks in an array (order matters)
ALL_CARD_SUITS
• Const
ALL_CARD_SUITS: Suit
[]
All basic suits in an array (order matters)
ENTITY_INTERACTION
• Const
ENTITY_INTERACTION: "EntityInteraction"
Action definitions Functions
defineCompoundAction
▸ defineCompoundAction<S
>(template
): CompoundActionDefinition
<S
>
@deprecated Focus on drag&drop. Continue with compound once you find a CONCRETE use case for it.
game-moving-cards-test-server might be enough of use case
Type parameters
Name | Type |
---|---|
S | extends State <Record <string , unknown >, S > = State <Record <string , unknown >> |
Parameters
Name | Type |
---|---|
template | CompoundActionTemplate <S > |
Returns
CompoundActionDefinition
<S
>
defineDragAction
▸ defineDragAction<S
>(template
): DragActionDefinition
<S
>
Type parameters
Name | Type |
---|---|
S | extends State <Record <string , unknown >, S > = State <Record <string , unknown >> |
Parameters
Name | Type |
---|---|
template | DragActionTemplate <S > |
Returns
DragActionDefinition
<S
>
defineEntityAction
▸ defineEntityAction<S
>(template
): EntityActionDefinition
<S
>
Type parameters
Name | Type |
---|---|
S | extends State <Record <string , unknown >, S > = State <Record <string , unknown >> |
Parameters
Name | Type |
---|---|
template | EntityActionTemplate <S > |
Returns
EntityActionDefinition
<S
>
defineMessageAction
▸ defineMessageAction<S
>(template
): MessageActionDefinition
<S
>
Type parameters
Name | Type |
---|---|
S | extends State <Record <string , unknown >, S > = State <Record <string , unknown >> |
Parameters
Name | Type |
---|---|
template | MessageActionTemplate <S > |
Returns
MessageActionDefinition
<S
>
Annotation Functions
canBeChild
▸ canBeChild(childConstructor
): void
Decorator! Register an entity class as possible child for any other parent entities.
Example
@canBeChild
export class ClassicCard extends Entity<ClassicCardOptions> {
// ...
}
Parameters
Name | Type |
---|---|
childConstructor | AnyClass |
Returns
void
containsChildren
▸ containsChildren(parentConstructor
): void
Class Decorator! Remember given class as possible parent to any kinds of child entities Also enables syncing any previously remembered children kind on this constructor
Example
@canBeChild
@containsChildren
export class Container extends Entity<ContainerOptions> {
// ...
}
Parameters
Name | Type |
---|---|
parentConstructor | typeof Entity |
Returns
void
Bot Functions
isBot
▸ isBot(player
): player is Bot
Type guard to ensure an object is Bot, and not just Player
Parameters
Name | Type |
---|---|
player | unknown |
Returns
player is Bot
Other Functions
defineTypes
▸ defineTypes(target
, fields
, context?
): typeof Schema
Parameters
Name | Type |
---|---|
target | typeof Schema |
fields | Object |
context? | Context |
Returns
typeof Schema
sortOnChildAdded
▸ sortOnChildAdded(child
): void
TODO: document
Parameters
Name | Type |
---|---|
child | ChildTrait |
Returns
void
standardDeckFactory
▸ standardDeckFactory(ranks?
, suits?
): Pick
<ClassicCard
<Suit
, Rank
>, "suit"
| "rank"
>[]
Will generate an array of card options. Use this array to create actual cards yourself
Example
standardDeckFactory().map(options => {
new ClassicCard({state, ...options})
})
Parameters
Name | Type | Default value | Description |
---|---|---|---|
ranks | Rank [] | ALL_CARD_RANKS | array of desired ranks |
suits | Suit [] | ALL_CARD_SUITS | array of desired suits |
Returns
Pick
<ClassicCard
<Suit
, Rank
>, "suit"
| "rank"
>[]
type
▸ type(typeDef
, typesContext?
): PropertyDecorator
Parameters
Name | Type |
---|---|
typeDef | DefinitionType |
typesContext? | Context |
Returns
PropertyDecorator
Room Functions
defineRoom
▸ defineRoom<S
, R
>(name
, definition
): RoomConstructor
<S
, R
>
Type parameters
Name | Type |
---|---|
S | extends State <Record <string , unknown >, S > |
R | extends Room <S , Record <string , unknown >, R > = Room <S , Record <string , unknown >> |
Parameters
Name | Type |
---|---|
name | string |
definition | RoomDefinition <S > |
Returns
RoomConstructor
<S
, R
>
State Functions
getAllBots
▸ getAllBots(state
): Bot
[]
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
Returns
Bot
[]
getEntitiesAlongPath
▸ getEntitiesAlongPath(state
, path
): IdentityTrait
[]
Gets an array of all entities from the top-most parent to the lowest of the child.
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
path | number [] |
Returns
getNextPlayer
▸ getNextPlayer(state
): Player
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
Returns
getNextPlayerIdx
▸ getNextPlayerIdx(state
): number
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
Returns
number
getPlayerByName
▸ getPlayerByName(state
, name
): Player
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
name | string |
Returns
getPlayersIndex
▸ getPlayersIndex(state
, player
): number
Will get you an index of given player in turn queue.
Useful if you happen to have just a Player
reference at hand.
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
player | Player |
Returns
number
getPreviousPlayer
▸ getPreviousPlayer(state
): Player
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
Returns
getPreviousPlayerIdx
▸ getPreviousPlayerIdx(state
): number
Parameters
Name | Type |
---|---|
state | State <Record <string , unknown >> |
Returns
number
Utility Functions
defaultHandOfCardsSorting
▸ defaultHandOfCardsSorting(childA
, childB
): number
TODO: document
Parameters
Name | Type |
---|---|
childA | ClassicCard <Suit , Rank > |
childB | ClassicCard <Suit , Rank > |
Returns
number
getRandomName
▸ getRandomName(): string
Returns
string