javalent / fantasy-statblocks

Create Dungeons and Dragons style statblocks for Obsidian.md
MIT License
341 stars 71 forks source link

Custom Layout not parcing dice roller correctly #353

Closed Daniel-Leinberger closed 4 months ago

Daniel-Leinberger commented 5 months ago

Check for existing bug reports before submitting.

Expected Behavior

When I used a custom layout in the past, I was able to use the formula 0 (1d20 + 1) to activate the dice roller addon inside a string or any kind of block.

I used it in my own layout to describe the value of ability and had the formula after that to see my base value and then my rolled value like strength: 14 | 0 (1d20+2) or strength: "14 | 0 (1d20+2)", which allowed me to see my strength of 14 at all times but roll for it if needed.

Current behaviour

Within a few newer patches (I didn't updated in a long time - last time I know it worked was Fantasy Statblocks v 3.8.4 and Dice Roller 9.30) the parser for dices is not correctly displayed for Property lines (see picture below).

I just updated one of my vaults where I had the formula given in "expected behavior" and after the update, it just parses the formula as plain string.

But if I use the standard Base 5e Layout it's working all fine. see in the picture below:

image

I don't know what I'm doing wrong here and before the update it was all working fine. Therefore, I assume it's a little bug. But if not I'm happy to hear, what's the solution for the problem.

Reproduction

  1. Get Obsidian
  2. Install Dice Roller and Fantasy Statblocks
  3. Create a new layout (I've just added a group, then saves, then spells and a simple property line)
  4. Create a new note
  5. Insert the following inside the statblock tag (can't correctly insert it here, Github just converts it to code):
layout: Basic 5e Layout
hp: 10
saves:
  - Strenght: 13 | 0 (1d20+1)
spells:
  - Super Spell: 13 | 0 (1d20+1)
damage_resistances: "Fire | 0 (1d20+1)"
layout: Test around
saves:
  - Strenght: 13 | 0 (1d20+1)
spells:
  - Super Spell: 13 | 0 (1d20+1)
property: Fire | 0 (1d20+1)

You should see the same statblocks as in my screenshot. Everything in the Base layout is transforming properly but nothing inside my own layout.

Which Operating Systems are you using?

Obsidian Version Check

1.5.3

Plugin Version

3.19.2

Confirmation

Possible solution

No response

Daniel-Leinberger commented 5 months ago

Never mind... seems like I forgot to copy-paste the dice regex underneath the "advanced"-tab to my new layout... Maybe this was prefilled in the old version, and that's why I didn't noticed it to need it...

So for everyone having the same problem, just follow these steps:

  1. Open the Basic 5e Layout
  2. Click on "Advanced" on the left of the window
  3. Copy paste the regex and the code to your notepad, word or whatever.
  4. Open your custom layout
  5. Click on "Advanced" on the left of the window
  6. Insert the regex with the corresponding code to it.
  7. Save and reload
  8. It should work now

Sorry for the useless issue. Great job this plugin :)

valentine195 commented 5 months ago

I am reopening this because it should inherit the old defaults if none are provided.

GladLantern commented 5 months ago

I have the exact same issue. Before the last update, the formula : Damage: 5 (1d5+3) in my custom layout would show the dice roller as in the Basic 5e Layout.

Now as you can see on the screenshot, on the left, the custom layout does not work anymore, but the Basic 5e Layout does.

image

GladLantern commented 5 months ago

@Daniel-Leinberger I followed your instructions, but in the "Advanced" tab of the Basic 5e Layout, there is no Regex to copy/paste. Same with any other layouts.

image

Daniel-Leinberger commented 5 months ago

@GladLantern

Interesting... I've got the following and I clearly did not code it myself because I don't know anything about this specific stuff 😅

image
  1. ([+-])(\d+) to hit let [, sign, number] = matches; let mult = 1; if (sign === "-") { mult = -1; } if (!isNaN(Number(number))) { return { text: 1d20+${mult * Number(number)}, original } }

  2. (\d+)\s((\d+d\d+(?:\s[+-]\s\d+)?)) let [, base, dice] = matches; let text; if (!isNaN(Number(base)) && dice) { text = dice; } return { text, original };

  3. . ([+-]\d+) let [, save, sign, number] = matches; let mult = 1; if (sign === "-") { mult = -1; } let text; if (!isNaN(Number(number))) { text = 1d20+${mult * Number(number)}; original = ${save} ${sign}${number}; } return { text, original };

Do you may have a different Version?

GladLantern commented 4 months ago

@Daniel-Leinberger thank you, it worked :) I had to copy/past the code in my custom layout json file.

valentine195 commented 4 months ago

Hey, the UX around this should be better. Could you please check?

GladLantern commented 4 months ago

@valentine195 I updated the plugin yesterday and yes, it works and the UX is clearer. Thank you !