repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
boardzilla-core
github_2023
boardzilla
typescript
GameElement.position
position() { return this._t.parent?._t.children.indexOf(this) ?? -1; }
/** * Returns the index of this element within its parent, starting at zero * @category Structure */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L771-L773
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.branch
branch() { const branches = []; let node = this as GameElement; while (node._t.parent) { const index = node.position(); if (index === -1) throw Error(`Reference to element ${this.constructor.name}${this.name ? ':' + this.name : ''} is no longer current`); branches.unshift(index); nod...
/** * Returns a string identifying the tree position of the element suitable for * anonymous reference * @internal */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L780-L791
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.atBranch
atBranch(b: string) { let branch = b.split('/'); let index = parseInt(branch[0]); let node = index === 0 ? this._ctx.top : this._ctx.removed._t.children[index - 1]; branch.shift(); while (branch[0] !== undefined) { node = node._t.children[parseInt(branch[0])]; branch.shift(); } r...
/** * Returns the element at the given position returned by {@link branch} * @internal */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L797-L807
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.atID
atID(id: number): GameElement | undefined { let el = this._t.children.find(c => c._t.id === id); if (el) return el; for (const child of this._t.children) { el = child.atID(id); if (el) return el; } }
/** * Returns the element for the given id * @internal */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L813-L820
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.atRef
atRef(ref: number): GameElement | undefined { let el = this._t.children.find(c => c._t.ref === ref); if (el) return el; for (const child of this._t.children) { el = child.atRef(ref); if (el) return el; } }
/** * Returns the element for the given ref * @internal */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L826-L833
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.setShape
setShape(...shape: string[]) { if (this._ctx.gameManager?.phase === 'started') throw Error('Cannot change shape once game has started.'); if (shape.some(s => s.length !== shape[0].length)) throw Error("Each row in shape must be same size. Invalid shape:\n" + shape); this._size = { shape, width: ...
/** * 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 {@link PieceGrid#adjacenciesByCell}. When rendered in a * PieceGrid, the element will have a size large enough to fill the * appropriate num...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L876-L884
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.setEdges
setEdges(edges: Record<string, Partial<Record<Direction, string>>> | Partial<Record<Direction, string>>) { if (this._ctx.gameManager?.phase === 'started') throw Error('Cannot change shape once game has started.'); if (Object.keys(edges)[0].length === 1) { const missingCell = Object.keys(edges).find(c => t...
/** * 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 {@link PieceGrid#adjacenciesByEdge}. * @category Adjacency * * @param edges - A set of edge labels for each cell label provided by {@link ...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L921-L931
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.isDescendantOf
isDescendantOf(el: GameElement): boolean { return this._t.parent === el || !!this._t.parent?.isDescendantOf(el) }
/** * Whether this element has the given element in its parent hierarchy * @category Structure */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L937-L939
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.toJSON
toJSON(seenBy?: number) { let attrs = this.attributeList(); // remove hidden attributes if (seenBy !== undefined && !this.isVisibleTo(seenBy)) { attrs = Object.fromEntries(Object.entries(attrs).filter( ([attr]) => ['_visible', 'row', 'column', '_rotation', '_size'].includes(attr) || ...
/** * JSON representation * @param seenBy - optional player position viewing the game * @internal */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L957-L990
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.layout
layout( applyTo: typeof this._ui.layouts[number]['applyTo'], attributes: Partial<LayoutAttributes> ) { let {slots, area, size, aspectRatio, scaling, gap, margin, offsetColumn, offsetRow} = attributes if (slots && (area || margin || scaling || gap || margin || offsetColumn || offsetRow)) { consol...
/** * Apply a layout to some of the elements directly contained within this * element. See also {@link ElementCollection#layout} * @category UI * * @param applyTo - Which elements this layout applies to. Provided value can be: * - A specific {@link GameElement} * - The name of an element * - A s...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L1079-L1110
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.layoutAsDrawer
layoutAsDrawer(applyTo: Space<G, P> | string, attributes: { area?: Box, openDirection: 'left' | 'right' | 'down' | 'up', tab?: React.ReactNode, closedTab?: React.ReactNode, openIf?: (actions: { name: string, args: Record<string, Argument> }[]) => boolean, closeIf?: (actions: { name: string, args...
/** * Creates a collapsible drawer layout for a Space within this Element. This * is like {@link 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. * *...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L1131-L1141
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.layoutAsTabs
layoutAsTabs(tabs: Record<string, Space<G, P> | string>, attributes: { area?: Box, tabDirection: 'left' | 'right' | 'down' | 'up', tabs?: Record<string, React.ReactNode>, setTabTo?: (actions: { name: string, args: Record<string, Argument> }[]) => string, }) { const { area, ...container } = attribu...
/** * Creates a tabbed layout for a set of Space's within this Element. This is * like {@link 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...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L1159-L1170
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.layoutAsPopout
layoutAsPopout(applyTo: Space<G, P> | string, attributes: { area?: Box, button: React.ReactNode, popoutMargin?: number | { top: number, bottom: number, left: number, right: number }, }) { const { area, ...container } = attributes; this.layout(applyTo, { area, __container__: { type: 'popout', attri...
/** * 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 {@link GameElement#layout} except for one Space, with additional * parameters that set the behaviour/appearance of the popout modal. * * @param ap...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L1187-L1194
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.configureLayout
configureLayout(layoutConfiguration: Partial<LayoutAttributes>) { this._ui.layouts[0] = { applyTo: GameElement, attributes: { ...this._ui.getBaseLayout(), ...layoutConfiguration, } }; }
/** * Change the layout attributes for this space's layout. * @category UI */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L1200-L1208
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
GameElement.appearance
appearance(appearance: ElementUI<this>['appearance']) { Object.assign(this._ui.appearance, appearance); }
/** * Define the appearance of this element. Any values provided override * previous ones. See also {@link ElementCollection#appearance} * @category UI * * @param appearance - Possible values are: * @param appearance.className - A class name to add to the dom element * * @param appearance.render...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L1241-L1243
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.registerClasses
registerClasses(...classList: ElementClass[]) { this._ctx.classRegistry = this._ctx.classRegistry.concat(classList); }
// no longer needed - remove in next minor release
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L161-L163
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.defineFlow
defineFlow(...flow: FlowStep[]) { this.defineSubflow('__main__', ...flow); }
/** * Define your game's main flow. May contain any of the following: * - {@link playerActions} * - {@link loop} * - {@link whileLoop} * - {@link forEach} * - {@link forLoop} * - {@link eachPlayer} * - {@link everyPlayer} * - {@link ifElse} * - {@link switchCase} * @category Definition ...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L178-L180
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.defineSubflow
defineSubflow(name: string, ...flow: FlowStep[]) { if (this._ctx.gameManager.phase !== 'new') throw Error('cannot call defineFlow once started'); this._ctx.gameManager.flows[name] = new Flow({ name, do: flow }); this._ctx.gameManager.flows[name].gameManager = this._ctx.gameManager; }
/** * Define an addtional flow that the main flow can enter. A subflow has a * unique name and can be entered at any point by calling {@link * Do|Do.subflow}. * * @param name - Unique name of flow * @param flow - Steps of the flow */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L190-L194
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.defineActions
defineActions(actions: Record<string, (player: P) => Action<Record<string, Argument>>>) { if (this._ctx.gameManager.phase !== 'new') throw Error('cannot call defineActions once started'); this._ctx.gameManager.actions = actions; }
/** * Define your game's actions. * @param actions - An object consisting of actions where the key is the name * of the action and value is a function that accepts a player taking the * action and returns the result of calling {@link action} and chaining * choices, results and messages onto the result ...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L204-L207
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.setting
setting(key: string) { return this._ctx.gameManager.settings[key]; }
/** * Retrieve the selected setting value for a setting defined in {@link * render}. * @category Definition */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L214-L216
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.action
action<A extends Record<string, Argument> = NonNullable<unknown>>(definition: { prompt?: string, description?: string, condition?: Action<A>['condition'], } = {}) { return new Action<A>(definition); }
/** * Create an {@link Action}. An action is a single move that a player can * take. Some actions require choices, sometimes several, before they can be * executed. Some don't have any choices, like if a player can simply * 'pass'. What defines where one action ends and another begins is how much * you a...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L268-L274
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.followUp
followUp(action: ActionStub) { Do.subflow('__followup__', action); }
/** * Queue up a follow-up action while processing an action. If called during * the processing of a game action, the follow-up action given will be added * as a new action immediately following the current one, before the game's * flow can resume normally. This is common for card games where the play of a ...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L303-L305
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.finish
finish(winner?: P | P[], announcement?: string) { this._ctx.gameManager.phase = 'finished'; if (winner) this._ctx.gameManager.winner = winner instanceof Array ? winner : [winner]; this._ctx.gameManager.announcements.push(announcement ?? '__finish__'); }
/** * End the game * * @param winner - a player or players that are the winners of the game. In a * solo game if no winner is provided, this is considered a loss. * @param announcement - an optional announcement from {@link render} to * replace the standard boardzilla announcement. * @category Game...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L348-L352
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.getWinners
getWinners() { let winner = this._ctx.gameManager.winner; if (!(winner instanceof Array)) winner = [winner]; return this._ctx.gameManager.phase === 'finished' ? winner : undefined; }
/** * Return array of game winners, or undefined if game is not yet finished * @category Game Management */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L358-L362
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.addDelay
addDelay() { this.resetMovementTracking(); if (this.game._ctx.trackMovement) { this._ctx.gameManager.sequence += 1; } else if (this._ctx.gameManager.intermediateUpdates.length) { return; // even if not tracking, record one intermediate to allow UI to extract proper state to animate towards }...
/** * Add a delay in the animation of the state change at this point for player * as they receive game updates. * @category Game Management */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L369-L379
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.message
message(text: string, args?: Record<string, Argument>) { this._ctx.gameManager.messages.push({body: n(text, args, true)}); }
/** * Add a message that will be broadcast in the chat at the next game update, * based on the current state of the game. * * @param text - The text of the message to send. This can contain interpolated strings * with double braces, i.e. {{player}} that are defined in args. Of course, * strings can be...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L402-L404
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.messageTo
messageTo(player: (BasePlayer | number) | (BasePlayer | number)[], text: string, args?: Record<string, Argument>) { if (!(player instanceof Array)) player = [player]; for (const p of player) { this._ctx.gameManager.messages.push({ body: n(text, args, true), position: typeof p === 'number' ...
/** * Add a message that will be broadcast to the given player(s) in the chat at * the next game update, based on the current state of the game. * * @param player - Player or players to receive the message * * @param text - The text of the message to send. This can contain interpolated strings * wi...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L429-L437
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.announce
announce(announcement: string) { this._ctx.gameManager.announcements.push(announcement); this.addDelay(); this._ctx.gameManager.announcements = []; }
/** * Broadcast a message to all players that interrupts the game and requires * dismissal before actions can be taken. * * @param announcement - The modal name to announce, as provided in {@link render}. * * @example * game.message( * '{{player}} has a score of {{score}}', * { player, sc...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L453-L457
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.allJSON
allJSON(seenBy?: number): ElementJSON[] { return [this.toJSON(seenBy)].concat( this._ctx.removed._t.children.map(el => el.toJSON(seenBy)) ); }
// also gets removed elements
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L460-L464
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.fromJSON
fromJSON(boardJSON: ElementJSON[]) { let { className, children, _id, order, ...rest } = boardJSON[0]; if (this.constructor.name !== className) throw Error(`Cannot create board from JSON. ${className} must equal ${this.constructor.name}`); // reset all on self - think this is unnecessary? if it is, need to ...
// hydrate from json, and assign all attrs. requires that players be hydrated first
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L467-L484
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.resetUI
resetUI() { super.resetUI(); this._ui.stepLayouts = {}; }
// restore default layout rules before running setupLayout
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L515-L518
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.layoutControls
layoutControls(attributes: ActionLayout) { this._ui.stepLayouts["*"] = attributes; }
/** * Apply default layout rules for all the placement of all player prompts and * choices, in relation to the playing area * * @param attributes - see {@link ActionLayout} * * @category UI */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L543-L545
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.layoutStep
layoutStep(step: string, attributes: ActionLayout) { if (!this._ctx.gameManager.getFlowStep(step)) throw Error(`No such step: ${step}`); this._ui.stepLayouts["step:" + step] = attributes; }
/** * Apply layout rules to a particular step in the flow, controlling where * player prompts and choices appear in relation to the playing area * * @param step - the name of the step as defined in {@link playerActions} * @param attributes - see {@link ActionLayout} * * @category UI */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L556-L559
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.layoutAction
layoutAction(action: string, attributes: ActionLayout) { this._ui.stepLayouts["action:" + action] = attributes; }
/** * Apply layout rules to a particular action, controlling where player prompts * and choices appear in relation to the playing area * * @param action - the name of the action as defined in {@link game#defineActions} * @param attributes - see {@link ActionLayout} * * @category UI */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L570-L572
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.disableDefaultAppearance
disableDefaultAppearance() { this._ui.disabledDefaultAppearance = true; }
/** * Remove all built-in default appearance. If any elements have not been given a * custom appearance, this causes them to be hidden. * * @category UI */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L580-L582
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Game.showLayoutBoundingBoxes
showLayoutBoundingBoxes() { this._ui.boundingBoxes = true; }
/** * Show bounding boxes around every layout * * @category UI */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/game.ts#L589-L591
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PieceGrid.cellsAround
cellsAround(piece: Piece<G>, pos: Vector) { const adjacencies: Partial<Record<DirectionWithDiagonals, string>> = { up: piece._cellAt({y: pos.y - 1, x: pos.x}), down: piece._cellAt({y: pos.y + 1, x: pos.x}), left: piece._cellAt({y: pos.y, x: pos.x - 1}), right: piece._cellAt({y: pos.y, x: pos...
// internal
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece-grid.ts#L80-L94
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PieceGrid.isOverlapping
isOverlapping(piece: Piece<G>, other?: Piece<G>): boolean { if (!other) { return this._t.children.some(p => p !== piece && this.isOverlapping(piece, p as Piece<G>)); } const p1: Vector = {x: piece.column!, y: piece.row!}; const p2: Vector = {x: other.column!, y: other.row!}; if (!piece._size &...
// internal
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece-grid.ts#L97-L124
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PieceGrid._fitPieceInFreePlace
_fitPieceInFreePlace(piece: Piece<G>, rows: number, columns: number, origin: {column: number, row: number}) { const tryLaterally = (vertical: boolean, d: number): boolean => { for (let lateral = 0; lateral < d + (vertical ? 0 : 1); lateral = -lateral + (lateral < 1 ? 1 : 0)) { if (vertical) { ...
// internal
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece-grid.ts#L127-L171
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PieceGrid.adjacenciesByCell
adjacenciesByCell(piece: Piece<G>, other?: Piece<G>): {piece: Piece<G>, from: string, to: string}[] { if (!other) { return this._t.children.reduce( (all, p) => all.concat(p !== piece ? this.adjacenciesByCell(piece, p as Piece<G>) : []), [] as {piece: Piece<G>, from: string, to: string}[] ...
/** * Returns a list of other Pieces in the grid that have a touching edge (or * touching corner if {@link diagonalAdjacency} is true} with this shape. Each * item in the list contains the adjacent Piece, as well as the string * representation of cells in both pieces, as provided in {@link * Piece#setSha...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece-grid.ts#L201-L248
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PieceGrid.adjacenciesByEdge
adjacenciesByEdge(piece: Piece<G>, other?: Piece<G>): {piece: Piece<G>, from?: string, to?: string}[] { if (!other) { const children = this._t.children; return children.reduce( (all, p) => all.concat(p !== piece ? this.adjacenciesByEdge(piece, p as Piece<G>) : []), [] as {piece: Piece<G>...
/** * Returns a list of other Pieces in the grid that have a touching edge with * this shape. Each item in the list contains the adjacent Piece, as well as * the string representation of the edges in both pieces, as provided in * {@link Piece#setEdges}. * @category Adjacency * * @param piece - The ...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece-grid.ts#L287-L338
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.showToAll
showToAll() { delete(this._visible); }
/** * Show this piece to all players * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L31-L33
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.showOnlyTo
showOnlyTo(player: Player | number) { if (typeof player !== 'number') player = player.position; this._visible = { default: false, except: [player] }; }
/** * Show this piece only to the given player * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L39-L45
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.showTo
showTo(...player: Player[] | number[]) { if (typeof player[0] !== 'number') player = (player as Player[]).map(p => p.position); if (this._visible === undefined) return; if (this._visible.default) { if (!this._visible.except) return; this._visible.except = this._visible.except.filter(i => !(playe...
/** * Show this piece to the given players without changing it's visibility to * any other players. * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L52-L61
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.hideFromAll
hideFromAll() { this._visible = {default: false}; }
/** * Hide this piece from all players * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L67-L69
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.hideFrom
hideFrom(...player: Player[] | number[]) { if (typeof player[0] !== 'number') player = (player as Player[]).map(p => p.position); if (this._visible?.default === false && !this._visible.except) return; if (this._visible === undefined || this._visible.default === true) { this._visible = { defaul...
/** * Hide this piece from the given players without changing it's visibility to * any other players. * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L76-L88
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.isVisibleTo
isVisibleTo(player: Player | number) { if (typeof player !== 'number') player = player.position; if (this._visible === undefined) return true; if (this._visible.default) { return !this._visible.except || !(this._visible.except.includes(player)); } else { return this._visible.except?.includes...
/** * Returns whether this piece is visible to the given player * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L94-L102
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.isVisible
isVisible() { if (this._ctx.player) return this.isVisibleTo(this._ctx.player.position); return this._visible?.default !== false && (this._visible?.except ?? []).length === 0; }
/** * Returns whether this piece is visible to all players, or to the current * player if called when in a player context (during an action taken by a * player or while the game is viewed by a given player.) * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L110-L113
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.revealWhenHidden
static revealWhenHidden<T extends Piece<BaseGame>>(this: ElementClass<T>, ...attrs: (string & keyof T)[]): void { this.visibleAttributes = attrs; }
/** * Provide list of attributes that remain visible even when these pieces are * not visible to players. E.g. In a game with multiple card decks with * different backs, identified by Card#deck, the identity of the card when * face-down is hidden, but the deck it belongs to is not, since the card art * o...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L126-L128
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.putInto
putInto(to: GameElement, options?: {position?: number, row?: number, column?: number, fromTop?: number, fromBottom?: number}) { if (to.isDescendantOf(this)) throw Error(`Cannot put ${this} into itself`); let pos: number = to._t.order === 'stacking' ? 0 : to._t.children.length; if (options?.position !== unde...
/** * Move this piece into another element. This triggers any {@link * Space#onEnter | onEnter} callbacks in the destination. * @category Structure * * @param to - Destination element * @param options.position - Place the piece into a specific numbered position * relative to the other elements in t...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L144-L168
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Piece.remove
remove() { return this.putInto(this._ctx.removed); }
/** * Remove this piece from the playing area and place it into {@link * Game#pile} * @category Structure */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/piece.ts#L192-L194
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.contentsWillBeShown
contentsWillBeShown() { this._visOnEnter = {default: true}; }
/** * Show pieces to all players when they enter this space * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L35-L37
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.contentsWillBeShownToOwner
contentsWillBeShownToOwner() { this._visOnEnter = {default: false, except: 'owner'}; }
/** * Show pieces when they enter this space to its owner * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L43-L45
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.contentsWillBeShownTo
contentsWillBeShownTo(...players: P[]) { this._visOnEnter = {default: false, except: players.map(p => p.position)}; }
/** * Show piece to these players when they enter this space * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L51-L53
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.contentsWillBeHidden
contentsWillBeHidden() { this._visOnEnter = {default: false}; }
/** * Hide pieces to all players when they enter this space * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L59-L61
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.contentsWillBeHiddenFrom
contentsWillBeHiddenFrom(...players: P[]) { this._visOnEnter = {default: true, except: players.map(p => p.position)}; }
/** * Hide piece to these players when they enter this space * @category Visibility */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L67-L69
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.blockViewFor
blockViewFor(players: 'all' | 'none' | 'all-but-owner' | Player[]) { this._screen = players === 'none' ? undefined : players instanceof Array ? players.map(p => p.position) : players }
/** * Call this to screen view completely from players. Blocked spaces completely * hide their contents, like a physical screen. No information about the * number, type or movement of contents inside this Space will be revealed to * the specified players * * @param players = Players for whom the view ...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L80-L82
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.onEnter
onEnter<T extends GameElement>(type: ElementClass<T>, callback: (el: T) => void) { this.addEventHandler<T>("enter", { callback, type }); }
/** * Attach a callback to this space for every element that enters or is created * within. * @category Structure * * @param type - the class of element that will trigger this callback * @param callback - Callback will be called each time an element enters, with * the entering element as the only a...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L109-L111
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Space.onExit
onExit<T extends GameElement>(type: ElementClass<T>, callback: (el: T) => void) { this.addEventHandler<T>("exit", { callback, type }); }
/** * Attach a callback to this space for every element that is moved out of this * space. * @category Structure * * @param type - the class of element that will trigger this callback * @param callback - Callback will be called each time an element exits, with * the exiting element as the only argu...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/space.ts#L125-L127
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
D6.roll
roll() { this.current = Math.ceil((this.game.random || Math.random)() * this.sides); this.rollSequence = this._ctx.gameManager.sequence; }
/** * Randomly choose a new face, causing the roll animation * @category D6 */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/components/d6/d6.ts#L28-L31
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flippable
const Flippable = ({ children }: { children?: React.ReactNode, }) => { let frontContent: React.ReactNode = null; let backContent: React.ReactNode = null; React.Children.forEach(children, child => { if (!React.isValidElement(child)) return; if (child.type === Flippable.Front) { frontContent = chil...
/** * A Piece with two sides: front and back. When the Piece is hidden, the back is * shown. When visible, the front is shown. When the visibility changes, the CSS * animates a 3d flip. * * @example * import { Flippable } from '@boardzilla/core/components'; * ... * Piece.appearance({ * render: piece => (...
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/components/flippable/Flippable.tsx#L27-L54
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
ActionStep.allowedActions
allowedActions(): string[] { return this.position ? [] : this.actions.map(a => a.name); }
// current actions that can process. does not check player
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/action-step.ts#L106-L108
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
ActionStep.processMove
processMove(move: { player: number, name: string, args: Record<string, Argument>, }): string | SubflowSignal['data'][] | undefined { if ((move.name !== '__continue__' || !this.continueIfImpossible) && !this.allowedActions().includes(move.name)) { throw Error(`No action ${move.name} available at ...
// returns error (string) or subflow {args, name} or ok (undefined)
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/action-step.ts#L137-L183
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
EveryPlayer.withPlayer
withPlayer<T>(value: number, fn: () => T, mutate=false): T { this.value = value; this.sequence = this.position.sequences[this.value]; this.setPosition(this.position, this.sequence); const result = fn(); if (mutate) { const currentPlayer = this.getPlayers()[this.value]; // capture positio...
// specific player and pretend to be a normal flow with just one subflow
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/every-player.ts#L43-L57
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
EveryPlayer.branchJSON
branchJSON(forPlayer=true): FlowBranchJSON[] { if (this.position === undefined && this.sequence === undefined) return []; // probably invalid let branch: FlowBranchJSON = { type: this.type, position: {positions: [], sequences: this.position.sequences, completed: this.completed} }; if (this.n...
// reimpl ourselves to collect json from all players
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/every-player.ts#L64-L78
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
EveryPlayer.setPosition
setPosition(positionJSON: any, sequence?: number) { const player = this.getPlayers()[this.value]; this.completed = positionJSON.completed; if (player) { player.setCurrent(); positionJSON.sequences[this.value] = sequence; } else { // not looking at an individual player. set game state t...
// add player management, hydration of flow for the correct player, sequences[] management
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/every-player.ts#L81-L99
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
EveryPlayer.playOneStep
playOneStep(): InterruptSignal[] | FlowControl | Flow { // step through each player over top of the normal super stepping const player = this.getPlayers().findIndex((_, p) => this.completed[p] === undefined); if (player !== -1) { // run for next player without a resolution return this.withPlaye...
// without us checking all branches
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/every-player.ts#L128-L145
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.playOneStep
playOneStep(): InterruptSignal[] | FlowControl | Flow { const step = this.step; let result: InterruptSignal[] | FlowControl | Flow = FlowControl.complete; if (step instanceof Function) { if (!interruptSignal[0]) step(this.flowStepArgs()); result = FlowControl.complete; if (interruptSignal[...
/** * Advance flow one step and return FlowControl.complete if complete, * FlowControl.ok if can continue, Do to interrupt the current loop. Returns * ActionStep if now waiting for player input. override for self-contained * flows that do not have subflows. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L253-L280
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.play
play() { interruptSignal.splice(0); let step; do { if (this.gameManager.phase !== 'finished') step = this.playOneStep(); if (!(step instanceof Flow)) console.debug(`Advancing flow:\n ${this.stacktrace()}`); } while (step === FlowControl.ok && interruptSignal[0]?.signal !== InterruptControl.s...
// play until action required (returns ActionStep) or flow complete (undefined) or subflow started {name, args}
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L283-L298
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.reset
reset() { this.setPosition(undefined); }
// must override. reset runs any logic needed and call setPosition. Must not modify own state.
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L301-L303
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.currentBlock
currentBlock(): FlowDefinition | undefined { return this.block; }
// must override. must rely solely on this.position
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L306-L308
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.toJSON
toJSON(_forPlayer=true): any { return this.position; }
// override if position contains objects that need serialization
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L311-L313
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.fromJSON
fromJSON(json: any): typeof this.position { return json; }
// override if position contains objects that need deserialization
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L316-L318
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.advance
advance(): FlowControl { return FlowControl.complete; }
// override for steps that advance through their subflows. call setPosition if needed. return ok/complete
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L321-L323
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Flow.allSteps
allSteps(): FlowDefinition | undefined { return this.block; }
// override return all subflows
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/flow/flow.ts#L326-L328
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.atPosition
atPosition(position: number) { return this.find(p => p.position === position); }
/** * Returns the player at a given table position. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L41-L43
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.current
current(): P | undefined { if (this.currentPosition.length > 1) throw Error(`Using players.current when ${this.currentPosition.length} players may act`); return this.atPosition(this.currentPosition[0] ?? -1); }
/** * Returns the player that may currently act. It is an error to call current * when multiple players can act */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L49-L52
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.allCurrent
allCurrent(): P[] { return this.currentPosition.map(p => this.atPosition(p)!); }
/** * Returns the array of all players that may currently act. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L57-L59
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.host
host(): P { return this.find(p => p.host)!; }
/** * Returns the host player */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L64-L66
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.notCurrent
notCurrent() { return this.filter(p => !this.currentPosition.includes(p.position)); }
/** * Returns the array of players that may not currently act. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L71-L73
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.inPositionOrder
inPositionOrder() { return this.sort((p1, p2) => (p1.position > p2.position ? 1 : -1)); }
/** * Returns the array of players in the order of table positions. Does not * alter the actual player order. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L79-L81
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.setCurrent
setCurrent(players: number | P | number[] | P[]) { if (!(players instanceof Array)) players = [players] as number[] | P[]; players = players.map(p => typeof p === 'number' ? p : p.position); this.currentPosition = players; }
/** * Set the current player(s). * * @param players - The {@link Player} or table position of the player to act, * or an array of either. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L89-L93
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.next
next() { if (this.currentPosition.length === 0) { this.currentPosition = [this[0].position]; } else if (this.currentPosition.length === 1) { this.currentPosition = [this.after(this.currentPosition[0]).position]; } return this.current()! }
/** * Advance the current player to act to the next player based on player order. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L98-L105
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.after
after(player: number | P) { return this[(this.turnOrderOf(player) + 1) % this.length]; }
/** * Return the next player to act based on player order. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L110-L112
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.seatedNext
seatedNext(player: P, steps = 1) { return this.atPosition((player.position + steps - 1) % this.length + 1)!; }
/** * Return the player next to this player at the table. * @param steps - 1 = one step to the left, -1 = one step to the right, etc */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L118-L120
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.turnOrderOf
turnOrderOf(player: number | P) { if (typeof player !== 'number') player = player.position; const index = this.findIndex(p => p.position === player); if (index === -1) throw Error("No such player"); return index; }
/** * Returns the turn order of the given player, starting with 0. This is * distinct from {@link Player#position}. Turn order can be altered during a * game, whereas table position cannot. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L127-L132
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.sortBy
sortBy(key: Sorter<P> | (Sorter<P>)[], direction?: "asc" | "desc") { const rank = (p: P, k: Sorter<P>) => typeof k === 'function' ? k(p) : p[k] const [up, down] = direction === 'desc' ? [-1, 1] : [1, -1]; return this.sort((a, b) => { const keys = key instanceof Array ? key : [key]; for (const k ...
/** * Sorts the players by some means, changing the turn order. * @param key - A key of function for sorting, or a list of such. See {@link * Sorter} * @param direction - `"asc"` to cause players to be sorted from lowest to * highest, `"desc"` for highest to lower */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L141-L154
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
PlayerCollection.sortedBy
sortedBy(key: Sorter<P> | (Sorter<P>)[], direction: "asc" | "desc" = "asc") { return (this.slice(0, this.length) as this).sortBy(key, direction); }
/** * Returns a copy of this collection sorted by some {@link Sorter}. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/collection.ts#L159-L161
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Player.hide
static hide<P extends BasePlayer>(this: {new(): P; hiddenAttributes: string[]}, ...attrs: (keyof P)[]): void { this.hiddenAttributes = attrs as string[]; }
/** * Provide list of attributes that are hidden from other players */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/player.ts#L59-L61
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Player.setCurrent
setCurrent(this: P) { return this._players.setCurrent(this); }
/** * Set this player as the current player */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/player.ts#L72-L74
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Player.others
others(): P[] { return Array.from(this._players).filter(p => p as Player !== this); }
/** * Returns an array of all other players. */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/player.ts#L79-L81
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
Player.other
other(): P { if (this._players.length !== 2) throw Error('Can only use `other` for 2 player games'); return this._players.find(p => p as Player !== this)!; }
/** * Returns the other player. Only allowed in 2 player games */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/player/player.ts#L86-L89
d701cb628e876cbe59171e837862ee09c925d6c9
boardzilla-core
github_2023
boardzilla
typescript
getArea
function getArea(absolutePosition: Box, margin?: number | { top: number, bottom: number, left: number, right: number }, area?: Box): Box { if (area) return area; if (!margin) return { left: 0, top: 0, width: 100, height: 100 }; // margins are absolute, so translate const transform: Vector = { x: absolutePo...
/** * calculate working area * @internal */
https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/ui/render.ts#L920-L942
d701cb628e876cbe59171e837862ee09c925d6c9
ev0-astro-theme
github_2023
gndx
typescript
e
const e = (str: string) => encodeURIComponent(encodeURIComponent(str));
// double escape for commas and slashes
https://github.com/gndx/ev0-astro-theme/blob/77777faab2e966a42411a5b8bd0f7e9b652d4e27/src/utils/createOgImage.ts#L23-L23
77777faab2e966a42411a5b8bd0f7e9b652d4e27
moonlight
github_2023
moonlight-mod
typescript
downloadStable
async function downloadStable(): Promise<[ArrayBuffer, string]> { const json = await getStableRelease(); const asset = json.assets.find((a) => a.name === artifactName); if (!asset) throw new Error("Artifact not found"); logger.debug(`Downloading ${asset.browser_download_url}`); ...
// Note: this won't do anything on browser, we should probably disable it
https://github.com/moonlight-mod/moonlight/blob/12cd3c869f2a9478b65033033d64bd82790396fd/packages/core-extensions/src/moonbase/native.ts#L66-L80
12cd3c869f2a9478b65033033d64bd82790396fd
moonlight
github_2023
moonlight-mod
typescript
MoonbaseSettingsStore.isModified
private isModified() { const orig = JSON.stringify(this.savedConfig); const curr = JSON.stringify(this.config); return orig !== curr; }
// Jank
https://github.com/moonlight-mod/moonlight/blob/12cd3c869f2a9478b65033033d64bd82790396fd/packages/core-extensions/src/moonbase/webpackModules/stores.ts#L159-L163
12cd3c869f2a9478b65033033d64bd82790396fd
moonlight
github_2023
moonlight-mod
typescript
MoonbaseSettingsStore.showNotice
showNotice() { return this.modified; }
// Required for the settings store contract
https://github.com/moonlight-mod/moonlight/blob/12cd3c869f2a9478b65033033d64bd82790396fd/packages/core-extensions/src/moonbase/webpackModules/stores.ts#L170-L172
12cd3c869f2a9478b65033033d64bd82790396fd
moonlight
github_2023
moonlight-mod
typescript
MoonbaseSettingsStore.clone
private clone<T>(obj: T): T { return structuredClone(obj); }
// This sucks.
https://github.com/moonlight-mod/moonlight/blob/12cd3c869f2a9478b65033033d64bd82790396fd/packages/core-extensions/src/moonbase/webpackModules/stores.ts#L535-L537
12cd3c869f2a9478b65033033d64bd82790396fd
moonlight
github_2023
moonlight-mod
typescript
call
const call = (event: string, ...args: any[]) => realEmit.call(this, event, ...args);
// Arrow functions don't bind `this` :D
https://github.com/moonlight-mod/moonlight/blob/12cd3c869f2a9478b65033033d64bd82790396fd/packages/core-extensions/src/nativeFixes/host.ts#L141-L141
12cd3c869f2a9478b65033033d64bd82790396fd
moonlight
github_2023
moonlight-mod
typescript
linkVenmic
function linkVenmic() { if (patchbay == null) return false; try { const pid = app .getAppMetrics() .find((proc) => proc.name === "Audio Service") ?.pid?.toString() ?? ""; logger.info("Audio Service PID:", pid); patchbay.unlink(); return patchbay.link({ exclude:...
// TODO: figure out how to map source to window with venmic
https://github.com/moonlight-mod/moonlight/blob/12cd3c869f2a9478b65033033d64bd82790396fd/packages/core-extensions/src/rocketship/host/venmic.ts#L24-L47
12cd3c869f2a9478b65033033d64bd82790396fd