@platonic-dice/core 2.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 +57 -0
- package/dist/entities/DieType.d.ts +35 -0
- package/dist/entities/DieType.d.ts.map +1 -0
- package/dist/entities/DieType.js +43 -0
- package/dist/entities/Outcome.d.ts +26 -0
- package/dist/entities/Outcome.d.ts.map +1 -0
- package/dist/entities/Outcome.js +37 -0
- package/dist/entities/RollModifier.d.ts +115 -0
- package/dist/entities/RollModifier.d.ts.map +1 -0
- package/dist/entities/RollModifier.js +147 -0
- package/dist/entities/RollType.d.ts +24 -0
- package/dist/entities/RollType.d.ts.map +1 -0
- package/dist/entities/RollType.js +35 -0
- package/dist/entities/TestConditions.d.ts +97 -0
- package/dist/entities/TestConditions.d.ts.map +1 -0
- package/dist/entities/TestConditions.js +324 -0
- package/dist/entities/TestType.d.ts +28 -0
- package/dist/entities/TestType.d.ts.map +1 -0
- package/dist/entities/TestType.js +39 -0
- package/dist/entities/index.d.ts +16 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +46 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/roll.d.ts +66 -0
- package/dist/roll.d.ts.map +1 -0
- package/dist/roll.js +135 -0
- package/dist/rollDice.d.ts +48 -0
- package/dist/rollDice.d.ts.map +1 -0
- package/dist/rollDice.js +92 -0
- package/dist/rollDiceMod.d.ts +54 -0
- package/dist/rollDiceMod.d.ts.map +1 -0
- package/dist/rollDiceMod.js +137 -0
- package/dist/rollMod.d.ts +52 -0
- package/dist/rollMod.d.ts.map +1 -0
- package/dist/rollMod.js +114 -0
- package/dist/rollTest.d.ts +40 -0
- package/dist/rollTest.d.ts.map +1 -0
- package/dist/rollTest.js +100 -0
- package/dist/utils/determineOutcome.d.ts +45 -0
- package/dist/utils/determineOutcome.d.ts.map +1 -0
- package/dist/utils/determineOutcome.js +115 -0
- package/dist/utils/generateResult.d.ts +30 -0
- package/dist/utils/generateResult.d.ts.map +1 -0
- package/dist/utils/generateResult.js +51 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +26 -0
- package/dist-types.d.ts +48 -0
- package/package.json +46 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @dice/core/src/entities/TestConditions
|
|
3
|
+
* @description
|
|
4
|
+
* This class validates the test type and associated conditions
|
|
5
|
+
* against the provided {@link DieType} during construction.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const tc = new TestConditions(TestType.AtLeast, { target: 15 }, DieType.D20);
|
|
9
|
+
* const result = rollTest(DieType.D20, tc);
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { isValidDieType } = require("./DieType");
|
|
13
|
+
const { isValidTestType } = require("./TestType");
|
|
14
|
+
const { numSides } = require("../utils");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {import("./TestType").TestTypeValue} TestTypeValue
|
|
18
|
+
* @typedef {import("./DieType").DieTypeValue} DieTypeValue
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents a set of conditions for a dice roll test.
|
|
23
|
+
*/
|
|
24
|
+
class TestConditions {
|
|
25
|
+
/**
|
|
26
|
+
* @param {TestTypeValue} testType - The test type.
|
|
27
|
+
* @param {Conditions} conditions - The test conditions object.
|
|
28
|
+
* @param {DieTypeValue} dieType - The die type to validate numeric ranges.
|
|
29
|
+
* @throws {TypeError|RangeError} If the test type or conditions are invalid.
|
|
30
|
+
*/
|
|
31
|
+
constructor(testType, conditions, dieType) {
|
|
32
|
+
if (!isValidTestType(testType)) {
|
|
33
|
+
throw new TypeError(`Invalid test type: ${testType}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!conditions || typeof conditions !== "object") {
|
|
37
|
+
throw new TypeError("conditions must be an object.");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!dieType) {
|
|
41
|
+
throw new TypeError("dieType is required to validate TestConditions.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Validate conditions immediately
|
|
45
|
+
if (!areValidTestConditions({ ...conditions, dieType }, testType)) {
|
|
46
|
+
switch (testType) {
|
|
47
|
+
case "at_least":
|
|
48
|
+
case "at_most":
|
|
49
|
+
case "exact":
|
|
50
|
+
throw new RangeError(
|
|
51
|
+
`Invalid ${testType} condition for die type ${dieType}: target must be an integer within valid die faces.`
|
|
52
|
+
);
|
|
53
|
+
case "within":
|
|
54
|
+
throw new RangeError(
|
|
55
|
+
`Invalid 'within' condition for die type ${dieType}: min must be ≤ max and both valid face values.`
|
|
56
|
+
);
|
|
57
|
+
case "in_list":
|
|
58
|
+
throw new RangeError(
|
|
59
|
+
`Invalid 'specificList' condition for die type ${dieType}: values must be a non-empty array of valid face values.`
|
|
60
|
+
);
|
|
61
|
+
case "skill":
|
|
62
|
+
throw new RangeError(
|
|
63
|
+
`Invalid 'skill' condition for die type ${dieType}: target, critical_success, and critical_failure must be valid and logically ordered.`
|
|
64
|
+
);
|
|
65
|
+
default:
|
|
66
|
+
throw new TypeError(`Unknown testType '${testType}'.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @type {TestTypeValue} */
|
|
71
|
+
this.testType = testType;
|
|
72
|
+
/** @type {Conditions} */
|
|
73
|
+
this.conditions = conditions;
|
|
74
|
+
/** @type {DieTypeValue} */
|
|
75
|
+
this.dieType = dieType;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Validates that the test conditions still conforms to spec.
|
|
80
|
+
* (Useful if they are loaded dynamically or serialized.)
|
|
81
|
+
* @throws {TypeError} If the test conditions are invalid.
|
|
82
|
+
*/
|
|
83
|
+
validate() {
|
|
84
|
+
if (
|
|
85
|
+
!areValidTestConditions(
|
|
86
|
+
{ ...this.conditions, dieType: this.dieType },
|
|
87
|
+
this.testType
|
|
88
|
+
)
|
|
89
|
+
) {
|
|
90
|
+
throw new TypeError("Invalid test conditions shape.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Master validation function for all test conditions.
|
|
97
|
+
*
|
|
98
|
+
* @function areValidTestConditions
|
|
99
|
+
* @param {Conditions} c
|
|
100
|
+
* @param {TestTypeValue} testType
|
|
101
|
+
* @returns {boolean}
|
|
102
|
+
*/
|
|
103
|
+
function areValidTestConditions(c, testType) {
|
|
104
|
+
switch (testType) {
|
|
105
|
+
case "at_least":
|
|
106
|
+
case "at_most":
|
|
107
|
+
case "exact":
|
|
108
|
+
// @ts-expect-error: we know c is TargetConditions for these test types
|
|
109
|
+
return isValidTargetConditions(c);
|
|
110
|
+
case "within":
|
|
111
|
+
// @ts-expect-error: we know c is WithinConditions for this test type
|
|
112
|
+
return isValidWithinConditions(c);
|
|
113
|
+
case "in_list":
|
|
114
|
+
// @ts-expect-error: we know c is SpecificListConditions
|
|
115
|
+
return isValidSpecificListConditions(c);
|
|
116
|
+
// case "odd":
|
|
117
|
+
// case "even":
|
|
118
|
+
// return isValidOddEvenCondition(c);
|
|
119
|
+
case "skill":
|
|
120
|
+
// @ts-expect-error: we know c is SkillConditions
|
|
121
|
+
return isValidSkillTestCondition(c);
|
|
122
|
+
default:
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Normalises any input into a {@link TestConditions} instance.
|
|
129
|
+
* Supports both pre-existing instances and plain objects.
|
|
130
|
+
* Automatically validates all conditions for the specified die type.
|
|
131
|
+
*
|
|
132
|
+
* @function normaliseTestConditions
|
|
133
|
+
* @param {TestConditions | { testType: TestTypeValue, [key: string]: any }} tc
|
|
134
|
+
* A {@link TestConditions} instance or plain object with `testType` and other fields.
|
|
135
|
+
* @param {DieTypeValue} dieType
|
|
136
|
+
* The die type (e.g., `'d6'`, `'d20'`) used for validation.
|
|
137
|
+
* @returns {TestConditions}
|
|
138
|
+
* A validated {@link TestConditions} instance.
|
|
139
|
+
* @throws {TypeError}
|
|
140
|
+
* If the input is neither a TestConditions instance nor a plain object.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* // Passing a plain object
|
|
144
|
+
* const conditions = normaliseTestConditions({ testType: 'atLeast', target: 4 }, 'd6');
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // Passing an existing TestConditions instance
|
|
148
|
+
* const existing = new TestConditions('exact', { target: 3 }, 'd6');
|
|
149
|
+
* const conditions2 = normaliseTestConditions(existing, 'd6');
|
|
150
|
+
*/
|
|
151
|
+
function normaliseTestConditions(tc, dieType) {
|
|
152
|
+
if (tc instanceof TestConditions) return tc;
|
|
153
|
+
if (tc && typeof tc === "object") {
|
|
154
|
+
const { testType, ...rest } = tc;
|
|
155
|
+
|
|
156
|
+
// @ts-expect-error: we are asserting that the rest of the object plus dieType
|
|
157
|
+
// will conform to the Conditions union when passed to the constructor
|
|
158
|
+
return new TestConditions(testType, { ...rest }, dieType);
|
|
159
|
+
}
|
|
160
|
+
throw new TypeError(
|
|
161
|
+
`Invalid TestConditions: must be a TestConditions instance or a plain object.`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Represents any valid dice roll test condition.
|
|
167
|
+
*
|
|
168
|
+
* This is a union type of all the internal test condition shapes:
|
|
169
|
+
* - `TargetConditions` – single target value
|
|
170
|
+
* - `SkillConditions` – target with optional critical thresholds
|
|
171
|
+
* - `WithinConditions` – min/max range
|
|
172
|
+
* - `SpecificListConditions` – array of specific allowed values
|
|
173
|
+
*
|
|
174
|
+
* @typedef {TargetConditions | SkillConditions | WithinConditions | SpecificListConditions} Conditions
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @typedef {InstanceType<typeof TestConditions>} TestConditionsInstance
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
module.exports = {
|
|
182
|
+
TestConditions,
|
|
183
|
+
areValidTestConditions,
|
|
184
|
+
normaliseTestConditions,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
//
|
|
188
|
+
// PRIVATE HELPER FUNCTIONS
|
|
189
|
+
//
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @private
|
|
193
|
+
* @typedef {Object} BaseTestCondition
|
|
194
|
+
* @property {DieTypeValue} dieType
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @private
|
|
199
|
+
* @typedef {BaseTestCondition & { target: number }} TargetConditions
|
|
200
|
+
* @private
|
|
201
|
+
* @typedef {BaseTestCondition & { min: number, max: number }} WithinConditions
|
|
202
|
+
* @private
|
|
203
|
+
* @typedef {BaseTestCondition & { values: number[] }} SpecificListConditions
|
|
204
|
+
* @private
|
|
205
|
+
* @typedef {BaseTestCondition & { target: number, critical_success?: number, critical_failure?: number }} SkillConditions
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Checks if a number is a valid face value for a die with the given sides.
|
|
210
|
+
*
|
|
211
|
+
* @private
|
|
212
|
+
* @function isValidFaceValue
|
|
213
|
+
* @param {number} n
|
|
214
|
+
* @param {number} sides
|
|
215
|
+
* @returns {boolean}
|
|
216
|
+
*/
|
|
217
|
+
function isValidFaceValue(n, sides) {
|
|
218
|
+
return Number.isInteger(n) && n >= 1 && n <= sides;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Checks multiple keys in an object for valid face values.
|
|
223
|
+
*
|
|
224
|
+
* @private
|
|
225
|
+
* @function areValidFaceValues
|
|
226
|
+
* @template T
|
|
227
|
+
* @param {T} obj
|
|
228
|
+
* @param {number} sides
|
|
229
|
+
* @param {(keyof T)[]} keys
|
|
230
|
+
* @returns {boolean}
|
|
231
|
+
*/
|
|
232
|
+
function areValidFaceValues(obj, sides, keys) {
|
|
233
|
+
return keys.every((key) => {
|
|
234
|
+
const value = obj[key];
|
|
235
|
+
return (
|
|
236
|
+
value == null || isValidFaceValue(/** @type {number} */ (value), sides)
|
|
237
|
+
);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Validates the ordering of target and critical thresholds.
|
|
243
|
+
*
|
|
244
|
+
* @private
|
|
245
|
+
* @function isValidThresholdOrder
|
|
246
|
+
* @param {SkillConditions} thresholds
|
|
247
|
+
* @returns {boolean}
|
|
248
|
+
*/
|
|
249
|
+
function isValidThresholdOrder({ target, critical_success, critical_failure }) {
|
|
250
|
+
if (critical_failure != null && critical_failure >= target) return false;
|
|
251
|
+
if (critical_success != null && critical_success < target) return false;
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Validates a target-based condition.
|
|
257
|
+
*
|
|
258
|
+
* @private
|
|
259
|
+
* @function isValidTargetConditions
|
|
260
|
+
* @param {TargetConditions} c
|
|
261
|
+
* @returns {boolean}
|
|
262
|
+
*/
|
|
263
|
+
function isValidTargetConditions(c) {
|
|
264
|
+
if (!c || !isValidDieType(c.dieType)) return false;
|
|
265
|
+
return isValidFaceValue(c.target, numSides(c.dieType));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Validates a skill-based test condition.
|
|
270
|
+
*
|
|
271
|
+
* @private
|
|
272
|
+
* @function isValidSkillTestCondition
|
|
273
|
+
* @param {SkillConditions} c
|
|
274
|
+
* @returns {boolean}
|
|
275
|
+
*/
|
|
276
|
+
function isValidSkillTestCondition(c) {
|
|
277
|
+
if (!c || !isValidDieType(c.dieType)) return false;
|
|
278
|
+
const sides = numSides(c.dieType);
|
|
279
|
+
|
|
280
|
+
if (
|
|
281
|
+
!areValidFaceValues(c, sides, [
|
|
282
|
+
"target",
|
|
283
|
+
"critical_success",
|
|
284
|
+
"critical_failure",
|
|
285
|
+
])
|
|
286
|
+
)
|
|
287
|
+
return false;
|
|
288
|
+
if (!isValidThresholdOrder(c)) return false;
|
|
289
|
+
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Validates a "within" range condition.
|
|
295
|
+
*
|
|
296
|
+
* @private
|
|
297
|
+
* @function isValidWithinConditions
|
|
298
|
+
* @param {WithinConditions} c
|
|
299
|
+
* @returns {boolean}
|
|
300
|
+
*/
|
|
301
|
+
function isValidWithinConditions(c) {
|
|
302
|
+
if (!c || !isValidDieType(c.dieType)) return false;
|
|
303
|
+
const sides = numSides(c.dieType);
|
|
304
|
+
|
|
305
|
+
if (!areValidFaceValues(c, sides, ["min", "max"])) return false;
|
|
306
|
+
if (c.min > c.max) return false;
|
|
307
|
+
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Validates a "specific list" condition.
|
|
313
|
+
*
|
|
314
|
+
* @private
|
|
315
|
+
* @function isValidSpecificListConditions
|
|
316
|
+
* @param {SpecificListConditions} c
|
|
317
|
+
* @returns {boolean}
|
|
318
|
+
*/
|
|
319
|
+
function isValidSpecificListConditions(c) {
|
|
320
|
+
if (!c || !isValidDieType(c.dieType)) return false;
|
|
321
|
+
const sides = numSides(c.dieType);
|
|
322
|
+
if (!Array.isArray(c.values) || c.values.length === 0) return false;
|
|
323
|
+
return c.values.every((v) => isValidFaceValue(v, sides));
|
|
324
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type TestTypeKey = keyof typeof TestType;
|
|
2
|
+
export type TestTypeValue = (typeof TestType)[keyof typeof TestType];
|
|
3
|
+
export type TestType = string;
|
|
4
|
+
/**
|
|
5
|
+
* @module @platonic-dice/core/src/entities/TestType
|
|
6
|
+
* @description
|
|
7
|
+
* Enum for test evaluation types (used in {@link TestConditions}).
|
|
8
|
+
*
|
|
9
|
+
* @readonly
|
|
10
|
+
* @enum {string}
|
|
11
|
+
*/
|
|
12
|
+
export const TestType: Readonly<{
|
|
13
|
+
Exact: "exact";
|
|
14
|
+
AtLeast: "at_least";
|
|
15
|
+
AtMost: "at_most";
|
|
16
|
+
Within: "within";
|
|
17
|
+
InList: "in_list";
|
|
18
|
+
Skill: "skill";
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Checks whether a given value is a valid `TestType`.
|
|
22
|
+
*
|
|
23
|
+
* @function isValidTestType
|
|
24
|
+
* @param {TestTypeValue | null | undefined} testType
|
|
25
|
+
* @returns {boolean}
|
|
26
|
+
*/
|
|
27
|
+
export function isValidTestType(testType: TestTypeValue | null | undefined): boolean;
|
|
28
|
+
//# sourceMappingURL=TestType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestType.d.ts","sourceRoot":"","sources":["../../src/entities/TestType.js"],"names":[],"mappings":"0BA+Ba,MAAM,OAAO,QAAQ;4BACrB,CAAA,OAAO,QAAQ,EAAC,MAAM,OAAO,QAAQ,CAAC;uBAzBzC,MAAM;AANhB;;;;;;;GAOG;AACH;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,0CAHW,aAAa,GAAG,IAAI,GAAG,SAAS,GAC9B,OAAO,CAKnB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module @platonic-dice/core/src/entities/TestType
|
|
4
|
+
* @description
|
|
5
|
+
* Enum for test evaluation types (used in {@link TestConditions}).
|
|
6
|
+
*
|
|
7
|
+
* @readonly
|
|
8
|
+
* @enum {string}
|
|
9
|
+
*/
|
|
10
|
+
const TestType = Object.freeze({
|
|
11
|
+
Exact: "exact", // Must roll exactly this number
|
|
12
|
+
AtLeast: "at_least", // Roll ≥ target
|
|
13
|
+
AtMost: "at_most", // Roll ≤ target
|
|
14
|
+
Within: "within", // Roll within [min, max]
|
|
15
|
+
InList: "in_list", // Roll in array of valid values
|
|
16
|
+
Skill: "skill", // Classic skill/threshold test (with crits)
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether a given value is a valid `TestType`.
|
|
21
|
+
*
|
|
22
|
+
* @function isValidTestType
|
|
23
|
+
* @param {TestTypeValue | null | undefined} testType
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
function isValidTestType(testType) {
|
|
27
|
+
if (!testType) return false;
|
|
28
|
+
return Object.values(TestType).includes(testType);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {keyof typeof TestType} TestTypeKey
|
|
33
|
+
* @typedef {typeof TestType[keyof typeof TestType]} TestTypeValue
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
TestType,
|
|
38
|
+
isValidTestType,
|
|
39
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DieType } from "./DieType.js";
|
|
2
|
+
import { isValidDieType } from "./DieType.js";
|
|
3
|
+
import { Outcome } from "./Outcome.js";
|
|
4
|
+
import { isValidOutcome } from "./Outcome.js";
|
|
5
|
+
import { RollModifier } from "./RollModifier.js";
|
|
6
|
+
import { isValidRollModifier } from "./RollModifier.js";
|
|
7
|
+
import { normaliseRollModifier } from "./RollModifier.js";
|
|
8
|
+
import { RollType } from "./RollType.js";
|
|
9
|
+
import { isValidRollType } from "./RollType.js";
|
|
10
|
+
import { TestConditions } from "./TestConditions.js";
|
|
11
|
+
import { areValidTestConditions } from "./TestConditions.js";
|
|
12
|
+
import { normaliseTestConditions } from "./TestConditions.js";
|
|
13
|
+
import { TestType } from "./TestType.js";
|
|
14
|
+
import { isValidTestType } from "./TestType.js";
|
|
15
|
+
export { DieType, isValidDieType, Outcome, isValidOutcome, RollModifier, isValidRollModifier, normaliseRollModifier, RollType, isValidRollType, TestConditions, areValidTestConditions, normaliseTestConditions, TestType, isValidTestType };
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @platonic-dice/core/src/entities
|
|
3
|
+
* @description
|
|
4
|
+
* Core entity definitions for the `@platonic-dice/core` package.
|
|
5
|
+
*
|
|
6
|
+
* Exports all primary enumerations, classes, and data types used throughout
|
|
7
|
+
* the dice logic system.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { DieType, RollType, RollModifier } from "@platonic-dice/core/src/entities";
|
|
11
|
+
*
|
|
12
|
+
* const mod = new RollModifier((n) => n + 2);
|
|
13
|
+
* const result = roll(DieType.D20, RollType.Advantage);
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const { DieType, isValidDieType } = require("./DieType.js");
|
|
17
|
+
const { Outcome, isValidOutcome } = require("./Outcome.js");
|
|
18
|
+
const {
|
|
19
|
+
RollModifier,
|
|
20
|
+
isValidRollModifier,
|
|
21
|
+
normaliseRollModifier,
|
|
22
|
+
} = require("./RollModifier.js");
|
|
23
|
+
const { RollType, isValidRollType } = require("./RollType.js");
|
|
24
|
+
const {
|
|
25
|
+
TestConditions,
|
|
26
|
+
areValidTestConditions,
|
|
27
|
+
normaliseTestConditions,
|
|
28
|
+
} = require("./TestConditions.js");
|
|
29
|
+
const { TestType, isValidTestType } = require("./TestType.js");
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
DieType,
|
|
33
|
+
isValidDieType,
|
|
34
|
+
Outcome,
|
|
35
|
+
isValidOutcome,
|
|
36
|
+
RollModifier,
|
|
37
|
+
isValidRollModifier,
|
|
38
|
+
normaliseRollModifier,
|
|
39
|
+
RollType,
|
|
40
|
+
isValidRollType,
|
|
41
|
+
TestConditions,
|
|
42
|
+
areValidTestConditions,
|
|
43
|
+
normaliseTestConditions,
|
|
44
|
+
TestType,
|
|
45
|
+
isValidTestType,
|
|
46
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const _exports: typeof import("./roll") & typeof import("./rollDice") & typeof import("./rollMod") & typeof import("./rollDiceMod") & typeof import("./rollTest") & typeof import("./entities") & {
|
|
2
|
+
default: any;
|
|
3
|
+
};
|
|
4
|
+
export = _exports;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"wBAsBU,cAAc,QAAQ,CAAC,GAChC,cAAuB,YAAY,CAAC,GACpC,cAAuB,WAAW,CAAC,GACnC,cAAuB,eAAe,CAAC,GACvC,cAAuB,YAAY,CAAC,GACpC,cAAuB,YAAY,CAAC,GACpC;IAAW,OAAO,EAAE,GAAG,CAAA;CAAE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core
|
|
3
|
+
* @description
|
|
4
|
+
* Primary entry point for the core dice logic.
|
|
5
|
+
* Re-exports all main rolling functions and modifiers.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { roll, rollMod, rollDice, rollDiceMod, rollTest } from "@platonic-dice/core";
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// --- Core modules ---
|
|
12
|
+
const rollDice = require("./rollDice.js");
|
|
13
|
+
const roll = require("./roll.js");
|
|
14
|
+
const rollMod = require("./rollMod.js");
|
|
15
|
+
const rollDiceMod = require("./rollDiceMod.js");
|
|
16
|
+
const rollTest = require("./rollTest.js");
|
|
17
|
+
|
|
18
|
+
// --- Entities (public API) ---
|
|
19
|
+
const entities = require("./entities");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Combined exports for Node and TypeScript users.
|
|
23
|
+
* @type {typeof import("./roll") &
|
|
24
|
+
* typeof import("./rollDice") &
|
|
25
|
+
* typeof import("./rollMod") &
|
|
26
|
+
* typeof import("./rollDiceMod") &
|
|
27
|
+
* typeof import("./rollTest") &
|
|
28
|
+
* typeof import("./entities") &
|
|
29
|
+
* { default: any }}
|
|
30
|
+
*/
|
|
31
|
+
module.exports = {
|
|
32
|
+
...roll,
|
|
33
|
+
...rollDice,
|
|
34
|
+
...rollMod,
|
|
35
|
+
...rollDiceMod,
|
|
36
|
+
...entities,
|
|
37
|
+
...rollTest,
|
|
38
|
+
default: undefined, // placeholder; will be overwritten
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// assign default at runtime
|
|
42
|
+
module.exports.default = module.exports;
|
package/dist/roll.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type DieTypeValue = import("./entities/DieType").DieTypeValue;
|
|
2
|
+
export type RollTypeValue = import("./entities/RollType").RollTypeValue;
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
|
|
5
|
+
* @typedef {import("./entities/RollType").RollTypeValue} RollTypeValue
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Rolls a single die of the specified type, optionally applying advantage or disadvantage.
|
|
9
|
+
*
|
|
10
|
+
* @function roll
|
|
11
|
+
* @param {DieTypeValue} dieType - The type of die to roll (e.g., `DieType.D20`).
|
|
12
|
+
* @param {RollTypeValue | undefined} [rollType=undefined] - Optional roll mode (`RollType.Advantage` or `RollType.Disadvantage`).
|
|
13
|
+
* @returns {number} The rolled value (integer between 1 and the die's maximum face).
|
|
14
|
+
* @throws {TypeError} If `dieType` or `rollType` are invalid.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const result = roll(DieType.D20, RollType.Advantage);
|
|
18
|
+
*/
|
|
19
|
+
export function roll(dieType: DieTypeValue, rollType?: RollTypeValue | undefined): number;
|
|
20
|
+
/**
|
|
21
|
+
* Rolls a die with advantage.
|
|
22
|
+
* @type {(dieType: DieTypeValue) => number}
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const result = rollAdv(DieType.D10);
|
|
26
|
+
*/
|
|
27
|
+
export const rollAdv: (dieType: DieTypeValue) => number;
|
|
28
|
+
/**
|
|
29
|
+
* Rolls a die with disadvantage.
|
|
30
|
+
* @type {(dieType: DieTypeValue) => number}
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const result = rollDis(DieType.D10);
|
|
34
|
+
*/
|
|
35
|
+
export const rollDis: (dieType: DieTypeValue) => number;
|
|
36
|
+
/**
|
|
37
|
+
* Rolls a D4 die.
|
|
38
|
+
* @type {(rollType?: RollTypeValue | undefined) => number}
|
|
39
|
+
*/
|
|
40
|
+
export const rollD4: (rollType?: RollTypeValue | undefined) => number;
|
|
41
|
+
/**
|
|
42
|
+
* Rolls a D6 die.
|
|
43
|
+
* @type {(rollType?: RollTypeValue | undefined) => number}
|
|
44
|
+
*/
|
|
45
|
+
export const rollD6: (rollType?: RollTypeValue | undefined) => number;
|
|
46
|
+
/**
|
|
47
|
+
* Rolls a D8 die.
|
|
48
|
+
* @type {(rollType?: RollTypeValue | undefined) => number}
|
|
49
|
+
*/
|
|
50
|
+
export const rollD8: (rollType?: RollTypeValue | undefined) => number;
|
|
51
|
+
/**
|
|
52
|
+
* Rolls a D10 die.
|
|
53
|
+
* @type {(rollType?: RollTypeValue | undefined) => number}
|
|
54
|
+
*/
|
|
55
|
+
export const rollD10: (rollType?: RollTypeValue | undefined) => number;
|
|
56
|
+
/**
|
|
57
|
+
* Rolls a D12 die.
|
|
58
|
+
* @type {(rollType?: RollTypeValue | undefined) => number}
|
|
59
|
+
*/
|
|
60
|
+
export const rollD12: (rollType?: RollTypeValue | undefined) => number;
|
|
61
|
+
/**
|
|
62
|
+
* Rolls a D20 die.
|
|
63
|
+
* @type {(rollType?: RollTypeValue | undefined) => number}
|
|
64
|
+
*/
|
|
65
|
+
export const rollD20: (rollType?: RollTypeValue | undefined) => number;
|
|
66
|
+
//# sourceMappingURL=roll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roll.d.ts","sourceRoot":"","sources":["../src/roll.js"],"names":[],"mappings":"2BA8Ba,OAAO,oBAAoB,EAAE,YAAY;4BACzC,OAAO,qBAAqB,EAAE,aAAa;AAFxD;;;GAGG;AAEH;;;;;;;;;;;GAWG;AACH,8BARW,YAAY,aACZ,aAAa,GAAG,SAAS,GACvB,MAAM,CAwBlB;AAMD;;;;;;GAMG;AACH,sBALU,CAAC,OAAO,EAAE,YAAY,KAAK,MAAM,CAKoB;AAE/D;;;;;;GAMG;AACH,sBALU,CAAC,OAAO,EAAE,YAAY,KAAK,MAAM,CAKuB;AAElE;;;GAGG;AACH,qBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEU;AAEpE;;;GAGG;AACH,qBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEU;AAEpE;;;GAGG;AACH,qBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEU;AAEpE;;;GAGG;AACH,sBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEY;AAEtE;;;GAGG;AACH,sBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEY;AAEtE;;;GAGG;AACH,sBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEY"}
|