@platonic-dice/core 2.2.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/dist/analyseModTest.js +12 -10
- package/dist/analyseTest.js +43 -11
- package/dist/entities/DiceTestConditions.js +174 -0
- package/dist/entities/ModifiedTestConditions.js +30 -41
- package/dist/entities/RollModifier.js +15 -1
- package/dist/entities/TestConditions.js +26 -182
- package/dist/entities/TestConditionsArray.js +87 -0
- package/dist/entities/index.js +250 -39
- package/dist/index.js +42 -25
- package/dist/rollDiceMod.js +30 -17
- package/dist/rollDiceTest.js +68 -0
- package/dist/rollMod.js +3 -4
- package/dist/rollModTest.js +40 -13
- package/dist/rollTest.js +50 -15
- package/dist/utils/determineOutcome.js +35 -7
- package/dist/utils/getArrayEvaluator.js +48 -0
- package/dist/utils/getEvaluator.js +84 -0
- package/dist/utils/index.js +244 -16
- package/dist/utils/outcomeMapper.js +62 -15
- package/dist/utils/testRegistry.js +91 -0
- package/dist/utils/testValidators.js +190 -0
- package/package.json +12 -15
- package/dist/analyseModTest.d.ts +0 -126
- package/dist/analyseModTest.d.ts.map +0 -1
- package/dist/analyseTest.d.ts +0 -101
- package/dist/analyseTest.d.ts.map +0 -1
- package/dist/entities/DieType.d.ts +0 -35
- package/dist/entities/DieType.d.ts.map +0 -1
- package/dist/entities/ModifiedTestConditions.d.ts +0 -89
- package/dist/entities/ModifiedTestConditions.d.ts.map +0 -1
- package/dist/entities/Outcome.d.ts +0 -26
- package/dist/entities/Outcome.d.ts.map +0 -1
- package/dist/entities/RollModifier.d.ts +0 -115
- package/dist/entities/RollModifier.d.ts.map +0 -1
- package/dist/entities/RollType.d.ts +0 -24
- package/dist/entities/RollType.d.ts.map +0 -1
- package/dist/entities/TestConditions.d.ts +0 -97
- package/dist/entities/TestConditions.d.ts.map +0 -1
- package/dist/entities/TestType.d.ts +0 -28
- package/dist/entities/TestType.d.ts.map +0 -1
- package/dist/entities/index.d.ts +0 -19
- package/dist/entities/index.d.ts.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/roll.d.ts +0 -66
- package/dist/roll.d.ts.map +0 -1
- package/dist/rollDice.d.ts +0 -48
- package/dist/rollDice.d.ts.map +0 -1
- package/dist/rollDiceMod.d.ts +0 -54
- package/dist/rollDiceMod.d.ts.map +0 -1
- package/dist/rollMod.d.ts +0 -52
- package/dist/rollMod.d.ts.map +0 -1
- package/dist/rollModTest.d.ts +0 -72
- package/dist/rollModTest.d.ts.map +0 -1
- package/dist/rollTest.d.ts +0 -59
- package/dist/rollTest.d.ts.map +0 -1
- package/dist/utils/determineOutcome.d.ts +0 -45
- package/dist/utils/determineOutcome.d.ts.map +0 -1
- package/dist/utils/generateResult.d.ts +0 -30
- package/dist/utils/generateResult.d.ts.map +0 -1
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/outcomeMapper.d.ts +0 -29
- package/dist/utils/outcomeMapper.d.ts.map +0 -1
- package/dist-types.d.ts +0 -70
package/package.json
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platonic-dice/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"packageManager": "pnpm@8.15.9",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=24"
|
|
7
|
+
},
|
|
5
8
|
"description": "Core JavaScript logic for simulating TTRPG dice rolls.",
|
|
6
9
|
"main": "dist/index.js",
|
|
7
|
-
"types": "dist-types.d.ts",
|
|
8
10
|
"exports": {
|
|
9
11
|
".": {
|
|
10
12
|
"import": "./dist/index.js",
|
|
11
|
-
"require": "./dist/index.js"
|
|
12
|
-
"types": "./dist-types.d.ts"
|
|
13
|
+
"require": "./dist/index.js"
|
|
13
14
|
},
|
|
14
15
|
"./entities": {
|
|
15
16
|
"import": "./dist/entities/index.js",
|
|
16
|
-
"require": "./dist/entities/index.js"
|
|
17
|
-
"types": "./dist/entities/index.d.ts"
|
|
17
|
+
"require": "./dist/entities/index.js"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
"dist-types.d.ts"
|
|
21
|
+
"dist"
|
|
23
22
|
],
|
|
24
23
|
"keywords": [
|
|
25
24
|
"dice",
|
|
@@ -41,24 +40,22 @@
|
|
|
41
40
|
},
|
|
42
41
|
"homepage": "https://github.com/sjs2k20/platonic-dice.git#readme",
|
|
43
42
|
"scripts": {
|
|
44
|
-
"build": "rm -rf dist && mkdir -p dist && cp -R src/* dist/ &&
|
|
43
|
+
"build": "rm -rf dist && mkdir -p dist && cp -R src/* dist/ && find dist -name \"*.d.ts\" -delete",
|
|
45
44
|
"prepublishOnly": "pnpm run build",
|
|
46
45
|
"test": "jest",
|
|
47
|
-
"
|
|
48
|
-
"examples": "pnpm run examples:roll && pnpm run examples:rollDice && pnpm run examples:rollMod && pnpm run examples:rollDiceMod && pnpm run examples:rollTest && pnpm run examples:rollModTest",
|
|
46
|
+
"examples": "pnpm run examples:roll && pnpm run examples:rollDice && pnpm run examples:rollMod && pnpm run examples:rollDiceMod && pnpm run examples:rollTest && pnpm run examples:rollModTest && pnpm run examples:rollDiceTest",
|
|
49
47
|
"examples:roll": "node examples/roll-example.js",
|
|
50
48
|
"examples:rollDice": "node examples/rollDice-example.js",
|
|
51
49
|
"examples:rollMod": "node examples/rollMod-example.js",
|
|
52
50
|
"examples:rollDiceMod": "node examples/rollDiceMod-example.js",
|
|
53
51
|
"examples:rollTest": "node examples/rollTest-example.js",
|
|
54
52
|
"examples:rollModTest": "node examples/rollModTest-example.js",
|
|
53
|
+
"examples:rollDiceTest": "node examples/rollDiceTest-example.js",
|
|
55
54
|
"examples:rollModTest:advanced": "node examples/rollModTest-advanced-features-example.js",
|
|
56
55
|
"examples:analyseTest": "node examples/analyseTest-example.js",
|
|
57
56
|
"examples:analyseModTest": "node examples/analyseModTest-example.js",
|
|
58
|
-
"examples:entities": "node examples/entities/DieType-example.js && node examples/entities/RollType-example.js && node examples/entities/RollModifier-example.js && node examples/entities/TestType-example.js && node examples/entities/TestConditions-example.js && node examples/entities/ModifiedTestConditions-example.js && node examples/entities/Outcome-example.js",
|
|
57
|
+
"examples:entities": "node examples/entities/DieType-example.js && node examples/entities/RollType-example.js && node examples/entities/RollModifier-example.js && node examples/entities/TestType-example.js && node examples/entities/TestConditions-example.js && node examples/entities/TestConditionsArray-example.js && node examples/entities/DiceTestConditions-example.js && node examples/entities/ModifiedTestConditions-example.js && node examples/entities/Outcome-example.js",
|
|
59
58
|
"examples:all": "pnpm run examples && pnpm run examples:rollModTest:advanced && pnpm run examples:analyseTest && pnpm run examples:analyseModTest && pnpm run examples:entities"
|
|
60
59
|
},
|
|
61
|
-
"
|
|
62
|
-
"directory": "src/test-d"
|
|
63
|
-
}
|
|
60
|
+
"devDependencies": {}
|
|
64
61
|
}
|
package/dist/analyseModTest.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
export type DieTypeValue = import("./entities/DieType").DieTypeValue;
|
|
2
|
-
export type OutcomeValue = import("./entities/Outcome").OutcomeValue;
|
|
3
|
-
export type RollModifierFunction = import("./entities/RollModifier").RollModifierFunction;
|
|
4
|
-
export type RollModifierInstance = import("./entities/RollModifier").RollModifierInstance;
|
|
5
|
-
export type TestTypeValue = import("./entities/TestType").TestTypeValue;
|
|
6
|
-
export type TestConditionsInstance = import("./entities/TestConditions").TestConditionsInstance;
|
|
7
|
-
export type ModifiedTestAnalysis = {
|
|
8
|
-
/**
|
|
9
|
-
* - Total number of possible die rolls
|
|
10
|
-
*/
|
|
11
|
-
totalPossibilities: number;
|
|
12
|
-
/**
|
|
13
|
-
* - Count of each outcome type
|
|
14
|
-
*/
|
|
15
|
-
outcomeCounts: {
|
|
16
|
-
[x: string]: number;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* - Probability (0-1) of each outcome
|
|
20
|
-
*/
|
|
21
|
-
outcomeProbabilities: {
|
|
22
|
-
[x: string]: number;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* - Map of base roll to outcome
|
|
26
|
-
*/
|
|
27
|
-
outcomesByRoll: {
|
|
28
|
-
[x: number]: import("./entities").OutcomeValue;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* - Map of base roll to modified value
|
|
32
|
-
*/
|
|
33
|
-
modifiedValuesByRoll: {
|
|
34
|
-
[x: number]: number;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* - Array of all possible base roll values
|
|
38
|
-
*/
|
|
39
|
-
rolls: number[];
|
|
40
|
-
/**
|
|
41
|
-
* - Base rolls grouped by their outcome
|
|
42
|
-
*/
|
|
43
|
-
rollsByOutcome: any;
|
|
44
|
-
/**
|
|
45
|
-
* - Range of modified values achievable
|
|
46
|
-
*/
|
|
47
|
-
modifiedRange: {
|
|
48
|
-
min: number;
|
|
49
|
-
max: number;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
export type analyseModTestOptions = {
|
|
53
|
-
/**
|
|
54
|
-
* - If true, natural max/min rolls trigger
|
|
55
|
-
* critical outcomes. Defaults to true for Skill tests, false otherwise.
|
|
56
|
-
*/
|
|
57
|
-
useNaturalCrits?: boolean | undefined;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
|
|
61
|
-
* @typedef {import("./entities/Outcome").OutcomeValue} OutcomeValue
|
|
62
|
-
* @typedef {import("./entities/RollModifier").RollModifierFunction} RollModifierFunction
|
|
63
|
-
* @typedef {import("./entities/RollModifier").RollModifierInstance} RollModifierInstance
|
|
64
|
-
* @typedef {import("./entities/TestType").TestTypeValue} TestTypeValue
|
|
65
|
-
* @typedef {import("./entities/TestConditions").TestConditionsInstance} TestConditionsInstance
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* @typedef {Object} ModifiedTestAnalysis
|
|
69
|
-
* @property {number} totalPossibilities - Total number of possible die rolls
|
|
70
|
-
* @property {Object.<string, number>} outcomeCounts - Count of each outcome type
|
|
71
|
-
* @property {Object.<string, number>} outcomeProbabilities - Probability (0-1) of each outcome
|
|
72
|
-
* @property {Object.<number, OutcomeValue>} outcomesByRoll - Map of base roll to outcome
|
|
73
|
-
* @property {Object.<number, number>} modifiedValuesByRoll - Map of base roll to modified value
|
|
74
|
-
* @property {number[]} rolls - Array of all possible base roll values
|
|
75
|
-
* @property {Object.<OutcomeValue, number[]>} rollsByOutcome - Base rolls grouped by their outcome
|
|
76
|
-
* @property {{ min: number, max: number }} modifiedRange - Range of modified values achievable
|
|
77
|
-
*/
|
|
78
|
-
/**
|
|
79
|
-
* @typedef {Object} analyseModTestOptions
|
|
80
|
-
* @property {boolean} [useNaturalCrits] - If true, natural max/min rolls trigger
|
|
81
|
-
* critical outcomes. Defaults to true for Skill tests, false otherwise.
|
|
82
|
-
*/
|
|
83
|
-
/**
|
|
84
|
-
* analyses modified test conditions without performing an actual roll.
|
|
85
|
-
*
|
|
86
|
-
* @function analyseModTest
|
|
87
|
-
* @param {DieTypeValue} dieType - The type of die (e.g., `DieType.D20`).
|
|
88
|
-
* @param {RollModifierFunction|RollModifierInstance} modifier - The modifier to apply to the roll.
|
|
89
|
-
* @param {TestConditionsInstance|{ testType: TestTypeValue, [key: string]: any }} testConditions
|
|
90
|
-
* Can be:
|
|
91
|
-
* - A `TestConditions` instance
|
|
92
|
-
* - A plain object `{ testType, ...conditions }`
|
|
93
|
-
* @param {analyseModTestOptions} [options={}] - Optional configuration
|
|
94
|
-
* @returns {ModifiedTestAnalysis} Detailed analysis of the modified test outcomes
|
|
95
|
-
* @throws {TypeError} If `dieType`, `modifier`, or `testConditions` are invalid.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* // analyse a D20+5 skill check with DC 20
|
|
99
|
-
* const analysis = analyseModTest(
|
|
100
|
-
* DieType.D20,
|
|
101
|
-
* (n) => n + 5,
|
|
102
|
-
* {
|
|
103
|
-
* testType: TestType.Skill,
|
|
104
|
-
* target: 20,
|
|
105
|
-
* critical_success: 25,
|
|
106
|
-
* critical_failure: 6
|
|
107
|
-
* }
|
|
108
|
-
* );
|
|
109
|
-
*
|
|
110
|
-
* console.log(`Modified range: ${analysis.modifiedRange.min}-${analysis.modifiedRange.max}`);
|
|
111
|
-
* console.log(`Success rate: ${(analysis.outcomeProbabilities.success * 100).toFixed(1)}%`);
|
|
112
|
-
* console.log(`Need to roll: ${analysis.rollsByOutcome.success}`);
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* // See how modifier affects outcomes
|
|
116
|
-
* const noMod = analyseTest(DieType.D20, { testType: TestType.AtLeast, target: 15 });
|
|
117
|
-
* const withMod = analyseModTest(DieType.D20, n => n + 5, { testType: TestType.AtLeast, target: 15 });
|
|
118
|
-
*
|
|
119
|
-
* console.log(`Without modifier: ${(noMod.outcomeProbabilities.success * 100).toFixed(1)}%`);
|
|
120
|
-
* console.log(`With +5 modifier: ${(withMod.outcomeProbabilities.success * 100).toFixed(1)}%`);
|
|
121
|
-
*/
|
|
122
|
-
export function analyseModTest(dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance, testConditions: TestConditionsInstance | {
|
|
123
|
-
testType: TestTypeValue;
|
|
124
|
-
[key: string]: any;
|
|
125
|
-
}, options?: analyseModTestOptions): ModifiedTestAnalysis;
|
|
126
|
-
//# sourceMappingURL=analyseModTest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyseModTest.d.ts","sourceRoot":"","sources":["../src/analyseModTest.js"],"names":[],"mappings":"2BAyBa,OAAO,oBAAoB,EAAE,YAAY;2BACzC,OAAO,oBAAoB,EAAE,YAAY;mCACzC,OAAO,yBAAyB,EAAE,oBAAoB;mCACtD,OAAO,yBAAyB,EAAE,oBAAoB;4BACtD,OAAO,qBAAqB,EAAE,aAAa;qCAC3C,OAAO,2BAA2B,EAAE,sBAAsB;;;;;wBAKzD,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAKN,MAAM,EAAE;;;;;;;;mBAER;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;;;;;;;;;AAlB1C;;;;;;;GAOG;AAEH;;;;;;;;;;GAUG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wCAnCW,YAAY,YACZ,oBAAoB,GAAC,oBAAoB,kBACzC,sBAAsB,GAAC;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,YAItE,qBAAqB,GACnB,oBAAoB,CAkHhC"}
|
package/dist/analyseTest.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
export type DieTypeValue = import("./entities/DieType").DieTypeValue;
|
|
2
|
-
export type OutcomeValue = import("./entities/Outcome").OutcomeValue;
|
|
3
|
-
export type TestTypeValue = import("./entities/TestType").TestTypeValue;
|
|
4
|
-
export type TestConditionsInstance = import("./entities/TestConditions").TestConditionsInstance;
|
|
5
|
-
export type TestAnalysis = {
|
|
6
|
-
/**
|
|
7
|
-
* - Total number of possible die rolls
|
|
8
|
-
*/
|
|
9
|
-
totalPossibilities: number;
|
|
10
|
-
/**
|
|
11
|
-
* - Count of each outcome type
|
|
12
|
-
*/
|
|
13
|
-
outcomeCounts: {
|
|
14
|
-
[x: string]: number;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* - Probability (0-1) of each outcome
|
|
18
|
-
*/
|
|
19
|
-
outcomeProbabilities: {
|
|
20
|
-
[x: string]: number;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* - Map of roll value to outcome
|
|
24
|
-
*/
|
|
25
|
-
outcomesByRoll: {
|
|
26
|
-
[x: number]: import("./entities").OutcomeValue;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* - Array of all possible roll values
|
|
30
|
-
*/
|
|
31
|
-
rolls: number[];
|
|
32
|
-
/**
|
|
33
|
-
* - Rolls grouped by their outcome
|
|
34
|
-
*/
|
|
35
|
-
rollsByOutcome: any;
|
|
36
|
-
};
|
|
37
|
-
export type analyseTestOptions = {
|
|
38
|
-
/**
|
|
39
|
-
* - If true, natural max/min rolls trigger
|
|
40
|
-
* critical outcomes. Defaults to true for Skill tests, false otherwise.
|
|
41
|
-
*/
|
|
42
|
-
useNaturalCrits?: boolean | undefined;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
|
|
46
|
-
* @typedef {import("./entities/Outcome").OutcomeValue} OutcomeValue
|
|
47
|
-
* @typedef {import("./entities/TestType").TestTypeValue} TestTypeValue
|
|
48
|
-
* @typedef {import("./entities/TestConditions").TestConditionsInstance} TestConditionsInstance
|
|
49
|
-
*/
|
|
50
|
-
/**
|
|
51
|
-
* @typedef {Object} TestAnalysis
|
|
52
|
-
* @property {number} totalPossibilities - Total number of possible die rolls
|
|
53
|
-
* @property {Object.<string, number>} outcomeCounts - Count of each outcome type
|
|
54
|
-
* @property {Object.<string, number>} outcomeProbabilities - Probability (0-1) of each outcome
|
|
55
|
-
* @property {Object.<number, OutcomeValue>} outcomesByRoll - Map of roll value to outcome
|
|
56
|
-
* @property {number[]} rolls - Array of all possible roll values
|
|
57
|
-
* @property {Object.<OutcomeValue, number[]>} rollsByOutcome - Rolls grouped by their outcome
|
|
58
|
-
*/
|
|
59
|
-
/**
|
|
60
|
-
* @typedef {Object} analyseTestOptions
|
|
61
|
-
* @property {boolean} [useNaturalCrits] - If true, natural max/min rolls trigger
|
|
62
|
-
* critical outcomes. Defaults to true for Skill tests, false otherwise.
|
|
63
|
-
*/
|
|
64
|
-
/**
|
|
65
|
-
* analyses test conditions without performing an actual roll.
|
|
66
|
-
*
|
|
67
|
-
* @function analyseTest
|
|
68
|
-
* @param {DieTypeValue} dieType - The type of die (e.g., `DieType.D20`).
|
|
69
|
-
* @param {TestConditionsInstance|{ testType: TestTypeValue, [key: string]: any }} testConditions
|
|
70
|
-
* Can be:
|
|
71
|
-
* - A `TestConditions` instance.
|
|
72
|
-
* - A plain object `{ testType, ...conditions }`.
|
|
73
|
-
* @param {analyseTestOptions} [options={}] - Optional configuration for analysis
|
|
74
|
-
* @returns {TestAnalysis} Detailed analysis of the test outcomes
|
|
75
|
-
* @throws {TypeError} If `dieType` or `testConditions` are invalid.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* // analyse a D20 skill check with DC 15
|
|
79
|
-
* const analysis = analyseTest(DieType.D20, {
|
|
80
|
-
* testType: TestType.Skill,
|
|
81
|
-
* target: 15,
|
|
82
|
-
* critical_success: 20,
|
|
83
|
-
* critical_failure: 1
|
|
84
|
-
* });
|
|
85
|
-
*
|
|
86
|
-
* console.log(`Success rate: ${(analysis.outcomeProbabilities.success * 100).toFixed(1)}%`);
|
|
87
|
-
* console.log(`Critical success on: ${analysis.rollsByOutcome.critical_success}`);
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* // analyse without natural crits
|
|
91
|
-
* const analysis = analyseTest(
|
|
92
|
-
* DieType.D20,
|
|
93
|
-
* { testType: TestType.AtLeast, target: 15 },
|
|
94
|
-
* { useNaturalCrits: false }
|
|
95
|
-
* );
|
|
96
|
-
*/
|
|
97
|
-
export function analyseTest(dieType: DieTypeValue, testConditions: TestConditionsInstance | {
|
|
98
|
-
testType: TestTypeValue;
|
|
99
|
-
[key: string]: any;
|
|
100
|
-
}, options?: analyseTestOptions): TestAnalysis;
|
|
101
|
-
//# sourceMappingURL=analyseTest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyseTest.d.ts","sourceRoot":"","sources":["../src/analyseTest.js"],"names":[],"mappings":"2BA0Ba,OAAO,oBAAoB,EAAE,YAAY;2BACzC,OAAO,oBAAoB,EAAE,YAAY;4BACzC,OAAO,qBAAqB,EAAE,aAAa;qCAC3C,OAAO,2BAA2B,EAAE,sBAAsB;;;;;wBAKzD,MAAM;;;;;;;;;;;;;;;;;;;;;;WAIN,MAAM,EAAE;;;;;;;;;;;;;AAbtB;;;;;GAKG;AAEH;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qCA7BW,YAAY,kBACZ,sBAAsB,GAAC;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,YAItE,kBAAkB,GAChB,YAAY,CA8ExB"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export type DieTypeKey = keyof typeof DieType;
|
|
2
|
-
export type DieTypeValue = (typeof DieType)[keyof typeof DieType];
|
|
3
|
-
/**
|
|
4
|
-
* *
|
|
5
|
-
*/
|
|
6
|
-
export type DieType = string;
|
|
7
|
-
/**
|
|
8
|
-
* @module @platonic-dice/core/src/entities/DieType
|
|
9
|
-
* @description
|
|
10
|
-
* Enum for die types used in rolling functions.
|
|
11
|
-
*
|
|
12
|
-
* @readonly
|
|
13
|
-
* @enum {string}
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* import { DieType } from "@platonic-dice/core/src/entities";
|
|
17
|
-
* const result = roll(DieType.D20);
|
|
18
|
-
*/
|
|
19
|
-
export const DieType: Readonly<{
|
|
20
|
-
D4: "d4";
|
|
21
|
-
D6: "d6";
|
|
22
|
-
D8: "d8";
|
|
23
|
-
D10: "d10";
|
|
24
|
-
D12: "d12";
|
|
25
|
-
D20: "d20";
|
|
26
|
-
}>;
|
|
27
|
-
/**
|
|
28
|
-
* Checks whether a given value is a valid `DieType`.
|
|
29
|
-
*
|
|
30
|
-
* @function isValidDieType
|
|
31
|
-
* @param {DieTypeValue | null | undefined} dieType
|
|
32
|
-
* @returns {boolean}
|
|
33
|
-
*/
|
|
34
|
-
export function isValidDieType(dieType: DieTypeValue | null | undefined): boolean;
|
|
35
|
-
//# sourceMappingURL=DieType.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DieType.d.ts","sourceRoot":"","sources":["../../src/entities/DieType.js"],"names":[],"mappings":"yBAmCa,MAAM,OAAO,OAAO;2BACpB,CAAA,OAAO,OAAO,EAAC,MAAM,OAAO,OAAO,CAAC;;;;sBA7BvC,MAAM;AANhB;;;;;;;;;;;GAWG;AACH;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,wCAHW,YAAY,GAAG,IAAI,GAAG,SAAS,GAC7B,OAAO,CAKnB"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
export type TestTypeValue = import("./TestType").TestTypeValue;
|
|
2
|
-
export type DieTypeValue = import("./DieType").DieTypeValue;
|
|
3
|
-
export type RollModifierFunction = import("./RollModifier").RollModifierFunction;
|
|
4
|
-
export type RollModifierInstance = import("./RollModifier").RollModifierInstance;
|
|
5
|
-
export type BaseTestCondition = {
|
|
6
|
-
modifiedRange: {
|
|
7
|
-
min: number;
|
|
8
|
-
max: number;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export type TargetConditions = BaseTestCondition & {
|
|
12
|
-
target: number;
|
|
13
|
-
};
|
|
14
|
-
export type WithinConditions = BaseTestCondition & {
|
|
15
|
-
min: number;
|
|
16
|
-
max: number;
|
|
17
|
-
};
|
|
18
|
-
export type SpecificListConditions = BaseTestCondition & {
|
|
19
|
-
values: number[];
|
|
20
|
-
};
|
|
21
|
-
export type SkillConditions = BaseTestCondition & {
|
|
22
|
-
target: number;
|
|
23
|
-
critical_success?: number;
|
|
24
|
-
critical_failure?: number;
|
|
25
|
-
};
|
|
26
|
-
export type Conditions = TargetConditions | SkillConditions | WithinConditions | SpecificListConditions;
|
|
27
|
-
export type ModifiedTestConditionsInstance = InstanceType<typeof ModifiedTestConditions>;
|
|
28
|
-
/**
|
|
29
|
-
* Represents a set of validated test conditions for modified rolls.
|
|
30
|
-
*
|
|
31
|
-
* This class is similar to {@link TestConditions} but validates numeric
|
|
32
|
-
* targets against the achievable range after applying a modifier.
|
|
33
|
-
*/
|
|
34
|
-
export class ModifiedTestConditions {
|
|
35
|
-
/**
|
|
36
|
-
* @param {TestTypeValue} testType - The test type.
|
|
37
|
-
* @param {Conditions} conditions - The test conditions object.
|
|
38
|
-
* @param {DieTypeValue} dieType - The base die type.
|
|
39
|
-
* @param {RollModifierFunction | RollModifierInstance} modifier - The modifier to apply.
|
|
40
|
-
* @throws {TypeError|RangeError} If the test type or conditions are invalid.
|
|
41
|
-
*/
|
|
42
|
-
constructor(testType: TestTypeValue, conditions: Conditions, dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance);
|
|
43
|
-
/** @type {TestTypeValue} */
|
|
44
|
-
testType: TestTypeValue;
|
|
45
|
-
/** @type {Conditions} */
|
|
46
|
-
conditions: Conditions;
|
|
47
|
-
/** @type {DieTypeValue} */
|
|
48
|
-
dieType: DieTypeValue;
|
|
49
|
-
/** @type {RollModifierInstance} */
|
|
50
|
-
modifier: RollModifierInstance;
|
|
51
|
-
/** @type {{ min: number, max: number }} */
|
|
52
|
-
modifiedRange: {
|
|
53
|
-
min: number;
|
|
54
|
-
max: number;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Validates that the test conditions still conform to spec.
|
|
58
|
-
* @throws {TypeError} If the test conditions are invalid.
|
|
59
|
-
*/
|
|
60
|
-
validate(): void;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Validates test conditions against a modified range.
|
|
64
|
-
*
|
|
65
|
-
* @private
|
|
66
|
-
* @param {Conditions & Record<string, any>} c - Conditions with modifiedRange
|
|
67
|
-
* @param {TestTypeValue} testType
|
|
68
|
-
* @returns {boolean}
|
|
69
|
-
*/
|
|
70
|
-
export function areValidModifiedTestConditions(c: Conditions & Record<string, any>, testType: TestTypeValue): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* @typedef {import("./TestType").TestTypeValue} TestTypeValue
|
|
73
|
-
* @typedef {import("./DieType").DieTypeValue} DieTypeValue
|
|
74
|
-
* @typedef {import("./RollModifier").RollModifierFunction} RollModifierFunction
|
|
75
|
-
* @typedef {import("./RollModifier").RollModifierInstance} RollModifierInstance
|
|
76
|
-
*/
|
|
77
|
-
/**
|
|
78
|
-
* Computes the achievable range for a die + modifier combination.
|
|
79
|
-
*
|
|
80
|
-
* @private
|
|
81
|
-
* @param {DieTypeValue} dieType
|
|
82
|
-
* @param {RollModifierInstance} modifier
|
|
83
|
-
* @returns {{ min: number, max: number }}
|
|
84
|
-
*/
|
|
85
|
-
export function computeModifiedRange(dieType: DieTypeValue, modifier: RollModifierInstance): {
|
|
86
|
-
min: number;
|
|
87
|
-
max: number;
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=ModifiedTestConditions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ModifiedTestConditions.d.ts","sourceRoot":"","sources":["../../src/entities/ModifiedTestConditions.js"],"names":[],"mappings":"4BAyBa,OAAO,YAAY,EAAE,aAAa;2BAClC,OAAO,WAAW,EAAE,YAAY;mCAChC,OAAO,gBAAgB,EAAE,oBAAoB;mCAC7C,OAAO,gBAAgB,EAAE,oBAAoB;;mBAsN5C;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;;+BAI7B,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;+BACtC,iBAAiB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE;qCAChD,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE;8BACxC,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE;yBAI5F,gBAAgB,GAAG,eAAe,GAAG,gBAAgB,GAAG,sBAAsB;6CAI9E,YAAY,CAAC,OAAO,sBAAsB,CAAC;AA1MxD;;;;;GAKG;AACH;IACE;;;;;;OAMG;IACH,sBANW,aAAa,cACb,UAAU,WACV,YAAY,YACZ,oBAAoB,GAAG,oBAAoB,EAmErD;IAVC,4BAA4B;IAC5B,UADW,aAAa,CACA;IACxB,yBAAyB;IACzB,YADW,UAAU,CACO;IAC5B,2BAA2B;IAC3B,SADW,YAAY,CACD;IACtB,mCAAmC;IACnC,UADW,oBAAoB,CACZ;IACnB,2CAA2C;IAC3C,eADW;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CACb;IAG5B;;;OAGG;IACH,iBASC;CACF;AAED;;;;;;;GAOG;AACH,kDAJW,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAChC,aAAa,GACX,OAAO,CAiFnB;AAtND;;;;;GAKG;AAEH;;;;;;;GAOG;AACH,8CAJW,YAAY,YACZ,oBAAoB,GAClB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAgBxC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type OutcomeKey = keyof typeof Outcome;
|
|
2
|
-
export type OutcomeValue = (typeof Outcome)[keyof typeof Outcome];
|
|
3
|
-
export type Outcome = string;
|
|
4
|
-
/**
|
|
5
|
-
* @module @platonic-dice/core/src/entities/Outcome
|
|
6
|
-
* @description
|
|
7
|
-
* Enum for possible roll outcomes.
|
|
8
|
-
*
|
|
9
|
-
* @readonly
|
|
10
|
-
* @enum {string}
|
|
11
|
-
*/
|
|
12
|
-
export const Outcome: Readonly<{
|
|
13
|
-
Success: "success";
|
|
14
|
-
Failure: "failure";
|
|
15
|
-
CriticalSuccess: "critical_success";
|
|
16
|
-
CriticalFailure: "critical_failure";
|
|
17
|
-
}>;
|
|
18
|
-
/**
|
|
19
|
-
* Checks whether a given value is a valid `Outcome`.
|
|
20
|
-
*
|
|
21
|
-
* @function isValidOutcome
|
|
22
|
-
* @param {OutcomeValue | null | undefined} outcome
|
|
23
|
-
* @returns {boolean}
|
|
24
|
-
*/
|
|
25
|
-
export function isValidOutcome(outcome: OutcomeValue | null | undefined): boolean;
|
|
26
|
-
//# sourceMappingURL=Outcome.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Outcome.d.ts","sourceRoot":"","sources":["../../src/entities/Outcome.js"],"names":[],"mappings":"yBA6Ba,MAAM,OAAO,OAAO;2BACpB,CAAA,OAAO,OAAO,EAAC,MAAM,OAAO,OAAO,CAAC;sBAvBvC,MAAM;AANhB;;;;;;;GAOG;AACH;;;;;GAKG;AAEH;;;;;;GAMG;AACH,wCAHW,YAAY,GAAG,IAAI,GAAG,SAAS,GAC7B,OAAO,CAKnB"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
export type RollModifierFunction = (n: number) => number;
|
|
2
|
-
export type DiceModifier = {
|
|
3
|
-
/**
|
|
4
|
-
* Function or {@link RollModifier} applied to each individual die.
|
|
5
|
-
*/
|
|
6
|
-
each?: RollModifierFunction | RollModifier | null | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Function or {@link RollModifier} applied to the total (sum) of all dice.
|
|
9
|
-
*/
|
|
10
|
-
net?: RollModifierFunction | RollModifier | null | undefined;
|
|
11
|
-
};
|
|
12
|
-
export type RollModifierInstance = InstanceType<typeof RollModifier>;
|
|
13
|
-
/**
|
|
14
|
-
* @module @platonic-dice/core/src/entities/RollModifier
|
|
15
|
-
* @description
|
|
16
|
-
* Represents a numeric modifier applied to dice rolls.
|
|
17
|
-
*
|
|
18
|
-
* A `RollModifier` wraps a pure function `(n: number) => number`
|
|
19
|
-
* that takes a base roll and returns a modified value.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const bonus = new RollModifier(n => n + 2);
|
|
23
|
-
* const result = bonus.apply(10); // 12
|
|
24
|
-
*/
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {(n: number) => number} RollModifierFunction
|
|
27
|
-
* @description
|
|
28
|
-
* A function that takes a single numeric input (the base roll or the total sum)
|
|
29
|
-
* and returns a numeric result. Implementations SHOULD:
|
|
30
|
-
* - declare exactly one parameter (helps static checks: `fn.length === 1`)
|
|
31
|
-
* - accept a number and return a number (ideally integer for dice use-cases)
|
|
32
|
-
*
|
|
33
|
-
* Examples:
|
|
34
|
-
* - Per-die modifier: `(n) => n + 1`
|
|
35
|
-
* - Net modifier: `(sum) => Math.floor(sum * 1.5)`
|
|
36
|
-
*
|
|
37
|
-
* Notes:
|
|
38
|
-
* - The runtime `isValidRollModifier` performs a light validation:
|
|
39
|
-
* checks the function arity and performs a test call `fn(1)` to ensure
|
|
40
|
-
* a numeric, integer-like result is returned. Keep modifiers pure.
|
|
41
|
-
*/
|
|
42
|
-
/**
|
|
43
|
-
* @typedef {Object} DiceModifier
|
|
44
|
-
* @property {RollModifierFunction | RollModifier | null | undefined} [each]
|
|
45
|
-
* Function or {@link RollModifier} applied to each individual die.
|
|
46
|
-
* @property {RollModifierFunction | RollModifier | null | undefined} [net]
|
|
47
|
-
* Function or {@link RollModifier} applied to the total (sum) of all dice.
|
|
48
|
-
*
|
|
49
|
-
* @description
|
|
50
|
-
* Represents the composite modifier structure used by {@link rollDiceMod}.
|
|
51
|
-
* Each field is optional and defaults to the identity modifier if omitted.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* const modifier = {
|
|
55
|
-
* each: (n) => n + 1,
|
|
56
|
-
* net: (sum) => sum + 2,
|
|
57
|
-
* };
|
|
58
|
-
*
|
|
59
|
-
* const mod2 = {
|
|
60
|
-
* each: new RollModifier((n) => n * 2),
|
|
61
|
-
* };
|
|
62
|
-
*/
|
|
63
|
-
/**
|
|
64
|
-
* Represents a numeric modifier applied to dice rolls.
|
|
65
|
-
*/
|
|
66
|
-
export class RollModifier {
|
|
67
|
-
/**
|
|
68
|
-
* @param {RollModifierFunction} fn - Modifier function.
|
|
69
|
-
* @throws {TypeError} If the function is not a valid roll modifier.
|
|
70
|
-
*/
|
|
71
|
-
constructor(fn: RollModifierFunction);
|
|
72
|
-
/** @type {RollModifierFunction} */
|
|
73
|
-
fn: RollModifierFunction;
|
|
74
|
-
/**
|
|
75
|
-
* Applies this modifier to a roll result.
|
|
76
|
-
* @param {number} baseValue - The base roll result.
|
|
77
|
-
* @returns {number} - The modified roll result.
|
|
78
|
-
*/
|
|
79
|
-
apply(baseValue: number): number;
|
|
80
|
-
/**
|
|
81
|
-
* Validates that this modifier still conforms to spec.
|
|
82
|
-
* (Useful if modifiers are loaded dynamically or serialized.)
|
|
83
|
-
* @throws {TypeError} If the modifier is invalid.
|
|
84
|
-
*/
|
|
85
|
-
validate(): void;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Checks whether a given function is a valid roll modifier.
|
|
89
|
-
*
|
|
90
|
-
* @function isValidRollModifier
|
|
91
|
-
* @param {Function | null} m
|
|
92
|
-
* @returns {boolean}
|
|
93
|
-
*/
|
|
94
|
-
export function isValidRollModifier(m: Function | null): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* This function ensures all modifiers conform to the correct structure:
|
|
97
|
-
* - A {@link RollModifier} instance → returned as-is.
|
|
98
|
-
* - A function `(n: number) => number` → wrapped in a new {@link RollModifier}.
|
|
99
|
-
* - `null` or `undefined` → treated as an identity modifier.
|
|
100
|
-
*
|
|
101
|
-
* @function normaliseRollModifier
|
|
102
|
-
* @param {RollModifier | ((n: number) => number) | null | undefined} m
|
|
103
|
-
* The input modifier to normalise.
|
|
104
|
-
* @returns {RollModifier}
|
|
105
|
-
* A valid {@link RollModifier} instance.
|
|
106
|
-
* @throws {TypeError}
|
|
107
|
-
* If the input is invalid (not a RollModifier, function, or null/undefined).
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* const rm1 = normaliseRollModifier(); // → identity modifier
|
|
111
|
-
* const rm2 = normaliseRollModifier(x => x + 1); // → RollModifier wrapping function
|
|
112
|
-
* const rm3 = normaliseRollModifier(new RollModifier(x => x * 2)); // → same instance
|
|
113
|
-
*/
|
|
114
|
-
export function normaliseRollModifier(m: RollModifier | ((n: number) => number) | null | undefined): RollModifier;
|
|
115
|
-
//# sourceMappingURL=RollModifier.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RollModifier.d.ts","sourceRoot":"","sources":["../../src/entities/RollModifier.js"],"names":[],"mappings":"mCAca,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM;;;;;WAmBpB,oBAAoB,GAAG,YAAY,GAAG,IAAI,GAAG,SAAS;;;;UAEtD,oBAAoB,GAAG,YAAY,GAAG,IAAI,GAAG,SAAS;;mCAwGvD,YAAY,CAAC,OAAO,YAAY,CAAC;AA3I9C;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;GAEG;AACH;IACE;;;OAGG;IACH,gBAHW,oBAAoB,EAY9B;IAFC,mCAAmC;IACnC,IADW,oBAAoB,CACnB;IAGd;;;;OAIG;IACH,iBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;OAIG;IACH,iBAIC;CACF;AAED;;;;;;GAMG;AACH,uCAHW,WAAW,IAAI,GACb,OAAO,CAWnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,yCAZW,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,GAEvD,YAAY,CAgBxB"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export type RollTypeKey = keyof typeof RollType;
|
|
2
|
-
export type RollTypeValue = (typeof RollType)[keyof typeof RollType];
|
|
3
|
-
export type RollType = string;
|
|
4
|
-
/**
|
|
5
|
-
* @module @platonic-dice/core/src/entities/RollType
|
|
6
|
-
* @description
|
|
7
|
-
* Enum for roll modes (normal, advantage, disadvantage).
|
|
8
|
-
*
|
|
9
|
-
* @readonly
|
|
10
|
-
* @enum {string}
|
|
11
|
-
*/
|
|
12
|
-
export const RollType: Readonly<{
|
|
13
|
-
Advantage: "advantage";
|
|
14
|
-
Disadvantage: "disadvantage";
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* Checks whether a given value is a valid `RollType`.
|
|
18
|
-
*
|
|
19
|
-
* @function isValidRollType
|
|
20
|
-
* @param {RollTypeValue | null | undefined} rollType
|
|
21
|
-
* @returns {boolean}
|
|
22
|
-
*/
|
|
23
|
-
export function isValidRollType(rollType: RollTypeValue | null | undefined): boolean;
|
|
24
|
-
//# sourceMappingURL=RollType.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RollType.d.ts","sourceRoot":"","sources":["../../src/entities/RollType.js"],"names":[],"mappings":"0BA2Ba,MAAM,OAAO,QAAQ;4BACrB,CAAA,OAAO,QAAQ,EAAC,MAAM,OAAO,QAAQ,CAAC;uBArBzC,MAAM;AANhB;;;;;;;GAOG;AACH;;;GAGG;AAEH;;;;;;GAMG;AACH,0CAHW,aAAa,GAAG,IAAI,GAAG,SAAS,GAC9B,OAAO,CAKnB"}
|