Skip to content

Commit

Permalink
Fix dice parsing to include any existing modifier. Prevent throwing a…
Browse files Browse the repository at this point in the history
…n error on parsing bad roll. Export some more types.
  • Loading branch information
Tom Wolfe authored and Tom Wolfe committed Oct 4, 2018
1 parent 930ca41 commit c0850a9
Show file tree
Hide file tree
Showing 98 changed files with 5,627 additions and 5,523 deletions.
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Karma Tests",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"url": "http://localhost:9876/debug.html",
// "runtimeArgs": [
// "--headless"
// ],
"pathMapping": {
"/": "${workspaceRoot}",
"/base/": "${workspaceRoot}/"
},
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*",
"webpack:///src/*": "${webRoot}/*",
"webpack:///*": "*",
"webpack:///./~/*": "${webRoot}/node_modules/*",
"meteor://💻app/*": "${webRoot}/*"
}
}
]
}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install dice-typescript
At its simplest, the dice roller is very simple to use. Take the following example:

```typescript
import * as Dice from "dice-typescript";
import { Dice } from "dice-typescript";

const dice = new Dice();
const result = dice.roll("1d20").total;
Expand Down Expand Up @@ -57,7 +57,7 @@ In addition to the ```abs```, ```ceil```, ```floor```, ```round``` and ```sqrt``
```typescript
const customFunctions = new FunctionDefinitionList();
customFunctions["floor"] = (interpreter: DiceInterpreter, functionNode: ExpressionNode, errors: ErrorMessage[]): number => {
return Math.floor(interpreter.evaluate(functionNode.getChild(0), errors));
return Math.floor(interpreter.evaluate(functionNode.getChild(0), errors));
}

const dice = new Dice(customFunctions);
Expand All @@ -71,10 +71,10 @@ By default, the Dice library uses [random-js](https://www.npmjs.com/package/rand

```typescript
export class CustomRandom implements RandomProvider {
numberBetween(min: number, max: number) {
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
numberBetween(min: number, max: number) {
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
}

const dice = new Dice(null, new CustomRandom());
Expand All @@ -89,7 +89,7 @@ The dice rolling syntax is based on the system used by Roll20, a detailed explan
In addition to the above syntax rules, some slightly more complicated variations are available. For example, you can roll a variable number of dice using an expression similar to the following:

```dice
(4d4)d20
(4d4)d20
```

##### Conditional Operators
Expand All @@ -101,7 +101,7 @@ As per the Roll20 syntax, you can use conditional operators, such as in ```4d20>
Sometimes it is necessary to roll complex groups of dice that aren't supported by the basic syntax. For example, rolling a saving throw at disadvantage for 10 creatures. For this, you can use the group repeater modifier, which works like this:

```dice
{2d20kl...10}>=14
{2d20kl...10}>=14
```

The above will roll 10 disadvantaged saving throws, reporting successes for those that break DC14.
Expand All @@ -111,7 +111,7 @@ The above will roll 10 disadvantaged saving throws, reporting successes for thos
Using the allowed syntax, it is possible to request a fractional number of dice to be rolled. Take the following example:

```dice
(2 / 5)d6
(2 / 5)d6
```

In this instance, the number of dice to be rolled will be rounded to the nearest integer (2.5 gets rounded up to 3).
Expand Down
86 changes: 45 additions & 41 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,52 @@ const watching = process.env.npm_lifecycle_script.indexOf("--single-run") === -1
console.log("Watching: " + watching);

module.exports = function (config) {
config.set({
browserNoActivityTimeout: 20000,
frameworks: ["jasmine", "karma-typescript"],
files: [
{ pattern: "spec/**/*.ts" },
{ pattern: "src/**/*.ts" },
],
preprocessors: {
"**/*.ts": ["karma-typescript"],
},
reporters: ["progress", "karma-typescript"],
browsers: ["Chrome"],
plugins: [
"karma-chrome-launcher",
"karma-jasmine",
"karma-typescript"
],
customLaunchers: {
chromeTravisCi: {
base: "Chrome",
flags: ["--no-sandbox"]
}
},
karmaTypescriptConfig: {
coverageOptions: {
instrumentation: true
},
reports: {
lcovonly: {
directory: "coverage",
filename: "lcov.info",
subdirectory: "lcov"
}
}
config.set({
browserNoActivityTimeout: 20000,
frameworks: ["jasmine", "karma-typescript"],
files: [
{ pattern: "spec/**/*.ts" },
{ pattern: "src/**/*.ts" },
],
preprocessors: {
"**/*.ts": ["karma-typescript"],
},
reporters: ["progress", "karma-typescript"],
browsers: ["chromeDebugging"],
plugins: [
"karma-chrome-launcher",
"karma-jasmine",
"karma-typescript"
],
customLaunchers: {
chromeDebugging: {
base: 'Chrome',
flags: [ '--remote-debugging-port=9333' ]
},
chromeTravisCi: {
base: "Chrome",
flags: ["--no-sandbox"]
}
},
karmaTypescriptConfig: {
coverageOptions: {
instrumentation: true
},
reports: {
lcovonly: {
directory: "coverage",
filename: "lcov.info",
subdirectory: "lcov"
}
});

if (watching) {
config.karmaTypescriptConfig.coverageOptions.instrumentation = false;
}
}
});

if (process.env.TRAVIS) {
config.browsers = ["chromeTravisCi"];
}
if (watching) {
config.karmaTypescriptConfig.coverageOptions.instrumentation = false;
}

if (process.env.TRAVIS) {
config.browsers = ["chromeTravisCi"];
}
};
Loading

0 comments on commit c0850a9

Please sign in to comment.