From 69f95bf701b4b7d867b1e6ee11b359d755f78c70 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Sat, 3 May 2025 08:50:33 -0400 Subject: [PATCH] organize artigen's types --- src/artigen/artigen.d.ts | 23 ++++ src/artigen/cmdTokenizer.ts | 4 +- src/artigen/dice/dice.d.ts | 79 ++++++++++++- src/artigen/dice/executeRoll.ts | 4 +- src/artigen/dice/generateFormattedRoll.ts | 4 +- .../managers/handler/workerComplete.ts | 4 +- .../managers/handler/workerTerminate.ts | 2 +- src/artigen/math/math.d.ts | 10 ++ src/artigen/math/mathSolver.ts | 2 +- src/artigen/math/mathTokenizer.ts | 6 +- src/artigen/parser.ts | 4 +- src/artigen/solver.d.ts | 111 ------------------ src/artigen/utils/counter.ts | 2 +- src/artigen/utils/generateRoll.ts | 4 +- src/artigen/utils/parenBalance.ts | 2 +- src/artigen/utils/sortFuncs.ts | 4 +- src/commandUtils.ts | 4 +- 17 files changed, 132 insertions(+), 137 deletions(-) create mode 100644 src/artigen/artigen.d.ts create mode 100644 src/artigen/math/math.d.ts delete mode 100644 src/artigen/solver.d.ts diff --git a/src/artigen/artigen.d.ts b/src/artigen/artigen.d.ts new file mode 100644 index 0000000..4f3792a --- /dev/null +++ b/src/artigen/artigen.d.ts @@ -0,0 +1,23 @@ +import { CountDetails } from 'artigen/dice/dice.d.ts'; + +// ReturnData is the temporary internal type used before getting turned into SolvedRoll +export interface ReturnData { + rollTotal: number; + rollPreFormat: string; + rollPostFormat: string; + rollDetails: string; + containsCrit: boolean; + containsFail: boolean; + initConfig: string; +} + +// SolvedRoll is the complete solved and formatted roll, or the error said roll created +export interface SolvedRoll { + error: boolean; + errorMsg: string; + errorCode: string; + line1: string; + line2: string; + line3: string; + counts: CountDetails; +} diff --git a/src/artigen/cmdTokenizer.ts b/src/artigen/cmdTokenizer.ts index ed54326..1872fb3 100644 --- a/src/artigen/cmdTokenizer.ts +++ b/src/artigen/cmdTokenizer.ts @@ -2,9 +2,9 @@ import { log, LogTypes as LT } from '@Log4Deno'; import config from '~config'; -import { CountDetails, ReturnData } from 'artigen/solver.d.ts'; +import { ReturnData } from 'artigen/artigen.d.ts'; -import { RollModifiers } from 'artigen/dice/dice.d.ts'; +import { CountDetails, RollModifiers } from 'artigen/dice/dice.d.ts'; import { tokenizeMath } from 'artigen/math/mathTokenizer.ts'; diff --git a/src/artigen/dice/dice.d.ts b/src/artigen/dice/dice.d.ts index bfb2b9d..40e3fae 100644 --- a/src/artigen/dice/dice.d.ts +++ b/src/artigen/dice/dice.d.ts @@ -1,5 +1,38 @@ +import { SolvedStep } from 'artigen/math/math.d.ts'; + +// Available Roll Types +export type RollType = '' | 'roll20' | 'fate' | 'cwod' | 'ova'; + +// RollSet is used to preserve all information about a calculated roll +export interface RollSet { + type: RollType; + origIdx: number; + roll: number; + dropped: boolean; + rerolled: boolean; + exploding: boolean; + critHit: boolean; + critFail: boolean; +} + +// CountDetails is the object holding the count data for creating the Count Embed +export interface CountDetails { + total: number; + successful: number; + failed: number; + rerolled: number; + dropped: number; + exploded: number; +} + +// RollFormat is the return structure for the rollFormatter +export interface RollFormat { + solvedStep: SolvedStep; + countDetails: CountDetails; +} + // RollModifiers is the structure to keep track of the decorators applied to a roll command -export type RollModifiers = { +export interface RollModifiers { noDetails: boolean; superNoDetails: boolean; spoiler: string; @@ -13,4 +46,46 @@ export type RollModifiers = { commaTotals: boolean; valid: boolean; apiWarn: string; -}; +} + +// Basic conf interfaces +interface CountConf { + on: boolean; + count: number; +} +interface RangeConf { + on: boolean; + range: number[]; +} + +// D% configuration +export interface DPercentConf { + on: boolean; + sizeAdjustment: number; + critVal: number; +} + +// RollConf is used by the roll20 setup +export interface RollConf { + dieCount: number; + dieSize: number; + dPercent: DPercentConf; + drop: CountConf; + keep: CountConf; + dropHigh: CountConf; + keepLow: CountConf; + reroll: { + on: boolean; + once: boolean; + nums: number[]; + }; + critScore: RangeConf; + critFail: RangeConf; + exploding: { + on: boolean; + once: boolean; + compounding: boolean; + penetrating: boolean; + nums: number[]; + }; +} diff --git a/src/artigen/dice/executeRoll.ts b/src/artigen/dice/executeRoll.ts index dc7cac2..3ca2a4d 100644 --- a/src/artigen/dice/executeRoll.ts +++ b/src/artigen/dice/executeRoll.ts @@ -2,9 +2,7 @@ import { log, LogTypes as LT } from '@Log4Deno'; import config from '~config'; -import { RollConf, RollSet, RollType } from 'artigen/solver.d.ts'; - -import { RollModifiers } from 'artigen/dice/dice.d.ts'; +import { RollConf, RollModifiers, RollSet, RollType } from 'artigen/dice/dice.d.ts'; import { genFateRoll, genRoll } from 'artigen/utils/generateRoll.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts'; diff --git a/src/artigen/dice/generateFormattedRoll.ts b/src/artigen/dice/generateFormattedRoll.ts index 1b2073f..eb6b52d 100644 --- a/src/artigen/dice/generateFormattedRoll.ts +++ b/src/artigen/dice/generateFormattedRoll.ts @@ -1,8 +1,6 @@ import { log, LogTypes as LT } from '@Log4Deno'; -import { RollFormat } from 'artigen/solver.d.ts'; - -import { RollModifiers } from 'artigen/dice/dice.d.ts'; +import { RollFormat, RollModifiers } from 'artigen/dice/dice.d.ts'; import { executeRoll } from 'artigen/dice/executeRoll.ts'; import { rollCounter } from 'artigen/utils/counter.ts'; diff --git a/src/artigen/managers/handler/workerComplete.ts b/src/artigen/managers/handler/workerComplete.ts index cf39647..e882b59 100644 --- a/src/artigen/managers/handler/workerComplete.ts +++ b/src/artigen/managers/handler/workerComplete.ts @@ -4,14 +4,14 @@ import { log, LogTypes as LT } from '@Log4Deno'; import config from '~config'; import { DEVMODE } from '~flags'; -import { SolvedRoll } from 'artigen/solver.d.ts'; +import { SolvedRoll } from 'artigen/artigen.d.ts'; import { removeWorker } from 'artigen/managers/countManager.ts'; import { QueuedRoll } from 'artigen/managers/manager.d.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts'; -import dbClient from 'db/client.ts'; +import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; import stdResp from 'endpoints/stdResponses.ts'; diff --git a/src/artigen/managers/handler/workerTerminate.ts b/src/artigen/managers/handler/workerTerminate.ts index 8f506b8..05540f3 100644 --- a/src/artigen/managers/handler/workerTerminate.ts +++ b/src/artigen/managers/handler/workerTerminate.ts @@ -1,4 +1,4 @@ -import { SolvedRoll } from 'artigen/solver.d.ts'; +import { SolvedRoll } from 'artigen/artigen.d.ts'; import { RollModifiers } from 'artigen/dice/dice.d.ts'; diff --git a/src/artigen/math/math.d.ts b/src/artigen/math/math.d.ts new file mode 100644 index 0000000..a8e948a --- /dev/null +++ b/src/artigen/math/math.d.ts @@ -0,0 +1,10 @@ +// SolvedStep is used to preserve information while math is being performed on the roll +export interface SolvedStep { + total: number; + details: string; + containsCrit: boolean; + containsFail: boolean; +} + +// Joined type for mathConf as its a "WIP" variable and moved everything from string->number->SolvedStep +export type MathConf = string | number | SolvedStep; diff --git a/src/artigen/math/mathSolver.ts b/src/artigen/math/mathSolver.ts index 3654ad2..827886c 100644 --- a/src/artigen/math/mathSolver.ts +++ b/src/artigen/math/mathSolver.ts @@ -5,7 +5,7 @@ */ import { log, LogTypes as LT } from '@Log4Deno'; -import { MathConf, SolvedStep } from 'artigen/solver.d.ts'; +import { MathConf, SolvedStep } from 'artigen/math/math.d.ts'; import { legalMath, legalMathOperators } from 'artigen/utils/legalMath.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts'; diff --git a/src/artigen/math/mathTokenizer.ts b/src/artigen/math/mathTokenizer.ts index f1875df..fce471b 100644 --- a/src/artigen/math/mathTokenizer.ts +++ b/src/artigen/math/mathTokenizer.ts @@ -1,8 +1,10 @@ import { log, LogTypes as LT } from '@Log4Deno'; -import { CountDetails, MathConf, ReturnData, SolvedStep } from 'artigen/solver.d.ts'; +import { ReturnData } from 'artigen/artigen.d.ts'; -import { RollModifiers } from 'artigen/dice/dice.d.ts'; +import { MathConf, SolvedStep } from 'artigen/math/math.d.ts'; + +import { CountDetails, RollModifiers } from 'artigen/dice/dice.d.ts'; import { generateFormattedRoll } from 'artigen/dice/generateFormattedRoll.ts'; import { mathSolver } from 'artigen/math/mathSolver.ts'; diff --git a/src/artigen/parser.ts b/src/artigen/parser.ts index 5458e8d..9989e6f 100644 --- a/src/artigen/parser.ts +++ b/src/artigen/parser.ts @@ -1,13 +1,13 @@ import { log, LogTypes as LT } from '@Log4Deno'; +import { SolvedRoll } from 'artigen/artigen.d.ts'; import { tokenizeCmd } from 'artigen/cmdTokenizer.ts'; -import { SolvedRoll } from 'artigen/solver.d.ts'; import { RollModifiers } from 'artigen/dice/dice.d.ts'; import { cmdSplitRegex, escapeCharacters } from 'artigen/utils/escape.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts'; -import { assertPrePostBalance } from 'src/artigen/utils/parenBalance.ts'; +import { assertPrePostBalance } from 'artigen/utils/parenBalance.ts'; import { compareTotalRolls, compareTotalRollsReverse } from 'artigen/utils/sortFuncs.ts'; import { translateError } from 'artigen/utils/translateError.ts'; diff --git a/src/artigen/solver.d.ts b/src/artigen/solver.d.ts deleted file mode 100644 index 1191ba6..0000000 --- a/src/artigen/solver.d.ts +++ /dev/null @@ -1,111 +0,0 @@ -// Available Roll Types -export type RollType = '' | 'roll20' | 'fate' | 'cwod' | 'ova'; - -export type MathConf = string | number | SolvedStep; - -// RollSet is used to preserve all information about a calculated roll -export type RollSet = { - type: RollType; - origIdx: number; - roll: number; - dropped: boolean; - rerolled: boolean; - exploding: boolean; - critHit: boolean; - critFail: boolean; -}; - -// SolvedStep is used to preserve information while math is being performed on the roll -export type SolvedStep = { - total: number; - details: string; - containsCrit: boolean; - containsFail: boolean; -}; - -// ReturnData is the temporary internal type used before getting turned into SolvedRoll -export type ReturnData = { - rollTotal: number; - rollPreFormat: string; - rollPostFormat: string; - rollDetails: string; - containsCrit: boolean; - containsFail: boolean; - initConfig: string; -}; - -// CountDetails is the object holding the count data for creating the Count Embed -export type CountDetails = { - total: number; - successful: number; - failed: number; - rerolled: number; - dropped: number; - exploded: number; -}; - -// RollFormat is the return structure for the rollFormatter -export type RollFormat = { - solvedStep: SolvedStep; - countDetails: CountDetails; -}; - -// SolvedRoll is the complete solved and formatted roll, or the error said roll created -export type SolvedRoll = { - error: boolean; - errorMsg: string; - errorCode: string; - line1: string; - line2: string; - line3: string; - counts: CountDetails; -}; - -export type DPercentConf = { - on: boolean; - sizeAdjustment: number; - critVal: number; -}; - -// RollConf is used by the roll20 setup -export type RollConf = { - dieCount: number; - dieSize: number; - dPercent: DPercentConf; - drop: { - on: boolean; - count: number; - }; - keep: { - on: boolean; - count: number; - }; - dropHigh: { - on: boolean; - count: number; - }; - keepLow: { - on: boolean; - count: number; - }; - reroll: { - on: boolean; - once: boolean; - nums: number[]; - }; - critScore: { - on: boolean; - range: number[]; - }; - critFail: { - on: boolean; - range: number[]; - }; - exploding: { - on: boolean; - once: boolean; - compounding: boolean; - penetrating: boolean; - nums: number[]; - }; -}; diff --git a/src/artigen/utils/counter.ts b/src/artigen/utils/counter.ts index 3b8e0b8..dae7689 100644 --- a/src/artigen/utils/counter.ts +++ b/src/artigen/utils/counter.ts @@ -1,4 +1,4 @@ -import { CountDetails, RollSet } from 'artigen/solver.d.ts'; +import { CountDetails, RollSet } from 'artigen/dice/dice.d.ts'; export const rollCounter = (rollSet: RollSet[]): CountDetails => { const countDetails = { diff --git a/src/artigen/utils/generateRoll.ts b/src/artigen/utils/generateRoll.ts index 20aa6ee..605db0d 100644 --- a/src/artigen/utils/generateRoll.ts +++ b/src/artigen/utils/generateRoll.ts @@ -1,6 +1,4 @@ -import { RollModifiers } from 'artigen/dice/dice.d.ts'; - -import { DPercentConf } from 'artigen/solver.d.ts'; +import { DPercentConf, RollModifiers } from 'artigen/dice/dice.d.ts'; // genRoll(size) returns number // genRoll rolls a die of size size and returns the result diff --git a/src/artigen/utils/parenBalance.ts b/src/artigen/utils/parenBalance.ts index 0b68b85..b00bf9e 100644 --- a/src/artigen/utils/parenBalance.ts +++ b/src/artigen/utils/parenBalance.ts @@ -2,7 +2,7 @@ import { log, LogTypes as LT } from '@Log4Deno'; import config from '~config'; -import { MathConf } from 'artigen/solver.d.ts'; +import { MathConf } from 'artigen/math/math.d.ts'; import { closeInternal, openInternal } from 'artigen/utils/escape.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts'; diff --git a/src/artigen/utils/sortFuncs.ts b/src/artigen/utils/sortFuncs.ts index ec18f32..e552ed6 100644 --- a/src/artigen/utils/sortFuncs.ts +++ b/src/artigen/utils/sortFuncs.ts @@ -1,4 +1,6 @@ -import { ReturnData, RollSet } from 'src/artigen/solver.d.ts'; +import { ReturnData } from 'artigen/artigen.d.ts'; + +import { RollSet } from 'artigen/dice/dice.d.ts'; // compareRolls(a, b) returns -1|0|1 // compareRolls is used to order an array of RollSets by RollSet.roll diff --git a/src/commandUtils.ts b/src/commandUtils.ts index b4c10f5..d92ffb7 100644 --- a/src/commandUtils.ts +++ b/src/commandUtils.ts @@ -2,9 +2,9 @@ import { log, LogTypes as LT } from '@Log4Deno'; import config from '~config'; -import { RollModifiers } from 'artigen/dice/dice.d.ts'; +import { SolvedRoll } from 'artigen/artigen.d.ts'; -import { CountDetails, SolvedRoll } from 'artigen/solver.d.ts'; +import { CountDetails, RollModifiers } from 'artigen/dice/dice.d.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts';