@swrpg-online/dice 0.9.0 → 1.0.3
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 +103 -8
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +128 -0
- package/dist/dice.d.ts +1 -1
- package/dist/dice.js +289 -51
- package/dist/index.d.ts +3 -3
- package/dist/pools.d.ts +1 -1
- package/dist/pools.js +4 -4
- package/dist/types.d.ts +1 -1
- package/package.json +24 -3
- package/.github/workflows/publish.yml +0 -31
- package/.husky/.skip-tests +0 -0
- package/.husky/pre-commit +0 -32
- package/.replit +0 -8
- package/coverage/clover.xml +0 -113
- package/coverage/coverage-final.json +0 -4
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/dice.ts.html +0 -817
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -146
- package/coverage/lcov-report/index.ts.html +0 -109
- package/coverage/lcov-report/pools.ts.html +0 -253
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -246
- package/jest.config.js +0 -8
- package/src/dice.ts +0 -244
- package/src/index.ts +0 -8
- package/src/pools.ts +0 -56
- package/src/types.ts +0 -30
- package/tests/dice.test.ts +0 -351
- package/tests/pools.test.ts +0 -86
- package/tsconfig.json +0 -14
package/README.md
CHANGED
|
@@ -1,31 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dice
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
[](https://codecov.io/gh/swrpg-online/dice)
|
|
6
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
7
|
+
|
|
8
|
+
A TypeScript library that creates dice rolls using the [narrative dice system](https://star-wars-rpg-ffg.fandom.com/wiki/Narrative_Dice) for the Star Wars Role-Playing Game by [Fantasy Flight Games](https://www.fantasyflightgames.com/en/starwarsrpg/) and [Edge Studio](https://www.edge-studio.net/categories-games/starwarsrpg/).
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
7
12
|
```bash
|
|
8
|
-
npm
|
|
13
|
+
npm i @swrpg-online/dice
|
|
9
14
|
```
|
|
10
15
|
|
|
16
|
+
or optionally to use as a CLI command you can install globally with `npm i -g @swrpg-online/dice`
|
|
17
|
+
|
|
11
18
|
## Features
|
|
12
19
|
|
|
13
20
|
- Complete narrative dice system implementation
|
|
14
21
|
- Detailed roll breakdown for each die
|
|
15
22
|
- Comprehensive test coverage
|
|
16
23
|
- TypeScript type safety
|
|
24
|
+
- roll from a CLI
|
|
17
25
|
|
|
18
26
|
## Usage
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
via code:
|
|
21
29
|
|
|
22
30
|
```typescript
|
|
23
|
-
import { roll, DicePool } from 'swrpg-dice';
|
|
31
|
+
import { roll, DicePool } from '@swrpg-online/dice';
|
|
24
32
|
|
|
25
33
|
const pool: DicePool = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
abilityDice: 2,
|
|
35
|
+
proficiencyDice: 1,
|
|
36
|
+
difficultyDice: 1,
|
|
37
|
+
challengeDice: 1
|
|
29
38
|
};
|
|
30
39
|
|
|
31
40
|
const result = roll(pool);
|
|
@@ -33,11 +42,97 @@ const result = roll(pool);
|
|
|
33
42
|
// Access detailed results
|
|
34
43
|
console.log(result.results); // Array of individual die results
|
|
35
44
|
console.log(result.summary); // Summary of total successes, advantages, etc.
|
|
45
|
+
|
|
46
|
+
=> {
|
|
47
|
+
"results": [
|
|
48
|
+
{
|
|
49
|
+
"type": "ability",
|
|
50
|
+
"roll": 5,
|
|
51
|
+
"result": {
|
|
52
|
+
"successes": 0,
|
|
53
|
+
"failures": 0,
|
|
54
|
+
"advantages": 1,
|
|
55
|
+
"threats": 0,
|
|
56
|
+
"triumphs": 0,
|
|
57
|
+
"despair": 0
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"type": "ability",
|
|
62
|
+
"roll": 3,
|
|
63
|
+
"result": {
|
|
64
|
+
"successes": 1,
|
|
65
|
+
"failures": 0,
|
|
66
|
+
"advantages": 0,
|
|
67
|
+
"threats": 0,
|
|
68
|
+
"triumphs": 0,
|
|
69
|
+
"despair": 0
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"type": "proficiency",
|
|
74
|
+
"roll": 10,
|
|
75
|
+
"result": {
|
|
76
|
+
"successes": 0,
|
|
77
|
+
"failures": 0,
|
|
78
|
+
"advantages": 2,
|
|
79
|
+
"threats": 0,
|
|
80
|
+
"triumphs": 0,
|
|
81
|
+
"despair": 0
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"type": "difficulty",
|
|
86
|
+
"roll": 2,
|
|
87
|
+
"result": {
|
|
88
|
+
"successes": 0,
|
|
89
|
+
"failures": 1,
|
|
90
|
+
"advantages": 0,
|
|
91
|
+
"threats": 0,
|
|
92
|
+
"triumphs": 0,
|
|
93
|
+
"despair": 0
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"type": "challenge",
|
|
98
|
+
"roll": 11,
|
|
99
|
+
"result": {
|
|
100
|
+
"successes": 0,
|
|
101
|
+
"failures": 0,
|
|
102
|
+
"advantages": 0,
|
|
103
|
+
"threats": 2,
|
|
104
|
+
"triumphs": 0,
|
|
105
|
+
"despair": 0
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"summary": {
|
|
110
|
+
"successes": 0,
|
|
111
|
+
"failures": 0,
|
|
112
|
+
"advantages": 3,
|
|
113
|
+
"threats": 2,
|
|
114
|
+
"triumphs": 0,
|
|
115
|
+
"despair": 0
|
|
116
|
+
}
|
|
117
|
+
}
|
|
36
118
|
```
|
|
37
119
|
|
|
38
120
|
Each roll result includes:
|
|
121
|
+
|
|
39
122
|
- Detailed breakdown of each die roll
|
|
40
123
|
- Die type identification
|
|
41
124
|
- Individual results per die
|
|
42
125
|
- Overall summary of the roll
|
|
43
126
|
|
|
127
|
+
# Roadmap or Under Review
|
|
128
|
+
|
|
129
|
+
- implement the Force die
|
|
130
|
+
- implement ability to add success, failure, and so on to dice pools
|
|
131
|
+
- ship combat?
|
|
132
|
+
- crits?
|
|
133
|
+
- polyhedral dice for convenience?
|
|
134
|
+
- anything else?
|
|
135
|
+
|
|
136
|
+
# Contribution
|
|
137
|
+
|
|
138
|
+
This is a new library for a game with not a lot of open source tooling available - feedback and pull requests welcome!
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const dice_1 = require("./dice");
|
|
5
|
+
// import * as path from 'path';
|
|
6
|
+
function parseDiceNotation(input) {
|
|
7
|
+
const pool = {
|
|
8
|
+
boostDice: 0,
|
|
9
|
+
abilityDice: 0,
|
|
10
|
+
proficiencyDice: 0,
|
|
11
|
+
setBackDice: 0,
|
|
12
|
+
difficultyDice: 0,
|
|
13
|
+
challengeDice: 0,
|
|
14
|
+
};
|
|
15
|
+
// function getImagePath(type: string): string {
|
|
16
|
+
// const basePath = path.join(__dirname, 'images');
|
|
17
|
+
// switch (type) {
|
|
18
|
+
// case 'successes':
|
|
19
|
+
// return path.join(basePath, 'success.svg'); // Adjust path and extension as needed
|
|
20
|
+
// case 'failures':
|
|
21
|
+
// return path.join(basePath, 'failure.svg');
|
|
22
|
+
// case 'advantages':
|
|
23
|
+
// return path.join(basePath, 'advantage.svg');
|
|
24
|
+
// case 'threats':
|
|
25
|
+
// return path.join(basePath, 'threat.svg');
|
|
26
|
+
// case 'triumphs':
|
|
27
|
+
// return path.join(basePath, 'triumph.svg');
|
|
28
|
+
// case 'despair':
|
|
29
|
+
// return path.join(basePath, 'despair.svg');
|
|
30
|
+
// default:
|
|
31
|
+
// return '';
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
const parts = input.toLowerCase().trim().split(" ");
|
|
35
|
+
for (const part of parts) {
|
|
36
|
+
const count = parseInt(part);
|
|
37
|
+
const color = part.slice(String(count).length);
|
|
38
|
+
switch (color) {
|
|
39
|
+
// y/pro = Yellow/Proficiency
|
|
40
|
+
case "y":
|
|
41
|
+
pool.proficiencyDice = count;
|
|
42
|
+
break;
|
|
43
|
+
case "pro":
|
|
44
|
+
pool.proficiencyDice = count;
|
|
45
|
+
break;
|
|
46
|
+
// g/a = Green/Ability
|
|
47
|
+
case "g":
|
|
48
|
+
pool.abilityDice = count;
|
|
49
|
+
break;
|
|
50
|
+
case "a":
|
|
51
|
+
pool.abilityDice = count;
|
|
52
|
+
break;
|
|
53
|
+
// b/boo = Blue/Boost
|
|
54
|
+
case "b":
|
|
55
|
+
pool.setBackDice = count;
|
|
56
|
+
break;
|
|
57
|
+
case "boo":
|
|
58
|
+
pool.setBackDice = count;
|
|
59
|
+
break;
|
|
60
|
+
// r/c = Red/ Challenge
|
|
61
|
+
case "r":
|
|
62
|
+
pool.challengeDice = count;
|
|
63
|
+
break;
|
|
64
|
+
case "c":
|
|
65
|
+
pool.challengeDice = count;
|
|
66
|
+
break;
|
|
67
|
+
// p/diff = Purple/ Difficulty
|
|
68
|
+
case "p":
|
|
69
|
+
pool.difficultyDice = count;
|
|
70
|
+
break;
|
|
71
|
+
case "diff":
|
|
72
|
+
pool.difficultyDice = count;
|
|
73
|
+
break;
|
|
74
|
+
// blk/k/sb/s = Black/Setback
|
|
75
|
+
case "blk":
|
|
76
|
+
pool.boostDice = count;
|
|
77
|
+
break;
|
|
78
|
+
case "k":
|
|
79
|
+
pool.boostDice = count;
|
|
80
|
+
break;
|
|
81
|
+
case "sb":
|
|
82
|
+
pool.boostDice = count;
|
|
83
|
+
break;
|
|
84
|
+
case "s":
|
|
85
|
+
pool.boostDice = count;
|
|
86
|
+
break;
|
|
87
|
+
// w/f = White/Force
|
|
88
|
+
// TODO
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return pool;
|
|
92
|
+
}
|
|
93
|
+
function formatResult(result) {
|
|
94
|
+
const parts = [];
|
|
95
|
+
if (result.summary.successes > 0)
|
|
96
|
+
parts.push(`${result.summary.successes} Success(es)`);
|
|
97
|
+
if (result.summary.failures > 0)
|
|
98
|
+
parts.push(`${result.summary.failures} Failure(s)`);
|
|
99
|
+
if (result.summary.advantages > 0)
|
|
100
|
+
parts.push(`${result.summary.advantages} Advantage(s)`);
|
|
101
|
+
if (result.summary.threats > 0)
|
|
102
|
+
parts.push(`${result.summary.threats} Threat(s)`);
|
|
103
|
+
if (result.summary.triumphs > 0)
|
|
104
|
+
parts.push(`${result.summary.triumphs} Triumph(s)`);
|
|
105
|
+
if (result.summary.despair > 0)
|
|
106
|
+
parts.push(`${result.summary.despair} Despair(s)`);
|
|
107
|
+
return parts.join(", ") || "No effects";
|
|
108
|
+
}
|
|
109
|
+
const main = () => {
|
|
110
|
+
const input = process.argv.slice(2).join(" ");
|
|
111
|
+
if (!input) {
|
|
112
|
+
console.log(`Usage: > swrpg-dice 2y 1g 2p 1r
|
|
113
|
+
- y/pro = Yellow / Proficiency
|
|
114
|
+
- g/a = Green / Ability
|
|
115
|
+
- b/boo = Blue / Boost
|
|
116
|
+
- r/c = Red / Challenge
|
|
117
|
+
- p/diff = Purple / Difficulty
|
|
118
|
+
- blk/k/sb/s = Black / Setback
|
|
119
|
+
`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
const pool = parseDiceNotation(input);
|
|
123
|
+
const result = (0, dice_1.roll)(pool);
|
|
124
|
+
console.log(formatResult(result));
|
|
125
|
+
};
|
|
126
|
+
if (require.main === module) {
|
|
127
|
+
main();
|
|
128
|
+
}
|
package/dist/dice.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DicePool, RollResult } from
|
|
1
|
+
import { DicePool, RollResult } from "./types";
|
|
2
2
|
export declare const roll: (pool: DicePool) => RollResult;
|