@swrpg-online/dice 0.9.0 → 1.0.4

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 CHANGED
@@ -1,31 +1,40 @@
1
- # swrpg-dice
1
+ # dice
2
2
 
3
- A TypeScript library for simulating Star Wars RPG narrative dice rolls.
3
+ ![npm version](https://img.shields.io/npm/v/@swrpg-online/dice)
4
+ ![build](https://github.com/swrpg-online/dice/actions/workflows/release.yml/badge.svg)
5
+ [![codecov](https://codecov.io/gh/swrpg-online/dice/graph/badge.svg?token=BQIFNBWKI8)](https://codecov.io/gh/swrpg-online/dice)
6
+ [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](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 install swrpg-dice
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
- Basic usage:
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
- proficiencyDice: 2,
27
- abilityDice: 1,
28
- difficultyDice: 2
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
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { DicePool } from "./types";
3
+ export declare function parseDiceNotation(input: string): DicePool;
4
+ export declare function formatResult(result: any): string;
package/dist/cli.js ADDED
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.parseDiceNotation = parseDiceNotation;
5
+ exports.formatResult = formatResult;
6
+ const dice_1 = require("./dice");
7
+ // import * as path from 'path';
8
+ function parseDiceNotation(input) {
9
+ const pool = {
10
+ boostDice: 0,
11
+ abilityDice: 0,
12
+ proficiencyDice: 0,
13
+ setBackDice: 0,
14
+ difficultyDice: 0,
15
+ challengeDice: 0,
16
+ };
17
+ // function getImagePath(type: string): string {
18
+ // const basePath = path.join(__dirname, 'images');
19
+ // switch (type) {
20
+ // case 'successes':
21
+ // return path.join(basePath, 'success.svg'); // Adjust path and extension as needed
22
+ // case 'failures':
23
+ // return path.join(basePath, 'failure.svg');
24
+ // case 'advantages':
25
+ // return path.join(basePath, 'advantage.svg');
26
+ // case 'threats':
27
+ // return path.join(basePath, 'threat.svg');
28
+ // case 'triumphs':
29
+ // return path.join(basePath, 'triumph.svg');
30
+ // case 'despair':
31
+ // return path.join(basePath, 'despair.svg');
32
+ // default:
33
+ // return '';
34
+ // }
35
+ // }
36
+ const parts = input.toLowerCase().trim().split(" ");
37
+ for (const part of parts) {
38
+ const count = parseInt(part);
39
+ const color = part.slice(String(count).length);
40
+ switch (color) {
41
+ // y/pro = Yellow/Proficiency
42
+ case "y":
43
+ pool.proficiencyDice = count;
44
+ break;
45
+ case "pro":
46
+ pool.proficiencyDice = count;
47
+ break;
48
+ // g/a = Green/Ability
49
+ case "g":
50
+ pool.abilityDice = count;
51
+ break;
52
+ case "a":
53
+ pool.abilityDice = count;
54
+ break;
55
+ // b/boo = Blue/Boost
56
+ case "b":
57
+ pool.setBackDice = count;
58
+ break;
59
+ case "boo":
60
+ pool.setBackDice = count;
61
+ break;
62
+ // r/c = Red/ Challenge
63
+ case "r":
64
+ pool.challengeDice = count;
65
+ break;
66
+ case "c":
67
+ pool.challengeDice = count;
68
+ break;
69
+ // p/diff = Purple/ Difficulty
70
+ case "p":
71
+ pool.difficultyDice = count;
72
+ break;
73
+ case "diff":
74
+ pool.difficultyDice = count;
75
+ break;
76
+ // blk/k/sb/s = Black/Setback
77
+ case "blk":
78
+ pool.setBackDice = count;
79
+ break;
80
+ case "k":
81
+ pool.setBackDice = count;
82
+ break;
83
+ case "sb":
84
+ pool.setBackDice = count;
85
+ break;
86
+ case "s":
87
+ pool.setBackDice = count;
88
+ break;
89
+ // w/f = White/Force
90
+ // TODO
91
+ }
92
+ }
93
+ return pool;
94
+ }
95
+ function formatResult(result) {
96
+ const parts = [];
97
+ if (result.summary.successes > 0)
98
+ parts.push(`${result.summary.successes} Success(es)`);
99
+ if (result.summary.failures > 0)
100
+ parts.push(`${result.summary.failures} Failure(s)`);
101
+ if (result.summary.advantages > 0)
102
+ parts.push(`${result.summary.advantages} Advantage(s)`);
103
+ if (result.summary.threats > 0)
104
+ parts.push(`${result.summary.threats} Threat(s)`);
105
+ if (result.summary.triumphs > 0)
106
+ parts.push(`${result.summary.triumphs} Triumph(s)`);
107
+ if (result.summary.despair > 0)
108
+ parts.push(`${result.summary.despair} Despair(s)`);
109
+ return parts.join(", ") || "No effects";
110
+ }
111
+ const main = () => {
112
+ const input = process.argv.slice(2).join(" ");
113
+ if (!input) {
114
+ console.log(`Usage: > swrpg-dice 2y 1g 2p 1r
115
+ - y/pro = Yellow / Proficiency
116
+ - g/a = Green / Ability
117
+ - b/boo = Blue / Boost
118
+ - r/c = Red / Challenge
119
+ - p/diff = Purple / Difficulty
120
+ - blk/k/sb/s = Black / Setback
121
+ `);
122
+ process.exit(1);
123
+ }
124
+ const pool = parseDiceNotation(input);
125
+ const result = (0, dice_1.roll)(pool);
126
+ console.log(formatResult(result));
127
+ };
128
+ if (require.main === module) {
129
+ main();
130
+ }
package/dist/dice.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { DicePool, RollResult } from './types';
1
+ import { DicePool, RollResult } from "./types";
2
2
  export declare const roll: (pool: DicePool) => RollResult;