Add loopCountCheck to more loops

This commit is contained in:
Ean Milligan 2025-05-06 03:00:57 -04:00
parent 5e1a509c96
commit 7a0b49dc0c
3 changed files with 21 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import { log, LogTypes as LT } from '@Log4Deno';
import { SolvedRoll } from 'artigen/artigen.d.ts'; import { SolvedRoll } from 'artigen/artigen.d.ts';
import { tokenizeCmd } from 'artigen/cmdTokenizer.ts'; import { tokenizeCmd } from 'artigen/cmdTokenizer.ts';
import { loopCountCheck } from 'artigen/managers/loopManager.ts';
import { QueuedRoll } from 'artigen/managers/manager.d.ts'; import { QueuedRoll } from 'artigen/managers/manager.d.ts';
import { cmdSplitRegex, escapeCharacters } from 'artigen/utils/escape.ts'; import { cmdSplitRegex, escapeCharacters } from 'artigen/utils/escape.ts';
@ -77,6 +78,8 @@ export const runCmd = (rollRequest: QueuedRoll): SolvedRoll => {
// Fill out all of the details and results now // Fill out all of the details and results now
tempReturnData.forEach((e) => { tempReturnData.forEach((e) => {
loopCountCheck();
loggingEnabled && log(LT.LOG, `Parsing roll ${rollRequest.rollCmd} | Making return text ${JSON.stringify(e)}`); loggingEnabled && log(LT.LOG, `Parsing roll ${rollRequest.rollCmd} | Making return text ${JSON.stringify(e)}`);
let preFormat = ''; let preFormat = '';
let postFormat = ''; let postFormat = '';

View File

@ -3,6 +3,8 @@ import { log, LogTypes as LT } from '@Log4Deno';
import { RollFormat, RollModifiers } from 'artigen/dice/dice.d.ts'; import { RollFormat, RollModifiers } from 'artigen/dice/dice.d.ts';
import { executeRoll } from 'artigen/dice/executeRoll.ts'; import { executeRoll } from 'artigen/dice/executeRoll.ts';
import { loopCountCheck } from 'artigen/managers/loopManager.ts';
import { rollCounter } from 'artigen/utils/counter.ts'; import { rollCounter } from 'artigen/utils/counter.ts';
import { loggingEnabled } from 'artigen/utils/logFlag.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts';
@ -19,6 +21,8 @@ export const generateFormattedRoll = (rollConf: string, modifiers: RollModifiers
// Loop thru all parts of the roll to document everything that was done to create the total roll // Loop thru all parts of the roll to document everything that was done to create the total roll
tempRollSet.forEach((e) => { tempRollSet.forEach((e) => {
loopCountCheck();
loggingEnabled && log(LT.LOG, `Formatting roll ${rollConf} | ${JSON.stringify(e)}`); loggingEnabled && log(LT.LOG, `Formatting roll ${rollConf} | ${JSON.stringify(e)}`);
let preFormat = ''; let preFormat = '';
let postFormat = ''; let postFormat = '';

View File

@ -1,5 +1,7 @@
import { CountDetails, RollSet } from 'artigen/dice/dice.d.ts'; import { CountDetails, RollSet } from 'artigen/dice/dice.d.ts';
import { loopCountCheck } from 'artigen/managers/loopManager.ts';
export const rollCounter = (rollSet: RollSet[]): CountDetails => { export const rollCounter = (rollSet: RollSet[]): CountDetails => {
const countDetails = { const countDetails = {
total: 0, total: 0,
@ -11,6 +13,7 @@ export const rollCounter = (rollSet: RollSet[]): CountDetails => {
}; };
rollSet.forEach((roll) => { rollSet.forEach((roll) => {
loopCountCheck();
countDetails.total++; countDetails.total++;
if (roll.critHit) countDetails.successful++; if (roll.critHit) countDetails.successful++;
if (roll.critFail) countDetails.failed++; if (roll.critFail) countDetails.failed++;
@ -24,14 +27,17 @@ export const rollCounter = (rollSet: RollSet[]): CountDetails => {
export const reduceCountDetails = (counts: CountDetails[]): CountDetails => { export const reduceCountDetails = (counts: CountDetails[]): CountDetails => {
return counts.reduce( return counts.reduce(
(acc, cnt) => ({ (acc, cnt) => {
total: acc.total + cnt.total, loopCountCheck();
successful: acc.successful + cnt.successful, return {
failed: acc.failed + cnt.failed, total: acc.total + cnt.total,
rerolled: acc.rerolled + cnt.rerolled, successful: acc.successful + cnt.successful,
dropped: acc.dropped + cnt.dropped, failed: acc.failed + cnt.failed,
exploded: acc.exploded + cnt.exploded, rerolled: acc.rerolled + cnt.rerolled,
}), dropped: acc.dropped + cnt.dropped,
exploded: acc.exploded + cnt.exploded,
};
},
{ {
total: 0, total: 0,
successful: 0, successful: 0,