javalent / fantasy-statblocks

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

[bug] In custom layout renamed spells property is broken in code #138

Closed Zorgatone closed 1 year ago

Zorgatone commented 1 year ago

I have a custom layout for a statblock in italian. I also renamed the properties, so the spells field in the YAML code is "incantesimi".

Here's the relevant portion of the data.json configuration:

{
  "type": "spells",
  "id": "ea084ae8a9ca",
  "properties": [
    "incantesimi"
  ],
  "conditioned": true,
  "dice": true
}

But this doesn't seem to be handled correctly in the plugin js code, and it breaks on this line:

image

TypeError: Cannot read properties of undefined (reading 'reduce')

It tries to access a property "spells" on the object, instead of reading that field name from the configuration of the layout (in my case "incantesimi")

Here's the rest of relevant information:

Obsidian v1.1.9 and TTRPG Statblocks v2.24.19 on Windows 10.

data.json:

{
  "monsters": [],
  "layouts": [
    {
      "blocks": [
        {
          "type": "inline",
          "id": "b8089ad83baa",
          "properties": [],
          "hasRule": true,
          "nested": [
            {
              "type": "group",
              "id": "699a09abb8fb",
              "properties": [
                "nome",
                "taglia",
                "razza",
                "sottorazza",
                "allineamento"
              ],
              "nested": [
                {
                  "type": "heading",
                  "id": "495aa88809ea",
                  "properties": [
                    "nome"
                  ],
                  "conditioned": true,
                  "fallback": "-"
                },
                {
                  "type": "subheading",
                  "id": "89081a991aa8",
                  "properties": [
                    "razza",
                    "taglia",
                    "sottorazza",
                    "allineamento"
                  ],
                  "conditioned": true
                }
              ],
              "conditioned": true
            },
            {
              "type": "image",
              "id": "bae928da48a9",
              "properties": [
                "image"
              ]
            }
          ]
        },
        {
          "type": "group",
          "id": "7aa99a388b5b",
          "properties": [
            "ca",
            "pf",
            "velocita"
          ],
          "nested": [
            {
              "type": "property",
              "id": "383b3b58682a",
              "properties": [
                "ca"
              ],
              "display": "Classe Armatura",
              "conditioned": true
            },
            {
              "type": "property",
              "id": "cbbb99681839",
              "properties": [
                "pf"
              ],
              "display": "Punti Ferita",
              "dice": true,
              "diceProperty": "dadi_vita",
              "diceCallback": "return [{ text: monster[\"dadi_vita\"] }]",
              "conditioned": true
            },
            {
              "type": "property",
              "id": "99fb28d8e8eb",
              "display": "Velocità",
              "properties": [
                "velocita"
              ],
              "conditioned": true
            }
          ],
          "hasRule": true,
          "conditioned": true
        },
        {
          "type": "table",
          "id": "89aa0b28bb49",
          "properties": [
            "punteggi_caratteristica"
          ],
          "headers": [
            "FOR",
            "DES",
            "COS",
            "INT",
            "SAG",
            "CAR"
          ],
          "calculate": true,
          "hasRule": true,
          "conditioned": true
        },
        {
          "type": "group",
          "id": "b84be92b18b8",
          "properties": [
            "tiri_salvezza",
            "abilita",
            "immunita_danni",
            "resistenza_danni",
            "vulnerabilita_danni",
            "immunita_condizioni",
            "gs",
            "linguaggi",
            "sensi"
          ],
          "nested": [
            {
              "type": "saves",
              "id": "e8194b1a4949",
              "display": "Tiri Salvezza",
              "properties": [
                "tiri_salvezza"
              ],
              "conditioned": true
            },
            {
              "type": "saves",
              "id": "5b29c88b889b",
              "display": "Abilità",
              "properties": [
                "abilita"
              ],
              "conditioned": true
            },
            {
              "type": "property",
              "id": "49299af93bf9",
              "display": "Resistenze ai Danni",
              "properties": [
                "resistenza_danni"
              ],
              "conditioned": true
            },
            {
              "type": "property",
              "id": "a82ab9ebcba8",
              "display": "Immunità ai Danni",
              "properties": [
                "immunita_danni"
              ],
              "conditioned": true
            },
            {
              "type": "property",
              "id": "a909cad8f938",
              "display": "Immunità alle Condizioni",
              "properties": [
                "immunita_condizioni"
              ],
              "conditioned": true
            },
            {
              "type": "property",
              "id": "7bcbc9e93848",
              "display": "Vulnerabilità ai Danni",
              "properties": [
                "vulnerabilita_danni"
              ],
              "conditioned": true
            },
            {
              "type": "property",
              "id": "1af89a08fb99",
              "display": "Sensi",
              "properties": [
                "sensi"
              ],
              "conditioned": true
            },
            {
              "type": "property",
              "id": "09b8ebc9ebb8",
              "display": "Linguaggi",
              "properties": [
                "linguaggi"
              ],
              "fallback": "-"
            },
            {
              "type": "inline",
              "id": "3b5b4899da18",
              "properties": [],
              "conditioned": true,
              "nested": [
                {
                  "type": "property",
                  "id": "7b9a7a79cb79",
                  "display": "Sfida",
                  "properties": [
                    "gs"
                  ],
                  "callback": "const e={0:{gs:\"0\",valore:0,pe:0},\"1/8\":{gs:\"1/8\",valore:.125,pe:25},\"1/4\":{gs:\"1/4\",valore:.25,pe:50},\"1/2\":{gs:\"1/2\",valore:.5,pe:100},.125:{gs:\"1/8\",valore:.125,pe:25},.25:{gs:\"1/4\",valore:.25,pe:50},.5:{gs:\"1/2\",valore:.5,pe:100},1:{gs:\"1\",valore:1,pe:200},2:{gs:\"2\",valore:2,pe:450},3:{gs:\"3\",valore:3,pe:700},4:{gs:\"4\",valore:4,pe:1100},5:{gs:\"5\",valore:5,pe:1800},6:{gs:\"6\",valore:6,pe:2300},7:{gs:\"7\",valore:7,pe:2900},8:{gs:\"8\",valore:8,pe:3900},9:{gs:\"9\",valore:9,pe:5e3},10:{gs:\"10\",valore:10,pe:5900},11:{gs:\"11\",valore:11,pe:7200},12:{gs:\"12\",valore:12,pe:8400},13:{gs:\"13\",valore:13,pe:1e4},14:{gs:\"14\",valore:14,pe:11500},15:{gs:\"15\",valore:15,pe:13e3},16:{gs:\"16\",valore:16,pe:15e3},17:{gs:\"17\",valore:17,pe:18e3},18:{gs:\"18\",valore:18,pe:2e4},19:{gs:\"19\",valore:19,pe:22e3},20:{gs:\"20\",valore:20,pe:25e3},21:{gs:\"21\",valore:21,pe:33e3},22:{gs:\"22\",valore:22,pe:41e3},23:{gs:\"23\",valore:23,pe:5e4},24:{gs:\"24\",valore:24,pe:62e3},25:{gs:\"25\",valore:25,pe:75e3},26:{gs:\"26\",valore:26,pe:9e4},27:{gs:\"27\",valore:27,pe:105e3},28:{gs:\"28\",valore:28,pe:12e4},29:{gs:\"29\",valore:29,pe:135e3},30:{gs:\"30\",valore:30,pe:155e3}};return\"gs\"in monster&&monster.gs in e?`${e[monster.gs].gs} (${e[monster.gs].pe.toLocaleString('it-IT')} PE)`:\"\""
                },
                {
                  "type": "property",
                  "id": "6b28e8ea488a",
                  "display": "Bonus di Competenza",
                  "properties": [
                    "gs"
                  ],
                  "callback": "const GS={0:0,\"1/8\":.125,\"1/4\":.25,\"1/2\":.5,.125:.125,.25:.25,.5:.5,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,10:10,11:11,12:12,13:13,14:14,15:15,16:16,17:17,18:18,19:19,20:20,21:21,22:22,23:23,24:24,25:25,26:26,27:27,28:28,29:29,30:30};if(\"gs\"in monster&&monster.gs in GS){const bc=Math.max(Math.floor(2+((GS[monster.gs]??0)-1)/4),2);return`+${bc}`}return\"\""
                }
              ]
            }
          ],
          "conditioned": true,
          "hasRule": true
        },
        {
          "type": "traits",
          "id": "c9c9ebc9485b",
          "properties": [
            "tratti"
          ],
          "conditioned": true,
          "dice": true
        },
        {
          "type": "spells",
          "id": "ea084ae8a9ca",
          "properties": [
            "incantesimi"
          ],
          "conditioned": true,
          "dice": true
        },
        {
          "type": "traits",
          "id": "f95a0b89bb78",
          "properties": [
            "azioni"
          ],
          "heading": "Azioni",
          "conditioned": true,
          "dice": true
        },
        {
          "type": "traits",
          "id": "da29f899286b",
          "properties": [
            "azioni_leggendarie"
          ],
          "heading": "Azioni Leggendarie",
          "conditioned": true,
          "dice": true
        },
        {
          "type": "traits",
          "id": "98b908885b58",
          "properties": [
            "reazioni"
          ],
          "heading": "Reazioni",
          "conditioned": true,
          "dice": true
        }
      ],
      "name": "5e Base Italiano"
    }
  ],
  "default": "Basic 5e Layout",
  "useDice": true,
  "renderDice": false,
  "export": true,
  "showAdvanced": true,
  "version": {
    "major": 2,
    "minor": 24,
    "patch": 19
  },
  "paths": [
    "/"
  ],
  "autoParse": false,
  "disableSRD": false,
  "tryToRenderLinks": true,
  "debug": false,
  "path": "/"
}

The obsidian YAML code for the statblock used:

#```statblock
columnWidth: , #hack: for some reason this makes the statblock take the full width of the page
render: true
layout: 5e Base Italiano
nome: Accolito
razza: Umanoide
taglia: "Medio (qualsiasi razza),"
allineamento: qualsiasi allineamento
ca: 10
pf: 9
dadi_vita: 2d8
velocita: 9 m
punteggi_caratteristica: [10, 10, 10, 10, 14, 11]
abilita:
  - Medicina: 4
  - Religione: 2
sensi: Percezione passiva 12
linguaggi: uno qualsiasi (di solito il Comune)
gs: 1/4
incantesimi:
  - "L'accolito è un incantatore di 1° livello: la sua caratteristica da incantatore è Saggezza (tiro salvezza degli incantesimi CD 12, +4 al tiro per colpire con degli attacchi con incantesimo). Ha preparato i seguenti incantesimi da chierico:"
  - Trucchetti (a volontà): "fiamma sacra, luce, taumaturgia"
  - 1° livello (3 slot): "benedizione, cura ferite, santuario"
#```
Zorgatone commented 1 year ago

As a side note, I also tried to customize the text shown when rendered, instead of "Spellcasting" "Incantesimi", but I could't get it to work even with the property name "spells"

I tried both with the "display" attribute and "heading" attribute but none worked.

{
  "type": "spells",
  "id": "ea084ae8a9ca",
  "display": "Incantesimi",
  "properties": [
    "spells"
  ],
  "conditioned": true,
  "dice": true
}
{
  "type": "spells",
  "id": "ea084ae8a9ca",
  "properties": [
    "spells"
  ],
  "heading": "Incantesimi",
  "conditioned": true,
  "dice": true
}
sigrunixia commented 1 year ago

Hi @Zorgatone. We're about to look at innate spell casting again and I wanted to check if you still had issues with this?

valentine195 commented 1 year ago

@Zorgatone this is fixed.

I also added in the ability to override the Spellcasting trait name:

image