Skip to content

🎲 Package for rolling some bones 🎲

License

Notifications You must be signed in to change notification settings

damienbullis/dice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dice


Top Language Downloads Version

codecov Build


🎲 Comes with all the basic polyhedral dice 🎲

🎲 Simple interface for creating custom or 'funky' dice 🎲

🎲 Pools is a simple helper for rolling multiple dice 🎲




Install

npm install @damienbullis/dice
# or
yarn add @damienbullis/dice
# or
pnpm add @damienbullis/dice

Usage

Basic Usage

To roll dice, you can use the Dice function.


import { Dice } from "@damienbullis/dice";

// Create some dice
const d4 = Dice(4);
const d6 = Dice(6);
const d8 = Dice(8);

d4(); // rolls a single d4
// returns [ 2 ]

d6(2); // rolls two d6's
// returns [ 3, 6 ]

d8(3); // rolls three d8's
// returns [ 8, 2, 2 ]

Using Custom Dice

If you have a need for dice with symbols, multiple values per facing, or to change the probability curve.


import { Dice } from "@damienbullis/dice";

// Create a custom die
const SuccessDie = Dice([
  "Success+Crit",
  "Success",
  "Success",
  "Failure+Crit",
  "Failure",
  "Failure",
]);

SuccessDie(); // rolls the die once
// returns [ "Failure+Crit" ]

Using a Pool

To roll a pool of dice, you can use the Pool function in conjunction with the Dice function.


import { Dice, Pool } from "@damienbullis/dice";

const d6 = Dice(6);
const d20 = Dice(20);

// Create a pool of dice
const pool = Pool(d6, d20);

pool(); // rolls the pool once
// returns [ [ 3, 20 ] ]
pool(2); // rolls the pool twice
// returns [ [ 6, 12 ], [ 1, 18 ] ]



Roadmap

  • Add error handling
  • Add tests
  • Publish to NPM
  • Better Types*
  • Custom Weights for Dice*
  • Custom Random Number Generator's*

*Not sure about these yet...


Contributing

Contributions are welcome! Please open an issue or PR.


License

MIT © damienbullis