Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…roller into main
  • Loading branch information
valentine195 committed Nov 1, 2023
2 parents 8e901b6 + ad21d53 commit 5c031cf
Show file tree
Hide file tree
Showing 17 changed files with 1,088 additions and 52 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.1.2"
".": "10.2.0"
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

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.2.0](https://github.com/javalent/dice-roller/compare/10.1.2...10.2.0) (2023-10-27)


### Features

* Enables changing the font of rendered dice ([c16d3c0](https://github.com/javalent/dice-roller/commit/c16d3c07fd71675fd56facaf94045dca51eeecb1))


### Bug Fixes

* **dicetray:** error handling for roll button ([#264](https://github.com/javalent/dice-roller/issues/264)) ([0f2c599](https://github.com/javalent/dice-roller/commit/0f2c599c242b099d7bd3811314cc95486fffca7c))
* Fixes average calculation ([bf87aa8](https://github.com/javalent/dice-roller/commit/bf87aa80565b4e45cbb4c88cc9b89a3c49e82be5))
* **lexer:** handle unary minus operator ([#262](https://github.com/javalent/dice-roller/issues/262)) ([139cbfa](https://github.com/javalent/dice-roller/commit/139cbfa6c7927686a3d2bedda6732c3ce3df7fef))

## [10.1.2](https://github.com/javalent/dice-roller/compare/10.1.1...10.1.2) (2023-10-20)


Expand Down
1 change: 1 addition & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ esbuild
bundle: true,
external: [
"obsidian",
"get-fonts",
"electron",
"codemirror",
"@codemirror/autocomplete",
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.1.2",
"version": "10.2.0",
"minAppVersion": "0.12.15",
"description": "Inline dice rolling for Obsidian.md",
"author": "Jeremy Valentine",
Expand Down
33 changes: 25 additions & 8 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dice-roller",
"version": "10.1.2",
"version": "10.2.0",
"description": "Inline dice rolling for Obsidian.md",
"main": "",
"types": "./@types/index.d.ts",
Expand All @@ -27,6 +27,7 @@
"@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-regular-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@popperjs/core": "^2.11.8",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ interface DiceRollerSettings {
scaler: number;
diceColor: string;
textColor: string;
textFont: string;
showLeafOnStartup: boolean;
customFormulas: string[];

Expand Down Expand Up @@ -201,6 +202,7 @@ export const DEFAULT_SETTINGS: DiceRollerSettings = {
scaler: 1,
diceColor: "#202020",
textColor: "#ffffff",
textFont: "Arial",
showLeafOnStartup: true,
showDice: true,
displayAsEmbed: true,
Expand Down
44 changes: 32 additions & 12 deletions src/parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as moo from "moo";
import DiceRollerPlugin from "src/main";
import { Conditional } from "src/types";
import { Parser } from "./parser";
import copy from "fast-copy";

export const TAG_REGEX =
/(?:\d+[Dd])?#(?:[\p{Letter}\p{Emoji_Presentation}\w/-]+)(?:\|(?:[+-]))?(?:\|(?:[^+-]+))?/u;
Expand Down Expand Up @@ -133,7 +134,7 @@ export default class Lexer {
"^": exponent
});
}
parse(input: string) {
parse(input: string): LexicalToken[] {
const tokens = Array.from(this.lexer.reset(input));
this.lexer.reset();
return this.parser.parse(this.transform(tokens));
Expand All @@ -142,18 +143,37 @@ export default class Lexer {
tokens = tokens.filter((token) => {
return token.type != "WS";
});
let clone: LexicalToken[] = [];
/** If the first token is a negative sign and the second is a dice roller, just make the dice roller negative. */
if (tokens.length >= 2) {
if (
(tokens[0].type === "-" ||
(tokens[0].type === "math" && tokens[0].value === "-")) &&
tokens[1].type === "dice"
) {
tokens[1].value = `-${tokens[1].value}`;
tokens.shift();

let isPlus = (t: moo.Token) =>
t.type === "+" || (t.type === "math" && t.value === "+");
let isMinus = (t: moo.Token) =>
t.type === "-" || (t.type === "math" && t.value === "-");
let isPlusOrMinus = (t: moo.Token) => isPlus(t) || isMinus(t);
let peek = (arr: moo.Token[]) => arr[arr.length - 1];
let replaceTop = (arr: moo.Token[], newTop: moo.Token) =>
arr.splice(arr.length - 1, 1, newTop);

tokens = tokens.reduce((acc, e) => {
if (acc.length == 0) {
acc.push(e);
} else {
let top = peek(acc);

if (isPlusOrMinus(top) && isPlusOrMinus(e)) {
if (isMinus(top) != isMinus(e)) {
// one minus => minus
if (!isMinus(top)) replaceTop(acc, e);
} else if (isMinus(top)) {
top.type = top.type === "math" ? top.type : "+";
top.value = "+";
}
} else {
acc.push(e);
}
}
}
return acc;
}, [] as moo.Token[]);
let clone: LexicalToken[] = [];
for (const token of tokens) {
if (token.type == "condition" && clone.length > 0) {
const previous = clone[clone.length - 1];
Expand Down
44 changes: 27 additions & 17 deletions src/renderer/geometries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ const MATERIAL_OPTIONS = {
shininess: 60,
flatShading: true
};
const DEFAULT_DICE_OPTIONS = {
const DEFAULT_DICE_OPTIONS: DiceOptions = {
diceColor: "#202020",
textColor: "#ffffff"
textColor: "#ffffff",
textFont: "Arial",
};

interface DiceOptions {
diceColor: string;
textColor: string;
textFont: string;
}

export default abstract class DiceGeometry {
body: Body;
chamferGeometry: { vectors: Vector3[]; faces: any[][] };
Expand Down Expand Up @@ -76,7 +84,7 @@ export default abstract class DiceGeometry {
constructor(
public w: number,
public h: number,
public options = {
public options: Partial<DiceOptions> = {
diceColor: "#202020",
textColor: "#aaaaaa"
},
Expand All @@ -86,6 +94,8 @@ export default abstract class DiceGeometry {
...DEFAULT_DICE_OPTIONS,
...options
};

this.fontFace = this.options.textFont;
}
setColor({
diceColor,
Expand Down Expand Up @@ -454,7 +464,7 @@ class D20DiceGeometry extends DiceGeometry {
constructor(
w: number,
h: number,
options = { diceColor: "#171120", textColor: "#FF0000" },
options: Partial<DiceOptions> = { diceColor: "#171120", textColor: "#FF0000" },
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -504,7 +514,7 @@ class D12DiceGeometry extends DiceGeometry {
constructor(
w: number,
h: number,
options = { diceColor: "#7339BE", textColor: "#FFFFFF" },
options: Partial<DiceOptions> = { diceColor: "#7339BE", textColor: "#FFFFFF" },
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -571,7 +581,7 @@ class D10DiceGeometry extends DiceGeometry {
constructor(
w: number,
h: number,
options = { diceColor: "#c74749", textColor: "#FFFFFF" },
options: Partial<DiceOptions> = { diceColor: "#c74749", textColor: "#FFFFFF" },
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -622,7 +632,7 @@ class D100DiceGeometry extends DiceGeometry {
constructor(
w: number,
h: number,
options = { diceColor: "#7a2c2d", textColor: "#FFFFFF" },
options: Partial<DiceOptions> = { diceColor: "#7a2c2d", textColor: "#FFFFFF" },
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -668,7 +678,7 @@ class D8DiceGeometry extends DiceGeometry {
constructor(
w: number,
h: number,
options = { diceColor: "#5eb0c5", textColor: "#FFFFFF" },
options: Partial<DiceOptions> = { diceColor: "#5eb0c5", textColor: "#FFFFFF" },
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -705,7 +715,7 @@ class D6DiceGeometry extends DiceGeometry {
constructor(
w: number,
h: number,
options = { diceColor: "#d68316", textColor: "#FFFFFF" },
options: Partial<DiceOptions> = { diceColor: "#d68316", textColor: "#FFFFFF" },
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -772,7 +782,7 @@ class D4DiceGeometry extends DiceGeometry {
constructor(
w: number,
h: number,
options = { diceColor: "#93b139", textColor: "#FFFFFF" },
options: Partial<DiceOptions> = { diceColor: "#93b139", textColor: "#FFFFFF" },
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -869,7 +879,7 @@ abstract class GenesysD12DiceGeometry extends GenesysDice {
constructor(
w: number,
h: number,
options = DEFAULT_DICE_OPTIONS,
options: Partial<DiceOptions> = DEFAULT_DICE_OPTIONS,
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -921,7 +931,7 @@ export class GenesysProficiencyDiceGeometry extends GenesysD12DiceGeometry {
constructor(
w: number,
h: number,
options = DEFAULT_DICE_OPTIONS,
options: Partial<DiceOptions> = DEFAULT_DICE_OPTIONS,
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -949,7 +959,7 @@ export class GenesysChallengeDiceGeometry extends GenesysD12DiceGeometry {
constructor(
w: number,
h: number,
options = DEFAULT_DICE_OPTIONS,
options: Partial<DiceOptions> = DEFAULT_DICE_OPTIONS,
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -991,7 +1001,7 @@ export class GenesysAbilityDiceGeometry extends GenesysD8DiceGeometry {
constructor(
w: number,
h: number,
options = DEFAULT_DICE_OPTIONS,
options: Partial<DiceOptions> = DEFAULT_DICE_OPTIONS,
scaler: number
) {
super(w, h, options, scaler);
Expand All @@ -1003,7 +1013,7 @@ export class GenesysDifficultyDiceGeometry extends GenesysD8DiceGeometry {
constructor(
w: number,
h: number,
options = DEFAULT_DICE_OPTIONS,
options: Partial<DiceOptions> = DEFAULT_DICE_OPTIONS,
scaler: number
) {
super(w, h, options, scaler);
Expand Down Expand Up @@ -1045,7 +1055,7 @@ export class GenesysBoostDiceGeometry extends GenesysD6DiceGeometry {
constructor(
w: number,
h: number,
options = DEFAULT_DICE_OPTIONS,
options: Partial<DiceOptions> = DEFAULT_DICE_OPTIONS,
scaler: number
) {
super(w, h, options, scaler);
Expand All @@ -1057,7 +1067,7 @@ export class GenesysSetbackDiceGeometry extends GenesysD6DiceGeometry {
constructor(
w: number,
h: number,
options = DEFAULT_DICE_OPTIONS,
options: Partial<DiceOptions> = DEFAULT_DICE_OPTIONS,
scaler: number
) {
super(w, h, options, scaler);
Expand Down
Loading

0 comments on commit 5c031cf

Please sign in to comment.