Skip to main content

@cardsgame/server

Namespaces

Bot Classes

Other Classes

Other Interfaces

Room Interfaces

Action definitions Type Aliases

Other Type Aliases

Action definitions Functions

Annotation Functions

Bot Functions

Other Functions

Room Functions

State Functions

Utility Functions

Action definitions Type Aliases

EntityActionTemplateInteraction

Ƭ EntityActionTemplateInteraction<S>: EntityActionTemplate<S>["interaction"]

Type parameters

NameType
Sextends State

Other Type Aliases

ActionTemplateCommand

Ƭ ActionTemplateCommand<S>: BaseActionTemplate<S>["command"]

Type parameters

NameType
Sextends State

ActionTemplateConditions

Ƭ ActionTemplateConditions<S>: BaseActionTemplate<S>["conditions"]

Type parameters

NameType
Sextends 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

NameType
Sextends State

BotActionsSet

Ƭ BotActionsSet<S>: Set<BotNeuron<S>>

Type parameters

NameType
Sextends 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

NameType
Sextends 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

NameType
Sextends 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

NameType
Sextends State

ClientMessageConditions

Ƭ ClientMessageConditions<S>: Conditions<ClientMessageContext<S>>

Type parameters

NameType
Sextends State

ClientMessageContext

Ƭ ClientMessageContext<S>: ClientMessageInitialSubjects & ConditionsContextBase<S>

Type parameters

NameType
Sextends State

CollectionContext

Ƭ CollectionContext<C>: { aborted: boolean ; pending: boolean } & C

Type parameters

NameType
Cextends Record<string, unknown> = Record<string, unknown>

ConditionErrorMessage

Ƭ ConditionErrorMessage: Object

Type declaration

NameTypeDescription
internalbooleanIs the message internal or provided by the game author?
messagestring-

IntegrationHookCallback

Ƭ IntegrationHookCallback<S>: (state: S, context: IntegrationHookCallbackContext<S>) => void

Type parameters

NameType
Sextends State

Type declaration

▸ (state, context): void

Parameters
NameType
stateS
contextIntegrationHookCallbackContext<S>
Returns

void


IntegrationHookCallbackContext

Ƭ IntegrationHookCallbackContext<S>: Object

Type parameters

NameType
Sextends State

Type declaration

NameType
addBotRoom<S>["addBot"]
addClientRoom<S>["addClient"]
dataReadonly<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

NameType
Sextends 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 for
  • selected - query only for selected or not-selected items
  • selectionIndex - query by items selection index, if it was in fact selected

RoomConstructor

Ƭ RoomConstructor<S, R>: (presence?: Presence) => R

Type parameters

NameType
Sextends State
Rextends Room<S> = Room<S>

Type declaration

• (presence?)

Parameters
NameType
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
NameType
childAChildTrait
childBChildTrait
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

NameType
Sextends State<Record<string, unknown>, S> = State<Record<string, unknown>>

Parameters

NameType
templateCompoundActionTemplate<S>

Returns

CompoundActionDefinition<S>


defineDragAction

defineDragAction<S>(template): DragActionDefinition<S>

Type parameters

NameType
Sextends State<Record<string, unknown>, S> = State<Record<string, unknown>>

Parameters

NameType
templateDragActionTemplate<S>

Returns

DragActionDefinition<S>


defineEntityAction

defineEntityAction<S>(template): EntityActionDefinition<S>

Type parameters

NameType
Sextends State<Record<string, unknown>, S> = State<Record<string, unknown>>

Parameters

NameType
templateEntityActionTemplate<S>

Returns

EntityActionDefinition<S>


defineMessageAction

defineMessageAction<S>(template): MessageActionDefinition<S>

Type parameters

NameType
Sextends State<Record<string, unknown>, S> = State<Record<string, unknown>>

Parameters

NameType
templateMessageActionTemplate<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

NameType
childConstructorAnyClass

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

NameType
parentConstructortypeof Entity

Returns

void


Bot Functions

isBot

isBot(player): player is Bot

Type guard to ensure an object is Bot, and not just Player

Parameters

NameType
playerunknown

Returns

player is Bot


Other Functions

defineTypes

defineTypes(target, fields, context?): typeof Schema

Parameters

NameType
targettypeof Schema
fieldsObject
context?Context

Returns

typeof Schema


sortOnChildAdded

sortOnChildAdded(child): void

TODO: document

Parameters

NameType
childChildTrait

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

NameTypeDefault valueDescription
ranksRank[]ALL_CARD_RANKSarray of desired ranks
suitsSuit[]ALL_CARD_SUITSarray of desired suits

Returns

Pick<ClassicCard<Suit, Rank>, "suit" | "rank">[]


type

type(typeDef, typesContext?): PropertyDecorator

Parameters

NameType
typeDefDefinitionType
typesContext?Context

Returns

PropertyDecorator


Room Functions

defineRoom

defineRoom<S, R>(name, definition): RoomConstructor<S, R>

Type parameters

NameType
Sextends State<Record<string, unknown>, S>
Rextends Room<S, Record<string, unknown>, R> = Room<S, Record<string, unknown>>

Parameters

NameType
namestring
definitionRoomDefinition<S>

Returns

RoomConstructor<S, R>


State Functions

getAllBots

getAllBots(state): Bot[]

Parameters

NameType
stateState<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

NameType
stateState<Record<string, unknown>>
pathnumber[]

Returns

IdentityTrait[]


getNextPlayer

getNextPlayer(state): Player

Parameters

NameType
stateState<Record<string, unknown>>

Returns

Player


getNextPlayerIdx

getNextPlayerIdx(state): number

Parameters

NameType
stateState<Record<string, unknown>>

Returns

number


getPlayerByName

getPlayerByName(state, name): Player

Parameters

NameType
stateState<Record<string, unknown>>
namestring

Returns

Player


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

NameType
stateState<Record<string, unknown>>
playerPlayer

Returns

number


getPreviousPlayer

getPreviousPlayer(state): Player

Parameters

NameType
stateState<Record<string, unknown>>

Returns

Player


getPreviousPlayerIdx

getPreviousPlayerIdx(state): number

Parameters

NameType
stateState<Record<string, unknown>>

Returns

number


Utility Functions

defaultHandOfCardsSorting

defaultHandOfCardsSorting(childA, childB): number

TODO: document

Parameters

NameType
childAClassicCard<Suit, Rank>
childBClassicCard<Suit, Rank>

Returns

number


getRandomName

getRandomName(): string

Returns

string