Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: disable debug logging during preview #208

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Try to simplify
  • Loading branch information
Greenheart committed Sep 9, 2023
commit 066f447786f8f6df1a4ddee6e97a345c7a182d02
24 changes: 13 additions & 11 deletions web/src/game/BasicGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type GameOptions<P> = {
* Change how actions are applied.
*/
export type ApplyActionOptions = {
/**
* Enabled when calculating action indicators.
*/
isPreview?: boolean
}

Expand Down Expand Up @@ -57,15 +60,21 @@ export class BasicGame<P> implements Game<P> {
applyAction(
state: GameState<P>,
action: StateModifier<P>,
options: ApplyActionOptions = {},
{ isPreview }: ApplyActionOptions = {},
): GameState<P> {
const nextState = this._applyModifiers(
{
...state,
card: undefined as unknown as Card<P>,
},
[action, ...this._tickModifiers],
options,
[
action,
...(Boolean(isPreview)
? this._tickModifiers.filter(
(modifier) => modifier.disabledDuringPreview,
)
: this._tickModifiers),
],
)
return nextState.card
? nextState
Expand All @@ -80,15 +89,8 @@ export class BasicGame<P> implements Game<P> {
private _applyModifiers(
state: GameState<P>,
modifiers: StateModifier<P>[],
{ isPreview }: ApplyActionOptions = {},
): GameState<P> {
return modifiers.reduce(
(acc, modifier) =>
Boolean(isPreview) && modifier.disabledDuringPreview
? state
: modifier(acc),
state,
)
return modifiers.reduce((acc, modifier) => modifier(acc), state)
}

private _getAvailableCards(state: GameState<P>): Card<P>[] {
Expand Down