Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…roller into main
  • Loading branch information
valentine195 committed Apr 16, 2024
2 parents 8a829a6 + 697cee6 commit 16d4144
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "10.4.6"
".": "10.5.0"
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [10.5.0](https://github.com/javalent/dice-roller/compare/10.4.6...10.5.0) (2024-04-15)


### Features

* New min/max syntax: `dice: 1d[5-10]` ([fc7ee80](https://github.com/javalent/dice-roller/commit/fc7ee80d3eacd2e95711d9c1ca7501a3bc58373a))

## [10.4.6](https://github.com/javalent/dice-roller/compare/10.4.5...10.4.6) (2024-03-19)


Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-dice-roller",
"name": "Dice Roller",
"version": "10.4.6",
"version": "10.5.0",
"minAppVersion": "0.12.15",
"description": "Inline dice rolling for Obsidian.md",
"author": "Jeremy Valentine",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dice-roller",
"version": "10.4.6",
"version": "10.5.0",
"description": "Inline dice rolling for Obsidian.md",
"main": "",
"types": "./@types/index.d.ts",
Expand Down
9 changes: 5 additions & 4 deletions src/parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const LINE_REGEX =
/(?:\d+[Dd])?(?:\[.*\]\(|\[\[)(?:.+)(?:\)|\]\])\|line/u;
export const MATH_REGEX = /[\(\^\+\-\*\/\)]/u;
export const OMITTED_REGEX =
/(?:\d+|\b)[Dd](?:%|F|-?\d+|\[\d+(?:[ \t]*,[ \t]*\d+)+\]|\b)/u;
/(?:\d+|\b)[Dd](?:%|F|-?\d+|\[\d+(?:[ \t]*[,-][ \t]*\d+)+\]|\b)/u;

export const CONDITIONAL_REGEX =
/(?:=|=!|<|>|<=|>=|=<|=>|-=|=-)(?:\d+(?:[Dd](?:%|F|-?\d+|\[\d+(?:[ \t]*,[ \t]*\d+)+\]|\b))?)/u;
/(?:=|=!|<|>|<=|>=|=<|=>|-=|=-)(?:\d+(?:[Dd](?:%|F|-?\d+|\[\d+(?:[ \t]*[,-][ \t]*\d+)+\]|\b))?)/u;

export interface LexicalToken extends Partial<moo.Token> {
conditions?: Conditional[];
Expand Down Expand Up @@ -71,8 +71,9 @@ export default class Lexer {
roll = this.defaultRoll,
faces = this.defaultFace
} = match.match(
/(?<roll>\d+)?[Dd](?<faces>%|F|-?\d+|\[\d+(?:[ \t]*,[ \t]*\d+)+\])?/
/(?<roll>\d+)?[Dd](?<faces>%|F|-?\d+|\[\d+(?:[ \t]*[,-][ \t]*\d+)+\])?/
).groups;
console.log("🚀 ~ file: lexer.ts:73 ~ faces:", faces);
return `${roll}d${faces}`;
}
},
Expand Down Expand Up @@ -180,7 +181,7 @@ export default class Lexer {
if (!previous.conditions) previous.conditions = [];
const [_, operator, comparer] =
token.value.match(
/(?<operator>=|=!|<|>|<=|>=|=<|=>|-=|=-)(?<comparer>\d+(?:[Dd](?:%|F|-?\d+|\[\d+(?:[ \t]*,[ \t]*\d+)+\]|\b))?)/
/(?<operator>=|=!|<|>|<=|>=|=<|=>|-=|=-)(?<comparer>\d+(?:[Dd](?:%|F|-?\d+|\[\d+(?:[ \t]*[,-][ \t]*\d+)+\]|\b))?)/
) ?? [];
const lexemes = this.parse(comparer);
previous.conditions.push({
Expand Down
13 changes: 12 additions & 1 deletion src/roller/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ export class DiceRoller {
this.modifiersAllowed = false;
}
let [, rolls, maxStr = "1"] = this.dice.match(
/(\-?\d+)[dD](%|F|-?\d+|\[\d+(?:[ \t]*,[ \t]*\d+)+\])/
/(\-?\d+)[dD](%|F|-?\d+|\[\d+(?:[ \t]*[,-][ \t]*\d+)+\])/
) || [, 1, "1"];

rolls = Number(rolls);

this.multiplier = rolls < 0 ? -1 : 1;
let min = 1;
let max = isNaN(Number(maxStr)) ? 1 : Number(maxStr);

this.rolls = Math.abs(Number(rolls)) || 1;

//ugly af
Expand All @@ -57,6 +58,15 @@ export class DiceRoller {
.replace(/[\[\]\s]/g, "")
.split(",")
.map((v) => Number(v));
} else if (/\[\d+(?:[ \t]*-[ \t]*\d+)+\]/.test(maxStr)) {
[min, max] = maxStr
.replace(/[\[\]\s]/g, "")
.split("-")
.map((v) => Number(v));
this.possibilities = Array.from(
{ length: max - min },
(_, i) => i + min
);
} else if (maxStr === "F") {
this.possibilities = [-1, 0, 1];
this.fudge = true;
Expand Down Expand Up @@ -1356,6 +1366,7 @@ export class StackRoller extends GenericRoller<number> {
dice
);
}

index++;
break;
}
Expand Down

0 comments on commit 16d4144

Please sign in to comment.