Skip to content

Commit

Permalink
feat: Genesys/Star Wars narrative dice are now supported and renderab…
Browse files Browse the repository at this point in the history
…le. (#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 <[email protected]>
  • Loading branch information
valentine195 and source-toad authored Nov 5, 2024
1 parent 5c1969f commit b0ba905
Show file tree
Hide file tree
Showing 25 changed files with 1,296 additions and 232 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ Use `` `dice: XdF` `` to roll a fudge/fate dice. See [here](<https://en.wikipedi

Use `` `dice: 1dS` `` to roll a Fantasy AGE stunt dice. The result will show the total roll and also the stunt points if successful.

## Genesys/SWRPG Narrative Dice

Use `` `dice: GgPpYyRrBbSsWw` `` to roll Narrative dice. The result will show the total roll in net symbols (Success, Advantage etc.). Total individual results displayed in the tooltip, and results display can be toggled between words and symbols in the settings.

| Dice | Syntax Options |
| ----------------- | -------------- |
| Ability | `Gg` `Aa` |
| Proficiency | `Yy` `Pp` `pro`|
| Difficulty | `Pp` `Dd` `diff` |
| Challenge | `Rr` `Cc` |
| Boost | `Bb` `boo` |
| Setback | `Ss` `sb` `blk` |
| Force | `Ww` `Ff` |

Specifying quantities of dice with a digit will also work. E.g. `` `dice: 3g4d` ``

> 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.
Expand Down
16 changes: 15 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -26,7 +27,8 @@ export {
type DataViewRoller,
type TagRoller,
type LineRoller,
type ArrayRoller
type ArrayRoller,
type NarrativeStackRoller
};

export interface RollerOptions {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/lexer/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/font.css

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

Loading

0 comments on commit b0ba905

Please sign in to comment.