diff --git a/src/lib/calculateScore.ts b/src/lib/calculateScore.ts index 6546e58..895816d 100644 --- a/src/lib/calculateScore.ts +++ b/src/lib/calculateScore.ts @@ -1,4 +1,3 @@ -import { log } from '#utilities/log.ts' import { notNullish } from '#utilities/notNullish.ts' import { RANK_TO_CHIP_MAP, PLAYED_CARD_RETRIGGER_JOKER_NAMES, HELD_CARD_RETRIGGER_JOKER_NAMES, LUCKS } from './data.ts' import { balanceMultWithLuck } from './balanceMultWithLuck.ts' @@ -64,7 +63,7 @@ function getScore (state: State, playedHand: HandName, scoringCards: Card[], luc // The Flint halves the base chips and multiplier. const baseFactor = (state.blind.name === 'The Flint' && state.blind.active ? 0.5 : 1) // The base score seems to be rounded here. - const score = createScoreProxy([]) + const score: ScoreValue[] = [] score.push({ chips: ['+', Math.round(baseScore.chips * baseFactor)], phase: 'base', @@ -266,25 +265,6 @@ function getScore (state: State, playedHand: HandName, scoringCards: Card[], luc return score } -/** - * Create a proxy for the array holding the individual score values that also prints logs for each score-affecting change. - */ -function createScoreProxy (value: T) { - return new Proxy(value, { - get (target, prop) { - if (prop === 'push') { - return (...scoreValues: Parameters) => { - for (const scoreValue of scoreValues) { - log(scoreValue) - } - return target.push(...scoreValues) - } - } - return Reflect.get(target, prop) - }, - }) -} - function getPlayedCardTriggers ({ state, card, index }: { state: State, card: Card, index: number }): string[] { const triggers = ['Regular'] diff --git a/src/lib/doBigMath.ts b/src/lib/doBigMath.ts index 2c5b713..41a8873 100644 --- a/src/lib/doBigMath.ts +++ b/src/lib/doBigMath.ts @@ -1,5 +1,6 @@ import { add, BigNumber, bignumber, divide, floor, multiply, pow } from 'mathjs' +import { log } from '#utilities/log.ts' import type { DeckName, ScoreValue } from './types.ts' export function doBigMath (initialScore: ScoreValue[], deck: DeckName) { @@ -16,6 +17,11 @@ export function doBigMath (initialScore: ScoreValue[], deck: DeckName) { const operation = operator === '+' ? add : multiply multiplier = operation(multiplier, bignumber(value)) } + + log(scoreValue, { + chips: chips.toString(), + multiplier: multiplier.toString(), + }) } let actualScore: BigNumber diff --git a/src/utilities/log.ts b/src/utilities/log.ts index c3b05b1..a28b0a2 100644 --- a/src/utilities/log.ts +++ b/src/utilities/log.ts @@ -2,7 +2,10 @@ import type { ScoreValue } from '#lib/types.ts' export const log = import.meta.env?.VITE_DEBUG === 'true' ? logFn : () => undefined -function logFn ({ chips, multiplier, phase, card, joker, type, trigger }: ScoreValue): void { +function logFn ( + { chips, multiplier, phase, card, joker, type, trigger }: ScoreValue, + currentScoreValue: { chips: string, multiplier: string }, +): void { let valueStr = '' if (chips) { const [operator, value] = chips @@ -40,5 +43,7 @@ function logFn ({ chips, multiplier, phase, card, joker, type, trigger }: ScoreV str += ` (trigger: ${trigger})` } + str += ` → ${currentScoreValue.chips}×${currentScoreValue.multiplier}` + console.log(str) }