From b0ba90596584b12a921e21148fbc64ed22541355 Mon Sep 17 00:00:00 2001 From: Jeremy Valentine <38669521+valentine195@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:23:44 -0500 Subject: [PATCH] feat: Genesys/Star Wars narrative dice are now supported and renderable. (#354) * chore(wip): initial impl of narrative dice * Narrative die (#334) * Updated to SWRPG Font for ease of testing * Updated Geometries to Match Roller order (Assuming asc order for labels) * Populated remaining subclasses & adjusted math logic (non-cancelling triumph/despairs). * fix: Adds force dice to the Narrative dice set * fix: Expands possible ways to specify narrative dice, allows spaces, allows number amounts * fix: Adds new RenderableRoller abstract class * fix: Improves behavior when canceling an in-process render * fix: Updates tests to new responses * Added Settings/Functionality for Symbols/Text & Handling Genesys/SWRPG symbol options. (#335) * fix: Fixes imports for file reorg * Narrative die (#344) * Added Settings/Functionality for Symbols/Text & Handling Genesys/SWRPG symbol options. * Updated Lexer to handle full abbreviation lexeme. * Updated Readme for Narrative Dice overview. * Updated Genesys font & ForceRoller logic. (#348) * Added Settings/Functionality for Symbols/Text & Handling Genesys/SWRPG symbol options. * Updated Lexer to handle full abbreviation lexeme. * Updated Readme for Narrative Dice overview. * Updated Genesys font to match EotE mappings. * Updated Force Dice logic as standalone light/dark results. --------- Co-authored-by: Josh <110574859+source-toad@users.noreply.github.com> --- README.md | 18 ++ src/api/api.ts | 16 +- src/lexer/lexer.ts | 21 ++ src/main.ts | 3 +- src/renderer/font.css | 9 +- src/renderer/geometries.ts | 156 +++++++--- src/renderer/renderer.ts | 115 ++++++- src/renderer/shapes.ts | 188 ++++++++++- src/rollers/dice/dice.ts | 19 +- src/rollers/dice/narrative.ts | 549 +++++++++++++++++++++++++++++++++ src/rollers/dice/renderable.ts | 27 +- src/rollers/dice/stack.ts | 137 ++++---- src/rollers/line/line.ts | 2 +- src/rollers/roller.ts | 86 +++++- src/rollers/section/section.ts | 2 +- src/rollers/table/table.ts | 19 +- src/rollers/tag/tag.ts | 2 +- src/settings/settings.const.ts | 2 + src/settings/settings.ts | 37 +++ src/settings/settings.types.ts | 2 + src/styles.css | 1 + src/types/obsidian-ext.d.ts | 3 +- src/view/view.ts | 11 +- test/parser/lexer.test.ts | 101 +++--- test/util.ts | 2 + 25 files changed, 1296 insertions(+), 232 deletions(-) create mode 100644 src/rollers/dice/narrative.ts diff --git a/README.md b/README.md index da7d7e3..e41244c 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,24 @@ Use `` `dice: XdF` `` to roll a fudge/fate dice. See [here]( Note: If any abbreviation exclusive letters are used (A,C,D), `P` will preference Proficiency. + ## Dice Modifiers The parser supports several modifiers. If a die has been modified, it will display _how_ it has been modified in the tooltip. diff --git a/src/api/api.ts b/src/api/api.ts index 22f34a4..000506d 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -16,6 +16,7 @@ import { TableRoller } from "src/rollers/table/table"; import { SectionRoller } from "src/rollers/section/section"; import { DataViewRoller, TagRoller } from "src/rollers/tag/tag"; import { LineRoller } from "src/rollers/line/line"; +import { NarrativeStackRoller } from "src/rollers/dice/narrative"; export * from "../types/api"; @@ -26,7 +27,8 @@ export { type DataViewRoller, type TagRoller, type LineRoller, - type ArrayRoller + type ArrayRoller, + type NarrativeStackRoller }; export interface RollerOptions { @@ -98,6 +100,9 @@ class APIInstance { if (lexemes.some(({ type }) => type === "line")) { return "line"; } + if (lexemes.some(({ type }) => type === "narrative")) { + return "narrative"; + } return "dice"; } getParametersForRoller( @@ -235,6 +240,15 @@ class APIInstance { const type = this.#getTypeFromLexemes(lexemes); switch (type) { + case "narrative": { + return new NarrativeStackRoller( + this.data, + content, + lexemes, + this.app, + position + ); + } case "dice": { const roller = new StackRoller( this.data, diff --git a/src/lexer/lexer.ts b/src/lexer/lexer.ts index 3de6514..1d87dd5 100644 --- a/src/lexer/lexer.ts +++ b/src/lexer/lexer.ts @@ -164,6 +164,27 @@ class LexerClass { value: this.clampInfinite }, u: /u/u, + narrative: { + match: /^(?:\d*(?:[GgYyBbRrPpSsWw]|[AaPpDdCcBbSsFf]|pro|boo|blk|k|sb|diff))(?: ?\d*(?:[GgYyBbRrPpSsWw]|[AaPpDdCcBbSsFf]|pro|boo|blk|k|sb|diff))+$/u, + value: (match) => { + const isAbbr = /[AaCcDd]/.test(match); + return match + .toLowerCase() + .replace(/pro/g, "y") + .replace(/diff/g, "p") + .replace(/(blk|k|sb)/g, "s") + .replace(/boo/g, "b") + .replace(/p/g, isAbbr ? "y" : "p") + .replace(/a/g, "g") + .replace(/d/g, "p") + .replace(/c/g, "r") + .replace(/f/g, "w") + .replace(/ /g, "") + .replace(/(\d+)(\w)/g, (_, num: string, char: string) => + char.repeat(Number(num)) + ) + } + }, stunt: /1[Dd]S/u, "%": /\d+[Dd]\d+%/u, fudge: { diff --git a/src/main.ts b/src/main.ts index 92fc249..94581e1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,6 +30,7 @@ export default class DiceRollerPlugin extends Plugin { return { diceColor: this.data.diceColor, textColor: this.data.textColor, + narrativeSymbolSet: this.data.narrativeSymbolSet, colorfulDice: this.data.colorfulDice, scaler: this.data.scaler, renderTime: this.data.renderTime, @@ -68,7 +69,7 @@ export default class DiceRollerPlugin extends Plugin { return; } await roller.roll(); - if (!roller.dice.length) { + if (!roller.children.length) { new Notice("Invalid formula."); return; } diff --git a/src/renderer/font.css b/src/renderer/font.css index df9a601..6347c88 100644 --- a/src/renderer/font.css +++ b/src/renderer/font.css @@ -1,4 +1,9 @@ @font-face { - font-family: "DICE_ROLLER_GENESYS_FONT"; - src: url("src/assets/genesysglyphsanddice.woff"); + font-family: "SWRPG"; + src: url(data:font/ttf;base64,T1RUTwAKAIAAAwAgQ0ZGIG0r1Q8AAAT4AAAKEEdTVUIAAQAAAAAP4AAAAApPUy8yaB1opwAAARAAAABgY21hcARGBvEAAAOcAAABOmhlYWT9s5gkAAAArAAAADZoaGVhCHcEHwAAAOQAAAAkaG10eLAsA5UAAA8IAAAA2G1heHAANlAAAAABCAAAAAZuYW1lNobiaQAAAXAAAAIscG9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bgBkAEQAaQBjAGUAAEdlbmVzeXNHbHlwaHNBbmREaWNlAABGAG8AbgB0ACAAZwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABGAG8AbgB0AEYAbwByAGcAZQAuACAAQgBhAHMAZQBkACAAbwBuACAAdABoAGUAIABHAGUAbgBlAHMAeQBzACAAZwBsAHkAcABoACAAZgBvAG4AeQAgAGIAeQAgAGwAZQBjAHUAZABhAHMAIABmAHIAbwBtACAAdABoAGUAIABGAEYAIABGAG8AcgB1AG0AcwAuAABGb250IGdlbmVyYXRlZCBieSBGb250Rm9yZ2UuIEJhc2VkIG9uIHRoZSBHZW5lc3lzIGdseXBoIGZvbnkgYnkgbGVjdWRhcyBmcm9tIHRoZSBGRiBGb3J1bXMuAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABcAAAABAQIBAwADAC0ALgAvAD0ARABGAEkASgBNAE4ATwBTAFYAVwBbAFwAXQEEB3VuaTAwMEQHdW5pMDAwMQZnbHlwaDEAAAAAAf//AAIAAQAAAAwAAAAWAAAAAgABAAEAFgABAAQAAAACAAAAAAAAAAEAAAAA39bLMQAAAADVt83vAAAAAOMuEmk=); } diff --git a/src/renderer/geometries.ts b/src/renderer/geometries.ts index 1acefc2..5a80976 100644 --- a/src/renderer/geometries.ts +++ b/src/renderer/geometries.ts @@ -27,13 +27,15 @@ const MATERIAL_OPTIONS = { const DEFAULT_DICE_OPTIONS: DiceOptions = { diceColor: "#202020", textColor: "#ffffff", - textFont: "Arial" + textFont: "Arial", + narrativeSymbolSet: "Genesys" }; interface DiceOptions { diceColor: string; textColor: string; textFont: string; + narrativeSymbolSet: string; } export default abstract class DiceGeometry { @@ -88,7 +90,8 @@ export default abstract class DiceGeometry { public h: number, public options: Partial = { diceColor: "#202020", - textColor: "#aaaaaa" + textColor: "#aaaaaa", + narrativeSymbolSet: "Genesys" }, public scaler: number ) { @@ -101,10 +104,12 @@ export default abstract class DiceGeometry { } setColor({ diceColor, - textColor + textColor, + narrativeSymbolSet }: { diceColor?: string; textColor?: string; + narrativeSymbolSet?: string; }) { if (diceColor) { this.options.diceColor = diceColor; @@ -112,6 +117,9 @@ export default abstract class DiceGeometry { if (textColor) { this.options.textColor = textColor; } + if (narrativeSymbolSet) { + this.options.narrativeSymbolSet = narrativeSymbolSet; + } } get radius() { return this.scale * this.scaleFactor * (this.scaler ?? 1); @@ -122,6 +130,9 @@ export default abstract class DiceGeometry { get textColor() { return this.options.textColor; } + get narrativeSymbolSet() { + return this.options.narrativeSymbolSet; + } get buffer() { return this.geometry.geometry; } @@ -839,22 +850,8 @@ class D4DiceGeometry extends DiceGeometry { } abstract class GenesysDice extends DiceGeometry { - fontFace: string = "DICE_ROLLER_GENESYS_FONT"; - - /* create() { - if (!document.fonts.check(`12px '${this.fontFace}'`)) { - const font = new FontFace( - this.fontFace, - `url(data:font/ttf;base64,AAEAAAAQAQAABAAARkZUTY5uVlsAACKQAAAAHEdERUYAJwAfAAAicAAAAB5PUy8yV5dgWQAAAYgAAABgY21hcDS7choAAAJMAAABjmN2dCD/6f/pAAAG8AAAABRmcGdtdCgNNAAAA9wAAALmZ2FzcAAAABAAACJoAAAACGdseWa0MxXZAAAHOAAAF2RoZWFkEoHbCQAAAQwAAAA2aGhlYQSwA/IAAAFEAAAAJGhtdHg1jvZhAAAB6AAAAGRsb2NhQwxHEAAABwQAAAA0bWF4cAI4AtMAAAFoAAAAIG5hbWWXsyolAAAenAAAA2Bwb3N06h3fcgAAIfwAAABrcHJlcJqapK0AAAbEAAAALAABAAAAAQAAkw85CF8PPPUAHwQAAAAAANW3ze8AAAAA3OnI7vy9/6gD8AOHAAAACAACAAAAAAAAAAEAAAPA/8AAQAQq/L3/7gPwAAEAAAAAAAAAAAAAAAAAAAAZAAEAAAAZASUACgAAAAAAAgAAAAAAFAAAAgABrAAAAAAABALVAZAABQAAApkCzAAAAI8CmQLMAAAB6wAzAQkAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAUGZFZABAA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AT/8cCtQASABgAF7gACisAugAVAA0ADSu6AAQAFwANKzAxARM2MyEyFhcTFgcDBiMhIicDJjMTIRMDIfzGsAoSAWAKDQWwCQmwChL+oBIKsAlKnQE8nZ3+xAF0ATEQCwX+zxAQ/s8QEAExEP7vAREBEQAAAAIAUQAxA7ADGAADAAkALbgACisAugAAAAEADSu6AAYAAQAAERI5ugAHAAEAABESOboACAABAAAREjkwMQkEHwELATcCAQGv/lH+UAGwIr7g4b4DGP0ZART+7AFcFHkBjf5zeQAIAD3/3APwA20AdwCkAMAA5gEFAR0BIAEkAay4AAorALoAgQCTAA0rugDPAN0ADSu6AAYA3QDPERI5uACBELgAhNC4AIQvuADPELgA0tC4ANIvuADdELgA4dC4AOEvAboAmAChAA0rugBTAA4ADSu6ACoApQANK7gAUxC4AE7QuABOL7oABgChAE4REjm6AAwADgBTERI5ugAXAA4AUxESOboAIAAOAFMREjlBGwAGACoAFgAqACYAKgA2ACoARgAqAFYAKgBmACoAdgAqAIYAKgCWACoApgAqALYAKgDGACoADV1BBQDVACoA5QAqAAJduAAOELgANtC4ADYvuAAOELgAONC4AFMQuABL0LgASy+6AH0AoQBOERI5ugCGAA4AUxESOUEbAAYAmAAWAJgAJgCYADYAmABGAJgAVgCYAGYAmAB2AJgAhgCYAJYAmACmAJgAtgCYAMYAmAANXUEFANUAmADlAJgAAl26AJsAoQBOERI5uAChELgApNC4AKQvuAClELgAwdC4AMEvuAClELgAxNC4AMQvuAAqELgA2NC4AKUQuAD73LgA99C4APcvugD9AKUAKhESOboBHgClACoREjkwMSUzMjc+ATceARceARcmNTQ2Nz4BNz4BNwcjIiYvATQmNRUOAQcOAQcOASMGJicuASc+ATc+ATc0NzQzPgEzNjMyFjMWMhceARceARcWFB0BFAYdARQWHwQOAQcuAScuAScuAzEuATUmJy4BJy4BJy4DATc+AT8BFz4BMzIWOwE3Fx4BHwEPATQuAicjIg4CBwYWFy8BNy4BNzQWNRc2MzIeAhcWBg8BIiYrASciJiMuAScuAScmNh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EYARgAgAEYAbwByAHUAbQBzAC4AAEZvbnQgZ2VuZXJhdGVkIGJ5IEZvbnRGb3JnZS4gQmFzZWQgb24gdGhlIEdlbmVzeXMgZ2x5cGggZm9ueSBieSBsZWN1ZGFzIGZyb20gdGhlIEZGIEZvcnVtcy4AAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQAAAAEBAgEDAAMALQAuAC8ARABGAEcASQBKAEsATQBOAE8AUwBWAFcAWQBaAFsAXAEEB3VuaTAwMEQHdW5pMDAwMQZnbHlwaDEAAAEAAf//AA8AAQAAAAwAAAAWAAAAAgABAAEAGAABAAQAAAACAAAAAAAAAAEAAAAA28y/fQAAAADVt83vAAAAANzpyO4=)` - ); - //@ts-ignore - document.fonts.add(font); - console.log(document.fonts.check(`12px '${this.fontFace}'`)); - } - return super.create(); - } */ + fontFace = this.narrativeSymbolSet } - abstract class GenesysD12DiceGeometry extends GenesysDice { mass = 350; sides = 12; @@ -914,22 +911,49 @@ abstract class GenesysD12DiceGeometry extends GenesysDice { } } +export class GenesysForceDiceGeometry extends GenesysD12DiceGeometry { + labels = [ + "", + "", + "z", //Moved Blank to top as a 1 roll. + "z", //Success + "z", //Success + "z", //Success Success + "z", //Success Success + "z", //Advantage + "z\nz", //Success Advantage + "Z", //Success Advantage + "Z", //Success Advantage + "Z\nZ", //Advantage Advantage + "Z\nZ", //Advantage Advantage + "Z\nZ", //Advantage Advantage + ]; + constructor( + w: number, + h: number, + options: Partial = DEFAULT_DICE_OPTIONS, + scaler: number + ) { + super(w, h, options, scaler); + this.setColor({ diceColor: "white", textColor: "#000000" }); + } +} export class GenesysProficiencyDiceGeometry extends GenesysD12DiceGeometry { labels = [ "", "", - "a\na", - "a", - "a\na", - "x", - "s", - "s\na", - "s", - "s\na", - "s\ns", - "s\na", - "s\ns", - "" + "", //Moved Blank to top as a 1 roll. + "s", //Success + "s", //Success + "s\ns", //Success Success + "s\ns", //Success Success + "a", //Advantage + "s\na", //Success Advantage + "s\na", //Success Advantage + "s\na", //Success Advantage + "a\na", //Advantage Advantage + "a\na", //Advantage Advantage + "x", //Triumph ]; constructor( w: number, @@ -946,18 +970,18 @@ export class GenesysChallengeDiceGeometry extends GenesysD12DiceGeometry { labels = [ "", "", - "t\nt", - "t", - "t\nt", - "t", - "t\nf", - "f", - "t\nf", - "f", - "f\nf", - "y", - "f\nf", - "" + "", //Moved blank to roll of 1. + "f", //Fail + "f", //Fail + "f\nf", //Fail Fail + "f\nf", //Fail Fail + "t", //Threat + "t", //Threat + "t\nf", //Threat Fail + "t\nf", //Threat Fail + "t\nt", //Threat Threat + "t\nt", //Threat Threat + "y", //Despair ]; constructor( w: number, @@ -1000,7 +1024,18 @@ abstract class GenesysD8DiceGeometry extends GenesysDice { } export class GenesysAbilityDiceGeometry extends GenesysD8DiceGeometry { - labels = ["", "", "s", "a", "s\na", "s\ns", "a", "s", "a\na", ""]; + labels = [ + "", + "", + "", //Blank on 1 + "s", //Success + "s", //Success + "s\ns", //Success Success + "a", //Adv + "a", //Adv + "s\na", //Success Advantage + "a\na", //Adv Adv + ]; constructor( w: number, h: number, @@ -1012,7 +1047,18 @@ export class GenesysAbilityDiceGeometry extends GenesysD8DiceGeometry { } } export class GenesysDifficultyDiceGeometry extends GenesysD8DiceGeometry { - labels = ["", "", "t", "f", "f\nt", "t", "", "t\nt", "f\nf", "t", ""]; + labels = [ + "", + "", + "", //Blank on 1 + "f", //Fail + "f\nf", //Fail Fail + "t", //Threat + "t", //Threat + "t", //Threat + "t\nt", //Threat Threat + "f\nt", //Fail Threat + ]; constructor( w: number, h: number, @@ -1054,7 +1100,16 @@ class GenesysD6DiceGeometry extends GenesysDice { } export class GenesysBoostDiceGeometry extends GenesysD6DiceGeometry { - labels = ["", "", "", "", "s", "s \n a", "a \n a", "a", "", ""]; + labels = [ + "", + "", + "", //Blank on 1 + "", //Blank on 2 + "a\na", //Adv Adv + "a", //Adv + "s\na", //Success Adv + "s", //Success + ]; constructor( w: number, h: number, @@ -1066,7 +1121,16 @@ export class GenesysBoostDiceGeometry extends GenesysD6DiceGeometry { } } export class GenesysSetbackDiceGeometry extends GenesysD6DiceGeometry { - labels = ["", "", "", "t", "f", "", ""]; + labels = [ + "", + "", + "", //Blank on 1 + "", //Blank on 2 + "f", //Fail + "f", //Fail + "t", //Threat + "t", //Threat + ]; constructor( w: number, h: number, diff --git a/src/renderer/renderer.ts b/src/renderer/renderer.ts index ce44912..0244761 100644 --- a/src/renderer/renderer.ts +++ b/src/renderer/renderer.ts @@ -15,6 +15,7 @@ import DiceGeometry, { GenesysBoostDiceGeometry, GenesysChallengeDiceGeometry, GenesysDifficultyDiceGeometry, + GenesysForceDiceGeometry, GenesysProficiencyDiceGeometry, GenesysSetbackDiceGeometry, StuntDiceGeometry @@ -27,7 +28,15 @@ import { D6Dice, D8Dice, D12Dice, - D20Dice + D20Dice, + D100Dice, + BoostDice, + ChallengeDice, + ProficiencyDice, + DifficultyDice, + AbilityDice, + SetbackDice, + ForceDice } from "./shapes"; import { @@ -65,6 +74,7 @@ export type RendererData = { scaler: number; renderTime: number; textFont: string; + narrativeSymbolSet: string; }; class DiceRendererClass extends Component { @@ -120,7 +130,8 @@ class DiceRendererClass extends Component { textColor: this.data.textColor, colorfulDice: this.data.colorfulDice, scaler: this.data.scaler, - textFont: this.data.textFont + textFont: this.data.textFont, + narrativeSymbolSet: this.data.narrativeSymbolSet }); } else { this.factory.width = this.WIDTH; @@ -186,7 +197,6 @@ class DiceRendererClass extends Component { } onunload() { - this.stop(); this.loaded = false; cancelAnimationFrame(this.animation); @@ -210,7 +220,7 @@ class DiceRendererClass extends Component { start() { if (this.#animating) { - this.unload(); + this.stop(); } if (!this.loaded) { this.load(); @@ -449,7 +459,7 @@ class DiceRendererClass extends Component { if (!this.data.renderTime) { const renderer = this; function unrender() { - renderer.unload(); + renderer.stop(); document.body.removeEventListener( "click", unrender @@ -623,6 +633,7 @@ class DiceFactory extends Component { const diceColor = this.options.diceColor; const textColor = this.options.textColor; const textFont = this.options.textFont; + const narrativeSymbolSet = this.options.narrativeSymbolSet; // If we want colorful dice then just use the default colors in the geometry if (this.options.colorfulDice) { @@ -631,7 +642,8 @@ class DiceFactory extends Component { return { diceColor, - textFont + textFont, + narrativeSymbolSet }; } constructor( @@ -756,19 +768,94 @@ class DiceFactory extends Component { } case RenderTypes.D100: { dice.push( - new D10Dice( + new D100Dice( this.width, this.height, this.clone("d100"), - vector, - true + vector ), new D10Dice( this.width, this.height, this.clone("d10"), - vector, - true + vector + ) + ); + break; + } + case RenderTypes.BOOST: { + dice.push( + new BoostDice( + this.width, + this.height, + this.clone("boost"), + vector + ) + ); + break; + } + case RenderTypes.SETBACK: { + dice.push( + new SetbackDice( + this.width, + this.height, + this.clone("setback"), + vector + ) + ); + break; + } + case RenderTypes.ABILITY: { + dice.push( + new AbilityDice( + this.width, + this.height, + this.clone("ability"), + vector + ) + ); + break; + } + case RenderTypes.DIFFICULTY: { + dice.push( + new DifficultyDice( + this.width, + this.height, + this.clone("difficulty"), + vector + ) + ); + break; + } + case RenderTypes.FORCE: { + dice.push( + new ForceDice( + this.width, + this.height, + this.clone("force"), + vector + ) + ); + break; + } + case RenderTypes.PROFICIENCY: { + dice.push( + new ProficiencyDice( + this.width, + this.height, + this.clone("proficiency"), + vector + ) + ); + break; + } + case RenderTypes.CHALLENGE: { + dice.push( + new ChallengeDice( + this.width, + this.height, + this.clone("challenge"), + vector ) ); break; @@ -880,6 +967,12 @@ class DiceFactory extends Component { this.colors, this.options.scaler ).create(); + this.dice.force = new GenesysForceDiceGeometry( + this.width, + this.height, + this.colors, + this.options.scaler + ).create(); this.dice.setback = new GenesysSetbackDiceGeometry( this.width, this.height, diff --git a/src/renderer/shapes.ts b/src/renderer/shapes.ts index 2f99c9a..298df4e 100644 --- a/src/renderer/shapes.ts +++ b/src/renderer/shapes.ts @@ -6,6 +6,7 @@ import { type Material, type Quaternion as ThreeQuaternion } from "three"; +import { RenderTypes } from "src/rollers/dice/renderable"; interface DiceVector { pos: { x: number; y: number; z: number }; @@ -44,6 +45,7 @@ export abstract class DiceShape { abstract inertia: number; body: Body; geometry: Mesh; + values: number[] = []; stopped: boolean | number = false; iterations: number = 0; @@ -153,6 +155,7 @@ export abstract class DiceShape { } } let matindex = closest_face.materialIndex - 1; + if (this.sides == 10 && matindex == 0) matindex = 10; return this.data.values?.[matindex] ?? matindex; } @@ -290,6 +293,54 @@ export class D12Dice extends DiceShape { this.create(); } } +export class ProficiencyDice extends DiceShape { + sides = 12; + inertia = 8; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class ForceDice extends DiceShape { + sides = 12; + inertia = 8; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class ChallengeDice extends DiceShape { + sides = 12; + inertia = 8; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} export class D10Dice extends DiceShape { sides = 10; @@ -298,8 +349,23 @@ export class D10Dice extends DiceShape { public w: number, public h: number, public data: { geometry: Mesh; body: Body }, - vector?: { x: number; y: number }, - public isPercentile: boolean = false + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class D100Dice extends DiceShape { + sides = 10; + inertia = 9; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } ) { super(w, h, data); if (vector) { @@ -325,6 +391,54 @@ export class D8Dice extends DiceShape { this.create(); } } +export class AbilityDice extends DiceShape { + sides = 8; + inertia = 10; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class DifficultyDice extends DiceShape { + sides = 8; + inertia = 10; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class Dice extends DiceShape { + sides = 8; + inertia = 10; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} export class D6Dice extends DiceShape { sides = 6; @@ -332,11 +446,71 @@ export class D6Dice extends DiceShape { constructor( public w: number, public h: number, - public data: { - geometry: Mesh; - body: Body; - values?: number[]; - }, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class BoostDice extends DiceShape { + sides = 6; + inertia = 13; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class SetbackDice extends DiceShape { + sides = 6; + inertia = 13; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class StuntDice extends DiceShape { + sides = 6; + inertia = 13; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, + vector?: { x: number; y: number } + ) { + super(w, h, data); + if (vector) { + this.vector = this.generateVector(vector); + } + this.create(); + } +} +export class FudgeDice extends DiceShape { + sides = 6; + inertia = 13; + constructor( + public w: number, + public h: number, + public data: { geometry: Mesh; body: Body }, vector?: { x: number; y: number } ) { super(w, h, data); diff --git a/src/rollers/dice/dice.ts b/src/rollers/dice/dice.ts index 2bb6307..326fbc9 100644 --- a/src/rollers/dice/dice.ts +++ b/src/rollers/dice/dice.ts @@ -32,7 +32,7 @@ type ModifierType = "sort" | "kh" | "kl" | "!" | "!!" | "r" | "u"; export class DiceRoller implements RenderableDice { getType() { - return `${this.faces.max}` as RenderTypes; + return `D${this.faces.max}` as RenderTypes; } constructor( @@ -484,7 +484,13 @@ export class DiceRoller implements RenderableDice { const promises = []; for (let index = 0; index < this.rolls; index++) { promises.push( - new Promise(async (resolve) => { + new Promise(async (resolve, reject) => { + this.#controller?.signal.addEventListener( + "abort", + () => { + reject(); + } + ); const value = await this.getValue( this.getShapes(index) ); @@ -493,11 +499,14 @@ export class DiceRoller implements RenderableDice { }) ); } - await Promise.all(promises); + try { + await Promise.all(promises); + } catch (e) {} } return results; } + applyConditions() { for (const result of this.results.values()) { const negate = this.conditions.find( @@ -670,8 +679,10 @@ export class DiceRoller implements RenderableDice { getGeometries() { return [...this.shapes.values()].flat(); } - async render(): Promise { + #controller: AbortController; + async render(abortController: AbortController): Promise { this.shouldRender = true; + this.#controller = abortController; await this.roll(); this.shouldRender = false; } diff --git a/src/rollers/dice/narrative.ts b/src/rollers/dice/narrative.ts new file mode 100644 index 0000000..cc48e08 --- /dev/null +++ b/src/rollers/dice/narrative.ts @@ -0,0 +1,549 @@ +import { RenderableRoller } from "../roller"; +import { DiceRoller } from "./dice"; +import { RenderTypes } from "./renderable"; +import type { App } from "obsidian"; +import type { LexicalToken } from "src/lexer/lexer"; +import type { DiceRollerSettings } from "src/settings/settings.types"; + +interface NarrativeResult { + success: number; //negative => failure + advantage: number; //negative => threat + triumph: number; //triumphs & despairs do not cancel, but count additonally for success/failure for the purpose of overall success. + despair: number; + light: number; //Light & Dark Side points are rolled independently and do not cancel. + dark: number; +} + +abstract class NarrativeRoller extends DiceRoller { + override canRender(): boolean { + return true; + } + abstract toNarrativeResult(): NarrativeResult; + abstract override getType(): RenderTypes; +} + +class BoostRoller extends NarrativeRoller { + toNarrativeResult(): NarrativeResult { + const narrativeResult: NarrativeResult = { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + for (const result of this.resultArray) { + if (result === 6) narrativeResult.success += 1; //Success + if (result === 5) { + //1 success 1 adv + narrativeResult.advantage += 1; + narrativeResult.success += 1; + } + if (result === 4) narrativeResult.advantage += 1; //1 Adv + if (result === 3) narrativeResult.advantage += 2; //2 Adv + if (result === 2) continue; //Blank + if (result === 1) continue; //Blank + if (result === 0) continue; + } + + return narrativeResult; + } + override getType(): RenderTypes { + return RenderTypes.BOOST; + } + override canRender(): boolean { + return true; + } + constructor(amount: number) { + super(`${amount}d6`); + } +} +class SetbackRoller extends NarrativeRoller { + toNarrativeResult(): NarrativeResult { + const narrativeResult: NarrativeResult = { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + for (const result of this.resultArray) { + if (result === 6) narrativeResult.advantage -= 1; //1 Threat + if (result === 5) narrativeResult.advantage -= 1; //1 Threat + if (result === 4) narrativeResult.success -= 1; //1 Fail + if (result === 3) narrativeResult.success -= 1; //1 Fail + if (result === 2) continue; //Blank + if (result === 1) continue; //Blank + if (result === 0) continue; + } + + return narrativeResult; + } + override getType(): RenderTypes { + return RenderTypes.SETBACK; + } + override canRender(): boolean { + return true; + } + constructor(amount: number) { + super(`${amount}d6`); + } +} +class AbilityRoller extends NarrativeRoller { + toNarrativeResult(): NarrativeResult { + const narrativeResult: NarrativeResult = { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + for (const result of this.resultArray) { + if (result === 8) { + //2 Adv + narrativeResult.advantage += 2; + } + if (result === 7) { + //1 success 1 adv + narrativeResult.advantage += 1; + narrativeResult.success += 1; + } + if (result === 6) narrativeResult.advantage += 1; //1 Adv + if (result === 5) narrativeResult.advantage += 1; //1 Adv + if (result === 4) narrativeResult.success += 2; //2 Success + if (result === 3) narrativeResult.success += 1; //1 Success + if (result === 2) narrativeResult.success += 1; //1 Success + if (result === 1) continue; //Blank + if (result === 0) continue; + } + + return narrativeResult; + } + override getType(): RenderTypes { + return RenderTypes.ABILITY; + } + override canRender(): boolean { + return true; + } + constructor(amount: number) { + super(`${amount}d8`); + } +} +class DifficultyRoller extends NarrativeRoller { + toNarrativeResult(): NarrativeResult { + const narrativeResult: NarrativeResult = { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + for (const result of this.resultArray) { + if (result === 8) { + //1 Threat 1 Fail + narrativeResult.advantage -= 1; + narrativeResult.success -= 1; + } + if (result === 7) narrativeResult.advantage -= 2; //2 Threat + if (result === 6) narrativeResult.advantage -= 1; //1 Threat + if (result === 5) narrativeResult.advantage -= 1; //1 Threat + if (result === 4) narrativeResult.advantage -= 1; //1 Threat + if (result === 3) narrativeResult.success -= 2; //2 Fail + if (result === 2) narrativeResult.success -= 1; //1 Fail + if (result === 1) continue; //Blank + if (result === 0) continue; + } + + return narrativeResult; + } + override getType(): RenderTypes { + return RenderTypes.DIFFICULTY; + } + override canRender(): boolean { + return true; + } + constructor(amount: number) { + super(`${amount}d8`); + } +} +class ProficiencyRoller extends NarrativeRoller { + toNarrativeResult(): NarrativeResult { + const narrativeResult: NarrativeResult = { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + for (const result of this.resultArray) { + //@Javalent are 0 results possible? + if (result === 12) { + //1 Triumph + narrativeResult.triumph += 1; + narrativeResult.success += 1; //Triumph counts as success, but Triumph cannot be cancelled. + } + if (result === 11) narrativeResult.advantage += 2; //2 Adv + if (result === 10) narrativeResult.advantage += 2; //2 Adv + if (result === 9) { + //1 Adv 1 Success + narrativeResult.advantage += 1; + narrativeResult.success += 1; + } + if (result === 8) { + //1 Adv 1 Suc + narrativeResult.advantage += 1; + narrativeResult.success += 1; + } + if (result === 7) { + //1 Adv 1 Suc + narrativeResult.advantage += 1; + narrativeResult.success += 1; + } + if (result === 6) { + //1 Adv + narrativeResult.advantage += 1; + } + if (result === 5) { + //2 Success + narrativeResult.success += 2; + } + if (result === 4) narrativeResult.success += 2; //2 Success + if (result === 3) narrativeResult.success += 1; //1 Success + if (result === 2) narrativeResult.success += 1; //1 Success + if (result === 1) continue; //Blank + if (result === 0) continue; + } + + return narrativeResult; + } + override getType(): RenderTypes { + return RenderTypes.PROFICIENCY; + } + override canRender(): boolean { + return true; + } + constructor(amount: number) { + super(`${amount}d12`); + } +} +class ChallengeRoller extends NarrativeRoller { + toNarrativeResult(): NarrativeResult { + const narrativeResult: NarrativeResult = { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + for (const result of this.resultArray) { + //@Javalent are 0 results possible? + if (result === 12) { + //1 Despair + narrativeResult.despair += 1; + narrativeResult.success -= 1; //Despair counts as fail, but does not cancel Despair. + } + if (result === 11) narrativeResult.advantage -= 2; //2 Threat + if (result === 10) narrativeResult.advantage -= 2; //2 Threat + if (result === 9) { + //1 Threat 1 Fail + narrativeResult.advantage -= 1; + narrativeResult.success -= 1; + } + if (result === 8) { + //1 Threat 1 Fail + narrativeResult.advantage -= 1; + narrativeResult.success -= 1; + } + if (result === 7) { + //1 Threat + narrativeResult.advantage -= 1; + } + if (result === 6) { + //1 Threat + narrativeResult.advantage -= 1; + } + if (result === 5) { + //2 Fail + narrativeResult.success -= 2; + } + if (result === 4) narrativeResult.success -= 2; //2 Fail + if (result === 3) narrativeResult.success -= 1; //1 Fail + if (result === 2) narrativeResult.success -= 1; //1 Fail + if (result === 1) continue; //Blank + if (result === 0) continue; + } + + return narrativeResult; + } + override getType(): RenderTypes { + return RenderTypes.CHALLENGE; + } + override canRender(): boolean { + return true; + } + constructor(amount: number) { + super(`${amount}d12`); + } +} +class ForceRoller extends NarrativeRoller { + toNarrativeResult(): NarrativeResult { + const narrativeResult: NarrativeResult = { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + for (const result of this.resultArray) { + //@Javalent are 0 results possible? + if (result === 12) narrativeResult.light += 2; //2 Light + if (result === 11) narrativeResult.light += 2; //2 Light + if (result === 10) narrativeResult.light += 2; //2 Light + if (result === 9) narrativeResult.light += 1; //1 Light + if (result === 8) narrativeResult.light += 1; //1 Light + if (result === 7) narrativeResult.dark += 2; //2 Dark + if (result === 6) narrativeResult.dark += 1; //1 Dark + if (result === 5) narrativeResult.dark += 1; //1 Dark + if (result === 4) narrativeResult.dark += 1; //1 Dark + if (result === 3) narrativeResult.dark += 1; //1 Dark + if (result === 2) narrativeResult.dark += 1; //1 Dark + if (result === 1) narrativeResult.dark += 1; //1 Dark + if (result === 0) continue; + } + + return narrativeResult; + } + override getType(): RenderTypes { + return RenderTypes.FORCE; + } + override canRender(): boolean { + return true; + } + constructor(amount: number) { + super(`${amount}d12`); + } +} +const NARRATIVE_FACES = ["g", "y", "b", "r", "p", "s", "w"] as const; +type NarrativeFace = (typeof NARRATIVE_FACES)[number]; +export class NarrativeStackRoller extends RenderableRoller { + constructor( + public data: DiceRollerSettings, + public original: string, + public lexemes: LexicalToken[], + public app: App, + position = data.position + ) { + super(data, original, lexemes, position); + } + children: NarrativeRoller[] = []; + getTooltip() { + let map = { + success: 0, + failure: 0, + advantage: 0, + threat: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + }; + + for (const child of this.children) { + const die = child.toNarrativeResult(); + + if (die.success > 0) { + map.success += die.success; + } else { + map.failure += die.success; + } + if (die.advantage > 0) { + map.advantage += die.advantage; + } else { + map.threat += die.advantage; + } + map.triumph += die.triumph; + map.despair += die.despair; + map.light += die.light; + map.dark += die.dark + } + return `**Totals** +Successes: ${map.success} +Failures: ${map.failure} +Advantages: ${map.advantage} +Threats: ${map.threat} +Triumphs: ${map.triumph} +Despairs: ${map.despair} +${map.light > 0 ? `Light Side: ${map.light}` : ''} +${map.dark > 0 ? `Dark Side: ${map.dark}` : ''}`; + } + private formatSymbol(text: string, fontFamily: string): string { + return `${text}`; + } + getResultText(): string { + const display = []; this.data.narrativeSymbolSet + if (this.data.displayAsSymbols) { + if (this.result.success === 0) { + display.push(`Wash`); + } else if (this.result.success > 0) { + display.push(`${this.result.success} `+ this.formatSymbol('s', this.data.narrativeSymbolSet)); + } else if (this.result.success < 0) { + display.push(`${this.result.success} ` + this.formatSymbol('f', this.data.narrativeSymbolSet)); + } + if (this.result.advantage > 0) { + display.push(`${this.result.advantage} ` + this.formatSymbol('a', this.data.narrativeSymbolSet)); + } else if (this.result.advantage < 0) { + display.push(`${Math.abs(this.result.advantage)} ` + this.formatSymbol('t', this.data.narrativeSymbolSet)); + } + if (this.result.triumph > 0) { + display.push(`${this.result.triumph} ` + this.formatSymbol('x', this.data.narrativeSymbolSet)); + } else if (this.result.despair > 0) { + display.push(`${Math.abs(this.result.despair)} ` + this.formatSymbol('y', this.data.narrativeSymbolSet)); + } + if (this.result.light > 0) { + display.push(`${this.result.light} ` + this.formatSymbol('z', this.data.narrativeSymbolSet)); + } + if (this.result.dark > 0) { + display.push(`${this.result.dark} ` + this.formatSymbol('Z', this.data.narrativeSymbolSet)); + } + return display.join(", "); + } else { + if (this.result.success === 0) { + display.push(`Wash`); + } else if (this.result.success > 0) { + display.push(`${this.result.success} success`); + } else if (this.result.success < 0) { + display.push(`${Math.abs(this.result.success)} failure`); + } + if (this.result.advantage > 0) { + display.push(`${this.result.advantage} advantage`); + } else if (this.result.advantage < 0) { + display.push(`${Math.abs(this.result.advantage)} threat`); + } + if (this.result.triumph > 0) { + display.push(`${this.result.triumph} triumph`); + } else if (this.result.despair > 0) { + display.push(`${Math.abs(this.result.despair)} despair`); + } + if (this.result.light > 0) { + display.push(`${this.result.light} light side`); + } + if (this.result.dark > 0) { + display.push(`${this.result.dark} dark side`); + } + return display.join(", "); + } + } + onload(): void { + const map: Map = new Map(); + + for (const lexeme of this.lexemes) { + for (const maybe of lexeme.value) { + let char = maybe as NarrativeFace; + if (!NARRATIVE_FACES.includes(char)) continue; + map.set(char, (map.get(char) ?? 0) + 1); + } + } + + for (const [type, amount] of map) { + let roller: NarrativeRoller; + switch (type) { + case "g": { + roller = new AbilityRoller(amount); + break; + } + case "y": { + roller = new ProficiencyRoller(amount); + break; + } + case "b": { + roller = new BoostRoller(amount); + break; + } + case "r": { + roller = new ChallengeRoller(amount); + break; + } + case "p": { + roller = new DifficultyRoller(amount); + break; + } + case "s": { + roller = new SetbackRoller(amount); + break; + } + case "w": { + roller = new ForceRoller(amount); + break; + } + } + this.children.push(roller); + } + super.onload(); + } + getReplacer(): Promise { + throw new Error("Method not implemented."); + } + result: NarrativeResult; + async roll(render?: boolean): Promise { + if (render || (this.shouldRender && this.hasRunOnce)) { + await this.renderChildren(); + } else { + return this.rollSync(); + } + this.hasRunOnce = true; + this.calculate(); + + this.trigger("new-result"); + this.app.workspace.trigger("dice-roller:new-result", this); + + this.render(); + return this.result; + } + rollSync() { + for (const dice of this.children) { + dice.rollSync(); + } + this.hasRunOnce = true; + this.calculate(); + this.trigger("new-result"); + this.app.workspace.trigger("dice-roller:new-result", this); + + this.render(); + return this.result; + } + + calculate() { + this.result = this.children.reduce( + (a, b) => { + a.success += b.toNarrativeResult().success; + a.advantage += b.toNarrativeResult().advantage; + a.triumph += b.toNarrativeResult().triumph; + a.despair += b.toNarrativeResult().despair; + a.light += b.toNarrativeResult().light; + a.dark += b.toNarrativeResult().dark; + return a; + }, + { + success: 0, + advantage: 0, + triumph: 0, + despair: 0, + light: 0, + dark: 0 + } + ); + } + + async build(): Promise { + this.resultEl.empty(); + + this.resultEl.addClass("dice-roller-genesys"); + this.resultEl.innerHTML = this.getResultText(); + } +} diff --git a/src/rollers/dice/renderable.ts b/src/rollers/dice/renderable.ts index 87e4e48..ae332e4 100644 --- a/src/rollers/dice/renderable.ts +++ b/src/rollers/dice/renderable.ts @@ -8,7 +8,7 @@ export interface RenderableDice { roll(): Promise; rollSync(): void; - render(): Promise; + render(abortController: AbortController): Promise; shouldRender: boolean; getValue(shapes?: DiceShape[]): Promise; @@ -16,17 +16,26 @@ export interface RenderableDice { } export const RenderTypes = { + NONE: "none", /** Polyhedral */ - D4: "4", - D6: "6", - D8: "8", - D10: "10", - D12: "12", - D20: "20", - D100: "100", + D4: "D4", + D6: "D6", + D8: "D8", + D10: "D10", + D12: "D12", + D20: "D20", + D100: "D100", /** Special */ FUDGE: "fudge", STUNT: "stunt", - NONE: "none" + + /** Genesys */ + BOOST: "boost", + SETBACK: "setback", + ABILITY: "ability", + DIFFICULTY: "difficulty", + PROFICIENCY: "proficiency", + CHALLENGE: "challenge", + FORCE: "force" } as const; export type RenderTypes = (typeof RenderTypes)[keyof typeof RenderTypes]; diff --git a/src/rollers/dice/stack.ts b/src/rollers/dice/stack.ts index f02031f..5af044a 100644 --- a/src/rollers/dice/stack.ts +++ b/src/rollers/dice/stack.ts @@ -1,4 +1,4 @@ -import { App, setIcon, Notice } from "obsidian"; +import { App, Notice } from "obsidian"; import type { LexicalToken } from "src/lexer/lexer"; import { DiceRenderer } from "src/renderer/renderer"; import { @@ -6,8 +6,7 @@ import { type DiceRollerSettings } from "src/settings/settings.types"; import { ExpectedValue, Round } from "src/types/api"; -import { Icons } from "src/utils/icons"; -import { Roller, BasicRoller } from "../roller"; +import { Roller, RenderableRoller } from "../roller"; import { DiceRoller } from "./dice"; import { PercentRoller } from "./percentage"; import { StuntRoller } from "./stunt"; @@ -248,13 +247,7 @@ export class BasicStackRoller extends Roller { } } -export class StackRoller extends BasicRoller { - onunload(): void { - if (this.isRendering) { - DiceRenderer.unrender(); - } - super.onunload(); - } +export class StackRoller extends RenderableRoller { result: number; fixedText: string; displayFixedText: boolean = false; @@ -271,10 +264,10 @@ export class StackRoller extends BasicRoller { shouldRender: boolean = false; isRendering: boolean = false; showFormula: boolean = false; - get resultText() { + getDisplayText() { let text: string[] = []; let index = 0; - this.dice.forEach((dice) => { + this.children.forEach((dice) => { const slice = this.original.slice(index); text.push( slice.slice(0, slice.indexOf(dice.lexeme.text)), @@ -289,22 +282,26 @@ export class StackRoller extends BasicRoller { text.push(this.original.slice(index)); return text.join(""); } - get tooltip() { + getResultText() { + return `${this.result}`; + } + getTooltip() { if (this.isRendering) { return this.original; } if (this._tooltip) return this._tooltip; + const display = this.getDisplayText(); if (this.expectedValue === ExpectedValue.Roll || this.shouldRender) { if (this.displayFixedText) { - return `${this.original}\n${this.result} = ${this.resultText}`; + return `${this.original}\n${this.result} = ${display}`; } - return `${this.original}\n${this.resultText}`; + return `${this.original}\n${display}`; } if (this.expectedValue === ExpectedValue.Average) { if (this.displayFixedText) { - return `${this.original}\n${this.result} = average: ${this.resultText}`; + return `${this.original}\n${this.result} = average: ${display}`; } - return `${this.original}\naverage: ${this.resultText}`; + return `${this.original}\naverage: ${display}`; } return `${this.original}\nempty`; @@ -395,29 +392,22 @@ export class StackRoller extends BasicRoller { } } async onClick(evt: MouseEvent) { - evt.stopPropagation(); - evt.stopImmediatePropagation(); if (evt.getModifierState("Alt")) { this.expectedValue = ExpectedValue.Average; } else if (evt.getModifierState("Control")) { this.expectedValue = ExpectedValue.None; } - if (evt.getModifierState("Shift")) { - await this.roll(true); - this.hasRunOnce = true; - } else if (window.getSelection()?.isCollapsed) { - await this.roll(); - } + super.onClick(evt); } get dynamic() { - return this.dice.filter((d) => !d.static); + return this.children.filter((d) => !d.static); } get static() { - return this.dice.filter((d) => d.static); + return this.children.filter((d) => d.static); } get isStatic() { - return this.dice.every((d) => d.static); + return this.children.every((d) => d.static); } constructor( @@ -446,8 +436,6 @@ export class StackRoller extends BasicRoller { this.displayFixedText = this.fixedText !== ""; this.round = round; this.signed = signed; - this.loaded = true; - this.trigger("loaded"); } operators: Record number> = { "+": (a: number, b: number): number => a + b, @@ -462,12 +450,12 @@ export class StackRoller extends BasicRoller { maxStack: number[] = []; minStack: number[] = []; stackCopy: Array = []; - dice: DiceRoller[] = []; + children: DiceRoller[] = []; hasRunOnce = false; rollSync() { this.stunted = ""; this.buildDiceTree(); - for (const dice of this.dice) { + for (const dice of this.children) { dice.rollSync(); } this.calculate(); @@ -478,28 +466,6 @@ export class StackRoller extends BasicRoller { this.hasRunOnce = true; return this.result; } - setSpinner() { - this.resultEl.empty(); - setIcon(this.resultEl.createDiv("should-spin"), Icons.LOADING); - } - async renderDice() { - this.isRendering = true; - this.setTooltip(); - this.setSpinner(); - const promises = []; - for (const die of this.dice) { - promises.push( - new Promise(async (resolve) => { - await die.render(); - resolve(); - }) - ); - } - await Promise.all(promises); - - this.isRendering = false; - this.setTooltip(); - } buildDiceTree() { let index = 0; for (const dice of this.lexemes) { @@ -513,7 +479,7 @@ export class StackRoller extends BasicRoller { continue; } case "u": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = dice.value ? Number(dice.value) : 1; diceInstance.modifiers.set("u", { @@ -524,7 +490,7 @@ export class StackRoller extends BasicRoller { break; } case "kh": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = dice.value ? Number(dice.value) : 1; diceInstance.modifiers.set("kh", { @@ -535,7 +501,7 @@ export class StackRoller extends BasicRoller { break; } case "dl": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = dice.value ? Number(dice.value) : 1; data = diceInstance.rolls - data; @@ -548,7 +514,7 @@ export class StackRoller extends BasicRoller { break; } case "kl": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = dice.value ? Number(dice.value) : 1; diceInstance.modifiers.set("kl", { @@ -559,7 +525,7 @@ export class StackRoller extends BasicRoller { break; } case "dh": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = dice.value ? Number(dice.value) : 1; data = diceInstance.rolls - data; @@ -572,7 +538,7 @@ export class StackRoller extends BasicRoller { break; } case "!": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = Number(dice.value) || 1; diceInstance.modifiers.set("!", { @@ -584,7 +550,7 @@ export class StackRoller extends BasicRoller { break; } case "!!": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = Number(dice.value) || 1; diceInstance.modifiers.set("!!", { @@ -596,7 +562,7 @@ export class StackRoller extends BasicRoller { break; } case "r": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = Number(dice.value) || 1; diceInstance.modifiers.set("r", { @@ -607,7 +573,7 @@ export class StackRoller extends BasicRoller { break; } case "sort": { - let diceInstance = this.dice[index - 1]; + let diceInstance = this.children[index - 1]; let data = Number(dice.value); diceInstance.modifiers.set("sort", { @@ -625,10 +591,10 @@ export class StackRoller extends BasicRoller { ) { const previous = this.stack.pop(); dice.value = `${previous.result}${dice.value}`; - this.dice[index] = new DiceRoller(dice.value, dice); + this.children[index] = new DiceRoller(dice.value, dice); } - if (!this.dice[index]) { - this.dice[index] = new DiceRoller(dice.value, dice); + if (!this.children[index]) { + this.children[index] = new DiceRoller(dice.value, dice); } index++; @@ -636,23 +602,32 @@ export class StackRoller extends BasicRoller { } case "fudge": { - if (!this.dice[index]) { - this.dice[index] = new FudgeRoller(dice.value, dice); + if (!this.children[index]) { + this.children[index] = new FudgeRoller( + dice.value, + dice + ); } index++; break; } case "stunt": { - if (!this.dice[index]) { - this.dice[index] = new StuntRoller(dice.value, dice); + if (!this.children[index]) { + this.children[index] = new StuntRoller( + dice.value, + dice + ); } index++; break; } case "%": { - if (!this.dice[index]) { - this.dice[index] = new PercentRoller(dice.value, dice); + if (!this.children[index]) { + this.children[index] = new PercentRoller( + dice.value, + dice + ); } index++; break; @@ -663,15 +638,15 @@ export class StackRoller extends BasicRoller { async roll(render?: boolean) { this.stunted = ""; this.stackCopy = []; - if (!this.dice.length) { + if (!this.children.length) { this.buildDiceTree(); } DiceRenderer.stop(); - this.dice.forEach((dice) => (dice.shouldRender = false)); + this.children.forEach((dice) => (dice.shouldRender = false)); if (render || (this.shouldRender && this.hasRunOnce)) { - await this.renderDice(); + await this.renderChildren(); } else { - for (const dice of this.dice) { + for (const dice of this.children) { await dice.roll(); } } @@ -682,7 +657,7 @@ export class StackRoller extends BasicRoller { this.showRenderNotice && (render || (this.shouldRender && this.hasRunOnce)) ) { - new Notice(`${this.tooltip}\n\nResult: ${this.result}`); + new Notice(`${this.getTooltip()}\n\nResult: ${this.result}`); } this.trigger("new-result"); @@ -743,10 +718,10 @@ export class StackRoller extends BasicRoller { case "fudge": case "%": case "dice": { - this.stack.push(this.dice[index]); - this.stackCopy.push(this.dice[index]); - this.minStack.push(this.dice[index].getMinPossible()); - this.maxStack.push(this.dice[index].getMaxPossible()); + this.stack.push(this.children[index]); + this.stackCopy.push(this.children[index]); + this.minStack.push(this.children[index].getMinPossible()); + this.maxStack.push(this.children[index].getMaxPossible()); index++; } default: { diff --git a/src/rollers/line/line.ts b/src/rollers/line/line.ts index 199e8ec..76e36f5 100644 --- a/src/rollers/line/line.ts +++ b/src/rollers/line/line.ts @@ -17,7 +17,7 @@ export class LineRoller extends GenericEmbeddedRoller { types: string[]; content: string; - get tooltip() { + getTooltip() { return `${this.original}\n${this.path}`; } async build() { diff --git a/src/rollers/roller.ts b/src/rollers/roller.ts index c2e0aa4..142be5d 100644 --- a/src/rollers/roller.ts +++ b/src/rollers/roller.ts @@ -11,11 +11,13 @@ import { } from "obsidian"; import type { LexicalToken } from "src/lexer/lexer"; +import { DiceRenderer } from "src/renderer/renderer"; import type { ButtonPosition, DiceRollerSettings } from "src/settings/settings.types"; import { Icons } from "src/utils/icons"; +import type { RenderableDice } from "./dice/renderable"; export interface ComponentLike { addChild(child: Component): void; @@ -46,7 +48,11 @@ export abstract class Roller extends Component implements Events { abstract roll(): Promise | T; components: ComponentLike[] = []; - + loaded: boolean = false; + onload(): void { + this.loaded = true; + this.trigger("loaded"); + } onunload(): void { this.components = []; } @@ -71,7 +77,8 @@ interface BareRoller { trigger(name: "loaded"): void; on(name: "new-result", callback: () => void): EventRef; trigger(name: "new-result"): void; -}abstract class BareRoller extends Roller { +} +abstract class BareRoller extends Roller { constructor( public data: DiceRollerSettings, public original = "", @@ -125,14 +132,14 @@ interface BareRoller { this.containerEl.append(pre); } abstract build(): Promise; - abstract get tooltip(): string; + abstract getTooltip(): string; containerEl: HTMLSpanElement; resultEl: HTMLSpanElement; iconEl: HTMLSpanElement; setTooltip() { if (this.data.displayResultsInline) return; this.containerEl.setAttrs({ - "aria-label": this.tooltip + "aria-label": this.getTooltip() }); } getRandomBetween(min: number, max: number): number { @@ -159,6 +166,12 @@ export abstract class BasicRoller extends BareRoller { source: string; abstract getReplacer(): Promise; save: boolean = false; + + setSpinner() { + this.resultEl.empty(); + setIcon(this.resultEl.createDiv("should-spin"), Icons.LOADING); + } + abstract result: T; abstract roll(): Promise; @@ -170,8 +183,9 @@ export abstract class BasicRoller extends BareRoller { } get inlineText() { - return `${this.tooltip.split("\n").join(" -> ")} -> `; + return `${this.getTooltip().split("\n").join(" -> ")} -> `; } + constructor( public data: DiceRollerSettings, public original: string, @@ -182,6 +196,66 @@ export abstract class BasicRoller extends BareRoller { } } +export abstract class RenderableRoller extends BasicRoller { + shouldRender: boolean = false; + isRendering: boolean = false; + hasRunOnce: boolean = false; + override onunload(): void { + if (this.isRendering) { + DiceRenderer.stop(); + } + super.onunload(); + } + override async onClick(evt: MouseEvent) { + evt.stopPropagation(); + evt.stopImmediatePropagation(); + + if (this.isRendering) { + DiceRenderer.stop(); + } + this.#controller?.abort(); + if (evt.getModifierState("Shift")) { + await this.roll(true); + this.hasRunOnce = true; + } else if (window.getSelection()?.isCollapsed) { + await this.roll(); + } + } + + abstract rollSync(): T; + abstract roll(render?: boolean): Promise; + abstract getResultText(): string; + + children: RenderableDice[]; + #controller: AbortController; + async renderChildren(): Promise { + this.isRendering = true; + this.setTooltip(); + this.setSpinner(); + const promises = []; + this.#controller = new AbortController(); + for (const die of this.children) { + promises.push( + new Promise(async (resolve, reject) => { + this.#controller.signal.addEventListener("abort", () => { + reject(); + }); + await die.render(this.#controller); + resolve(); + }) + ); + } + try { + await Promise.all(promises); + } catch (e) { + return; + } + + this.isRendering = false; + + this.setTooltip(); + } +} export abstract class GenericFileRoller extends BasicRoller { path: string; file: TFile; @@ -308,7 +382,7 @@ export abstract class GenericEmbeddedRoller extends GenericFileRoller { export class ArrayRoller extends BareRoller { declare result: any; results: any[]; - get tooltip() { + getTooltip(): string { return `${this.options.toString()}\n\n${this.results.toString()}`; } async roll() { diff --git a/src/rollers/section/section.ts b/src/rollers/section/section.ts index 370358f..9fdef86 100644 --- a/src/rollers/section/section.ts +++ b/src/rollers/section/section.ts @@ -44,7 +44,7 @@ export class SectionRoller extends GenericEmbeddedRoller { content: string; levels: string[]; - get tooltip() { + getTooltip() { return `${this.original}\n${this.path}`; } async build() { diff --git a/src/rollers/table/table.ts b/src/rollers/table/table.ts index 6faf16b..b903e44 100644 --- a/src/rollers/table/table.ts +++ b/src/rollers/table/table.ts @@ -68,13 +68,20 @@ export class TableRoller extends GenericFileRoller { .toLowerCase(); this.header = header; } - get tooltip() { + getTooltip() { return this.prettyTooltip; } async getReplacer() { return this.result; } result: string; + getResultText(): string { + const result = [this.result]; + if (this.data.displayResultsInline) { + result.unshift(this.inlineText); + } + return result.join(""); + } async build() { this.resultEl.empty(); const result = [this.result]; @@ -84,7 +91,7 @@ export class TableRoller extends GenericFileRoller { const div = createSpan(); MarkdownRenderer.render( this.app, - result.join(""), + this.getResultText(), div, this.source, new Component() @@ -179,7 +186,7 @@ export class TableRoller extends GenericFileRoller { if (subRoller instanceof TableRoller) { subTooltips.push(subRoller.combinedTooltip); } else { - const [top, bottom] = subRoller.tooltip.split("\n"); + const [top, bottom] = subRoller.getTooltip().split("\n"); subTooltips.push(top + " --> " + bottom); } } @@ -215,9 +222,7 @@ export class TableRoller extends GenericFileRoller { if (!rollsRoller.isStatic) { formula = formula.replace( this.rollsFormula, - `${this.rollsFormula.trim()} --> ${ - rollsRoller.resultText - } > ` + `${this.rollsFormula.trim()} --> ${rollsRoller.getDisplayText()} > ` ); } } @@ -244,7 +249,7 @@ export class TableRoller extends GenericFileRoller { subTooltip = this.lookupRoller.original.trim() + " --> " + - `${this.lookupRoller.resultText}${ + `${this.lookupRoller.getDisplayText()}${ this.header ? " | " + this.header : "" }`.trim(); selectedOption = option[1]; diff --git a/src/rollers/tag/tag.ts b/src/rollers/tag/tag.ts index a612f34..efe5b0b 100644 --- a/src/rollers/tag/tag.ts +++ b/src/rollers/tag/tag.ts @@ -201,7 +201,7 @@ abstract class DataViewEnabledRoller extends BasicRoller { } }); } - get tooltip() { + getTooltip() { return this.original; } } diff --git a/src/settings/settings.const.ts b/src/settings/settings.const.ts index b48ec24..691c722 100644 --- a/src/settings/settings.const.ts +++ b/src/settings/settings.const.ts @@ -28,6 +28,8 @@ export const DEFAULT_SETTINGS: DiceRollerSettings = { textColor: "#ffffff", textFont: "Arial", showLeafOnStartup: true, + narrativeSymbolSet: "Genesys", + displayAsSymbols: false, displayAsEmbed: true, round: Round.None, diff --git a/src/settings/settings.ts b/src/settings/settings.ts index 5a99048..3709e21 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -125,6 +125,11 @@ export default class SettingTab extends PluginSettingTab { cls: "dice-roller-nested-settings" }) ); + this.buildNarrative( + this.contentEl.createEl("details", { + cls: "dice-roller-nested-settings" + }) + ); this.buildDiceModTemplateFoldersSettings( this.contentEl.createEl("details", { cls: "dice-roller-nested-settings" @@ -359,6 +364,38 @@ export default class SettingTab extends PluginSettingTab { }); }); } + buildNarrative(containerEl: HTMLDetailsElement) { + containerEl.empty(); + this.#buildSummary(containerEl, "Narrative Rollers"); + + // Dropdown for selecting the symbol set (Genesys or SWRPG) + new Setting(containerEl) + .setName("Symbol Set") + .setDesc("Select between Genesys or SWRPG symbols.") + .addDropdown((dropdown) => { + dropdown.addOption("Genesys", "Genesys"); + dropdown.addOption("SWRPG", "SWRPG"); + dropdown.setValue(this.plugin.data.narrativeSymbolSet); + dropdown.onChange(async (value) => { + this.plugin.data.narrativeSymbolSet = value; + DiceRenderer.setData(this.plugin.getRendererData()); + await this.plugin.saveSettings(); + }); + }); + + // Toggle for displaying as text or symbols + new Setting(containerEl) + .setName("Display Results as Symbols") + .setDesc("Toggle between text and symbol results.") + .addToggle((toggle) => { + toggle.setValue(this.plugin.data.displayAsSymbols); + toggle.onChange(async (value) => { + this.plugin.data.displayAsSymbols = value; + await this.plugin.saveSettings(); + }); + }); + } + buildView(containerEl: HTMLDetailsElement) { containerEl.empty(); this.#buildSummary(containerEl, "Dice Tray"); diff --git a/src/settings/settings.types.ts b/src/settings/settings.types.ts index 33000de..49a11d3 100644 --- a/src/settings/settings.types.ts +++ b/src/settings/settings.types.ts @@ -33,6 +33,8 @@ export interface DiceRollerSettings { textColor: string; textFont: string; showLeafOnStartup: boolean; + narrativeSymbolSet: string; + displayAsSymbols: boolean; customFormulas: string[]; displayAsEmbed: boolean; diff --git a/src/styles.css b/src/styles.css index 8f2ad7f..bf6291c 100644 --- a/src/styles.css +++ b/src/styles.css @@ -1,3 +1,4 @@ @import "./assets/main.css"; @import "./view/view.css"; @import "./settings/settings.css"; +@import "./renderer/font.css"; diff --git a/src/types/obsidian-ext.d.ts b/src/types/obsidian-ext.d.ts index 827464c..c72973d 100644 --- a/src/types/obsidian-ext.d.ts +++ b/src/types/obsidian-ext.d.ts @@ -1,10 +1,11 @@ import type { StackRoller } from "src/rollers"; +import type { RenderableRoller } from "src/rollers/roller"; import type { DiceRollerSettings } from "src/settings/settings.types"; //expose dataview plugin for tags declare module "obsidian" { interface Workspace { - trigger(name: "dice-roller:new-result", data: StackRoller): void; + trigger(name: "dice-roller:new-result", data: RenderableRoller): void; trigger(name: "dice-roller:rendered-result", data: number): void; trigger(name: "dice-roller:loaded"): void; trigger(name: "dice-roller:unloaded"): void; diff --git a/src/view/view.ts b/src/view/view.ts index 394b560..b1885a1 100644 --- a/src/view/view.ts +++ b/src/view/view.ts @@ -15,6 +15,7 @@ import { type DiceIcon, IconManager } from "./view.icons"; import { Icons } from "src/utils/icons"; import { nanoid } from "nanoid"; import DiceTray from "./ui/DiceTray.svelte"; +import type { RenderableRoller } from "src/rollers/roller"; /* import { Details } from "@javalent/utilities"; */ @@ -60,15 +61,15 @@ export default class DiceView extends ItemView { this.registerEvent( this.plugin.app.workspace.on( "dice-roller:new-result", - async (roller: StackRoller) => { + async (roller: RenderableRoller) => { if ( this.plugin.data.addToView || roller.getSource() == VIEW_TYPE ) { await this.addResult({ - result: roller.result, + result: roller.getResultText(), original: roller.original, - resultText: roller.resultText, + resultText: roller.getTooltip(), timestamp: new Date().valueOf(), id: nanoid(12) }); @@ -265,7 +266,7 @@ export default class DiceView extends ItemView { roller.iconEl.detach(); roller.containerEl.onclick = null; roller.buildDiceTree(); - if (!roller.dice.length) { + if (!roller.children.length) { throw new Error("No dice."); } await roller.roll(this.plugin.data.renderer).catch((e) => { @@ -337,7 +338,7 @@ export default class DiceView extends ItemView { .setIcon(Icons.COPY) .setTooltip("Copy Result") .onClick(async () => { - await navigator.clipboard.writeText(`${result.result}`); + await navigator.clipboard.writeText(`${result.resultText}`); }); copy.extraSettingsEl.addClass("dice-content-copy"); if (Platform.isMobile) { diff --git a/test/parser/lexer.test.ts b/test/parser/lexer.test.ts index d8859c7..4d92bbd 100644 --- a/test/parser/lexer.test.ts +++ b/test/parser/lexer.test.ts @@ -1,6 +1,7 @@ import { vi, test, expect } from "vitest"; import { Lexer } from "../../src/lexer/lexer"; import { toLexicalToken } from "../util"; +import { Ok } from "@sniptt/monads"; /** * possible formats: @@ -50,7 +51,7 @@ Lexer.setDefaultFace(100); Lexer.setDefaultRoll(1); test('Lexer should parse "d"', () => { - let actual = Lexer.parse("d").map(toLexicalToken); + let actual = Lexer.parse("d").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -62,7 +63,7 @@ test('Lexer should parse "d"', () => { }); test('Lexer should parse "5d17"', () => { - let actual = Lexer.parse("5d17").map(toLexicalToken); + let actual = Lexer.parse("5d17").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -74,7 +75,7 @@ test('Lexer should parse "5d17"', () => { }); test('Lexer should parse "5d%"', () => { - let actual = Lexer.parse("5d%").map(toLexicalToken); + let actual = Lexer.parse("5d%").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -86,7 +87,7 @@ test('Lexer should parse "5d%"', () => { }); test('Lexer should parse "2d66%"', () => { - let actual = Lexer.parse("2d66%").map(toLexicalToken); + let actual = Lexer.parse("2d66%").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -98,7 +99,7 @@ test('Lexer should parse "2d66%"', () => { }); test('Lexer should parse "1d6dh', () => { - let actual = Lexer.parse("1d6dh").map(toLexicalToken); + let actual = Lexer.parse("1d6dh").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -116,7 +117,7 @@ test('Lexer should parse "1d6dh', () => { }); test('Lexer should parse "1d6dh3', () => { - let actual = Lexer.parse("1d6dh3").map(toLexicalToken); + let actual = Lexer.parse("1d6dh3").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -134,7 +135,7 @@ test('Lexer should parse "1d6dh3', () => { }); test('Lexer should parse "1d6dl', () => { - let actual = Lexer.parse("1d6dl").map(toLexicalToken); + let actual = Lexer.parse("1d6dl").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -152,7 +153,7 @@ test('Lexer should parse "1d6dl', () => { }); test('Lexer should parse "1d6dl3', () => { - let actual = Lexer.parse("1d6dl3").map(toLexicalToken); + let actual = Lexer.parse("1d6dl3").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -170,7 +171,7 @@ test('Lexer should parse "1d6dl3', () => { }); test('Lexer should parse "1d6kl', () => { - let actual = Lexer.parse("1d6kl").map(toLexicalToken); + let actual = Lexer.parse("1d6kl").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -188,7 +189,7 @@ test('Lexer should parse "1d6kl', () => { }); test('Lexer should parse "1d6kl3', () => { - let actual = Lexer.parse("1d6kl3").map(toLexicalToken); + let actual = Lexer.parse("1d6kl3").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -206,7 +207,7 @@ test('Lexer should parse "1d6kl3', () => { }); test('Lexer should parse "1d6k', () => { - let actual = Lexer.parse("1d6k").map(toLexicalToken); + let actual = Lexer.parse("1d6k").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -224,7 +225,7 @@ test('Lexer should parse "1d6k', () => { }); test('Lexer should parse "1d6k3', () => { - let actual = Lexer.parse("1d6k3").map(toLexicalToken); + let actual = Lexer.parse("1d6k3").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -242,7 +243,7 @@ test('Lexer should parse "1d6k3', () => { }); test('Lexer should parse "1d6kh', () => { - let actual = Lexer.parse("1d6kh").map(toLexicalToken); + let actual = Lexer.parse("1d6kh").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -260,7 +261,7 @@ test('Lexer should parse "1d6kh', () => { }); test('Lexer should parse "1d6kh3', () => { - let actual = Lexer.parse("1d6kh3").map(toLexicalToken); + let actual = Lexer.parse("1d6kh3").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -278,7 +279,7 @@ test('Lexer should parse "1d6kh3', () => { }); test('Lexer should parse "5d6!!', () => { - let actual = Lexer.parse("5d6!!").map(toLexicalToken); + let actual = Lexer.parse("5d6!!").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -296,7 +297,7 @@ test('Lexer should parse "5d6!!', () => { }); test('Lexer should parse "5d6!!3', () => { - let actual = Lexer.parse("5d6!!3").map(toLexicalToken); + let actual = Lexer.parse("5d6!!3").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -314,7 +315,7 @@ test('Lexer should parse "5d6!!3', () => { }); test('Lexer should parse "5d6!!i', () => { - let actual = Lexer.parse("5d6!!i").map(toLexicalToken); + let actual = Lexer.parse("5d6!!i").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -332,7 +333,7 @@ test('Lexer should parse "5d6!!i', () => { }); test('Lexer should parse "5d6!', () => { - let actual = Lexer.parse("5d6!").map(toLexicalToken); + let actual = Lexer.parse("5d6!").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -350,7 +351,7 @@ test('Lexer should parse "5d6!', () => { }); test('Lexer should parse "5d6!3', () => { - let actual = Lexer.parse("5d6!3").map(toLexicalToken); + let actual = Lexer.parse("5d6!3").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -368,7 +369,7 @@ test('Lexer should parse "5d6!3', () => { }); test('Lexer should parse "5d6!i', () => { - let actual = Lexer.parse("5d6!i").map(toLexicalToken); + let actual = Lexer.parse("5d6!i").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -386,7 +387,7 @@ test('Lexer should parse "5d6!i', () => { }); test('Lexer should parse "5d6u', () => { - let actual = Lexer.parse("5d6u").map(toLexicalToken); + let actual = Lexer.parse("5d6u").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -404,7 +405,7 @@ test('Lexer should parse "5d6u', () => { }); test('Lexer should parse "5d[3,7]', () => { - let actual = Lexer.parse("5d[3,7]").map(toLexicalToken); + let actual = Lexer.parse("5d[3,7]").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -416,7 +417,7 @@ test('Lexer should parse "5d[3,7]', () => { }); test('Lexer should parse "5d[7,3]', () => { - let actual = Lexer.parse("5d[7,3]").map(toLexicalToken); + let actual = Lexer.parse("5d[7,3]").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -428,7 +429,7 @@ test('Lexer should parse "5d[7,3]', () => { }); test('Lexer should parse "5d7r', () => { - let actual = Lexer.parse("5d7r").map(toLexicalToken); + let actual = Lexer.parse("5d7r").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -446,7 +447,7 @@ test('Lexer should parse "5d7r', () => { }); test('Lexer should parse "5d7r4', () => { - let actual = Lexer.parse("5d7r4").map(toLexicalToken); + let actual = Lexer.parse("5d7r4").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -464,7 +465,7 @@ test('Lexer should parse "5d7r4', () => { }); test('Lexer should parse "5d7ri', () => { - let actual = Lexer.parse("5d7ri").map(toLexicalToken); + let actual = Lexer.parse("5d7ri").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -482,7 +483,7 @@ test('Lexer should parse "5d7ri', () => { }); test('Lexer should parse "5d7s', () => { - let actual = Lexer.parse("5d7s").map(toLexicalToken); + let actual = Lexer.parse("5d7s").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -500,7 +501,7 @@ test('Lexer should parse "5d7s', () => { }); test('Lexer should parse "5d7sa', () => { - let actual = Lexer.parse("5d7sa").map(toLexicalToken); + let actual = Lexer.parse("5d7sa").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -518,7 +519,7 @@ test('Lexer should parse "5d7sa', () => { }); test('Lexer should parse "5d7sd', () => { - let actual = Lexer.parse("5d7sd").map(toLexicalToken); + let actual = Lexer.parse("5d7sd").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -536,12 +537,12 @@ test('Lexer should parse "5d7sd', () => { }); test('Lexer should parse "6dF', () => { - let actual = Lexer.parse("6dF").map(toLexicalToken); + let actual = Lexer.parse("6dF").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, parenedDice: undefined, - type: "dice", + type: "fudge", value: "6dF" } ]); @@ -550,7 +551,7 @@ test('Lexer should parse "6dF', () => { // SPECIAL DICE =============================================================== test('Lexer should parse "1dS', () => { - let actual = Lexer.parse("1dS").map(toLexicalToken); + let actual = Lexer.parse("1dS").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -562,13 +563,13 @@ test('Lexer should parse "1dS', () => { }); test('Lexer should parse "5dS', () => { - expect(() => Lexer.parse("5dS")).toThrow(); + expect(Lexer.parse("5dS").unwrapErr()).toBe("Could not parse"); }); // BLOCKS ===================================================================== test('Lexer should parse "[[Note]]', () => { - let actual = Lexer.parse("[[Note]]").map(toLexicalToken); + let actual = Lexer.parse("[[Note]]").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -580,7 +581,7 @@ test('Lexer should parse "[[Note]]', () => { }); test('Lexer should parse "4d[[Note]]', () => { - let actual = Lexer.parse("4d[[Note]]").map(toLexicalToken); + let actual = Lexer.parse("4d[[Note]]").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -592,7 +593,7 @@ test('Lexer should parse "4d[[Note]]', () => { }); test('Lexer should parse "[[Note]]|line', () => { - let actual = Lexer.parse("[[Note]]|line").map(toLexicalToken); + let actual = Lexer.parse("[[Note]]|line").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -604,7 +605,7 @@ test('Lexer should parse "[[Note]]|line', () => { }); test('Lexer should parse "[[Note]]|heading-2', () => { - let actual = Lexer.parse("[[Note]]|heading-2").map(toLexicalToken); + let actual = Lexer.parse("[[Note]]|heading-2").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -616,7 +617,7 @@ test('Lexer should parse "[[Note]]|heading-2', () => { }); test('Lexer should parse "[[Note^block-id]]', () => { - let actual = Lexer.parse("[[Note^block-id]]").map(toLexicalToken); + let actual = Lexer.parse("[[Note^block-id]]").unwrap().map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -628,7 +629,9 @@ test('Lexer should parse "[[Note^block-id]]', () => { }); test('Lexer should parse "1d4+1[[Note^block-id]]', () => { - let actual = Lexer.parse("1d4+1[[Note^block-id]]").map(toLexicalToken); + let actual = Lexer.parse("1d4+1[[Note^block-id]]") + .unwrap() + .map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -640,7 +643,9 @@ test('Lexer should parse "1d4+1[[Note^block-id]]', () => { }); test('Lexer should parse "[[Note^block-id]]|Header 2', () => { - let actual = Lexer.parse("[[Note^block-id]]|Header 2").map(toLexicalToken); + let actual = Lexer.parse("[[Note^block-id]]|Header 2") + .unwrap() + .map(toLexicalToken); expect(actual).toEqual([ { conditions: undefined, @@ -654,25 +659,25 @@ test('Lexer should parse "[[Note^block-id]]|Header 2', () => { // FORMULAS =================================================================== test('Lexer should parse "1d20 + -2" like "1d20 - 2"', () => { - let a = Lexer.parse("1d20 + -2").map(toLexicalToken); - let b = Lexer.parse("1d20 - 2").map(toLexicalToken); + let a = Lexer.parse("1d20 + -2").unwrap().map(toLexicalToken); + let b = Lexer.parse("1d20 - 2").unwrap().map(toLexicalToken); expect(a).toEqual(b); }); test('Lexer should parse "1d20 - -2" like "1d20 + 2"', () => { - let a = Lexer.parse("1d20 - -2").map(toLexicalToken); - let b = Lexer.parse("1d20 + 2").map(toLexicalToken); + let a = Lexer.parse("1d20 - -2").unwrap().map(toLexicalToken); + let b = Lexer.parse("1d20 + 2").unwrap().map(toLexicalToken); expect(a).toEqual(b); }); test('Lexer should parse "1d20 ----2" like "1d20 + 2"', () => { - let a = Lexer.parse("1d20 ----2").map(toLexicalToken); - let b = Lexer.parse("1d20 + 2").map(toLexicalToken); + let a = Lexer.parse("1d20 ----2").unwrap().map(toLexicalToken); + let b = Lexer.parse("1d20 + 2").unwrap().map(toLexicalToken); expect(a).toEqual(b); }); test('Lexer should parse "1d20 -++---+-+--++17" like "1d20 - 17"', () => { - let a = Lexer.parse("1d20 -++---+-+--++17").map(toLexicalToken); - let b = Lexer.parse("1d20 - 17").map(toLexicalToken); + let a = Lexer.parse("1d20 -++---+-+--++17").unwrap().map(toLexicalToken); + let b = Lexer.parse("1d20 - 17").unwrap().map(toLexicalToken); expect(a).toEqual(b); }); diff --git a/test/util.ts b/test/util.ts index 3989a73..f1a139c 100644 --- a/test/util.ts +++ b/test/util.ts @@ -1,3 +1,5 @@ +import { LexicalToken } from "../src/lexer/lexer"; + export function toLexicalToken(e: LexicalToken): LexicalToken { let { conditions, parenedDice, type, value } = e; return { conditions, parenedDice, type, value };