BCDice ported package for JavaScript by Opal.
$ npm install --save bcdice
import BCDice, { Info } from 'bcdice';
import 'bcdice/lib/diceBot/Cthulhu';
/* or CommonJS
const BCDice = require('bcdice').default; // Do not forget ".default"
require('bcdice/lib/diceBot/Cthulhu');
*/
function getInfo(gameType: string): Info | undefined {
return BCDice.infoList.find(info => info.gameType === gameType);
}
interface RollResult {
result: string;
rands: number[][] | null;
}
function roll(command: string, gameType: string): RollResult {
const bcdice = new BCDice();
const [result, rands] = bcdice.roll(command, gameType);
return {
result,
rands,
};
}
console.log(getInfo('Cthulhu'))
console.log(roll('CC', 'Cthulhu'));
import BCDice, { Info } from 'bcdice';
function getInfo(gameType: string): Info | undefined {
return BCDice.infoList.find(info => info.gameType === gameType);
}
interface RollResult {
result: string;
rands: number[][] | null;
}
function roll(command: string, gameType: string): Promise<RollResult? {
const bcdice = new BCDice();
return import(`bcdice/lib/diceBot/${gameType}`).then(() => {
const [result, rands] = bcdice.roll(command, gameType);
return {
result,
rands,
};
});
}
console.log(getInfo('Cthulhu'));
roll('CC', 'Cthulhu').then(result => console.log(result));
$ bundle install
$ npm install
$ npm run build
$ npm test