ebullient / ttrpg-convert-cli

Utility to convert JSON data (for content you own) from 5etools or pf2etools into Obsidian-friendly Markdown.
https://www.ebullient.dev/projects/ttrpg-convert-cli/
Apache License 2.0
197 stars 39 forks source link

PF2e Item Variants #173

Closed Caedis closed 1 year ago

Caedis commented 1 year ago

How difficult would it be to show variants of items like how PF2eTools shows them?

Also, if I wanted to attempt adding it and submitting a PR, how do you debug this project in jetbrains idea?

image

image

Example JSON codeblocks

{
            "name": "Goggles of Night",
            "source": "CRB",
            "page": 610,
            "type": "Item",
            "level": "5+",
            "traits": [
                "invested",
                "magical",
                "transmutation"
            ],
            "usage": "worn eyepiece",
            "bulk": "\u2014",
            "category": "Worn",
            "entries": [
                "The opaque crystal lenses of these sleek goggles do not obscure vision, but rather enhance it. While wearing the goggles, you gain a +1 item bonus to {@skill Perception} checks involving sight.",
                {
                    "type": "ability",
                    "style": "compact",
                    "activity": {
                        "number": 1,
                        "unit": "action"
                    },
                    "components": [
                        "{@action Interact}"
                    ],
                    "frequency": {
                        "unit": "day",
                        "number": 1
                    },
                    "entries": [
                        "Rotating the lenses 90 degrees, you gain {@ability darkvision} for 1 hour."
                    ]
                }
            ],
            "generic": "G",
            "variants": [
                {
                    "level": 5,
                    "price": {
                        "coin": "gp",
                        "amount": 150
                    },
                    "entries": [],
                    "variantType": "goggles of night"
                },
                {
                    "variantType": "greater goggles of night",
                    "level": 11,
                    "price": {
                        "coin": "gp",
                        "amount": 1250
                    },
                    "entries": [
                        "The item bonus is +2, and the {@ability darkvision} lasts until you rotate the lenses back or the item is no longer invested by you, whichever comes first."
                    ]
                },
                {
                    "variantType": "major goggles of night",
                    "level": 18,
                    "price": {
                        "coin": "gp",
                        "amount": 20000
                    },
                    "entries": [
                        "The item bonus is +3, and the goggles grant {@ability darkvision||greater darkvision}, which lasts until you rotate the lenses back or the item is no longer invested by you, whichever comes first."
                    ]
                }
            ]
},
{
            "name": "Healing Potion",
            "source": "CRB",
            "page": 563,
            "otherSources": {
                "Reprinted": [
                    "BB|52"
                ]
            },
            "type": "Item",
            "level": "1+",
            "traits": [
                "consumable",
                "healing",
                "magical",
                "necromancy",
                "potion"
            ],
            "usage": "held in 1 hand",
            "bulk": "L",
            "activate": {
                "activity": {
                    "number": 1,
                    "unit": "action"
                },
                "components": [
                    "{@action Interact}"
                ]
            },
            "category": "Potion",
            "entries": [
                "A healing potion is a vial of a ruby-red liquid that imparts a tingling sensation as the drinker's wounds heal rapidly. When you drink a healing potion, you regain the listed number of Hit Points."
            ],
            "generic": "G",
            "variants": [
                {
                    "variantType": "minor",
                    "level": 1,
                    "equipment": true,
                    "price": {
                        "coin": "gp",
                        "amount": 4
                    },
                    "entries": [
                        "The potion restores {@dice 1d8} Hit Points."
                    ],
                    "_mod": {
                        "entries": {
                            "with": "{@dice 1d8}"
                        }
                    }
                },
                {
                    "variantType": "lesser",
                    "level": 3,
                    "price": {
                        "coin": "gp",
                        "amount": 12
                    },
                    "entries": [
                        "The potion restores {@dice 2d8+5} Hit Points."
                    ],
                    "_mod": {
                        "entries": {
                            "with": "{@dice 2d8+5}"
                        }
                    }
                },
                {
                    "variantType": "moderate",
                    "level": 6,
                    "price": {
                        "coin": "gp",
                        "amount": 50
                    },
                    "entries": [
                        "The potion restores {@dice 3d8+10} Hit Points."
                    ],
                    "_mod": {
                        "entries": {
                            "with": "{@dice 3d8+10}"
                        }
                    }
                },
                {
                    "variantType": "greater",
                    "level": 12,
                    "price": {
                        "coin": "gp",
                        "amount": 400
                    },
                    "entries": [
                        "The potion restores {@dice 6d8+20} Hit Points."
                    ],
                    "_mod": {
                        "entries": {
                            "with": "{@dice 6d8+20}"
                        }
                    }
                },
                {
                    "variantType": "major",
                    "level": 18,
                    "price": {
                        "coin": "gp",
                        "amount": 5000
                    },
                    "entries": [
                        "The potion restores {@dice 8d8+30} Hit Points."
                    ],
                    "_mod": {
                        "entries": {
                            "with": "{@dice 8d8+30}"
                        }
                    }
                }
            ],
            "_vmod": {
                "entriesMode": "generic",
                "entries": {
                    "mode": "replaceTxt",
                    "replace": "the listed number of"
                }
            }
},
ebullient commented 1 year ago

Your willingness to attempt debugging is awesome. ;)

p2fe and 5e are two separate (but akin) code paths. The roads diverge at src/main/java/dev/ebullient/convert/tools .. (dnd5e and pf2e).

There is a crazy inheritance structure for parsing (and it is done recursively). JsonTextConverter (in tools itself) is extended in pf2e by JsonTextReplacement (which handles {@thing.. } and creating links), which itself is extended by JsonSource, which does most of the recursive parsing of entry text.

Within IntelliJ or VSCode, you can debug individual tests by type using tests from src/test/java/dev/ebullient/convert/tools/[dnd5e or pf2e]. There are three input variants (none: no sources (whatever the default is; subset: some sources; all: all the sources). These tests require content in a sources directory (a symlink to where you've cloned Pf2e data, or the cloned directory itself would work).

Go right to item processing to debug variants: src/main/java/dev/ebullient/convert/tools/pf2e/Json2QuteItem.java.. buildQuteResource is where the individual json entry is torn into a million pieces and set as template data.

Probably need to gather variants separately, and then.. send the data as an attribute to src/main/java/dev/ebullient/convert/tools/pf2e/qute/QuteItem.java, or merge it sensibly with other text headed that way. I'll let you see what feels right. ;)

Let me know if you have questions. ;)

Caedis commented 1 year ago

Thanks!

Do you have any ideas on how to handle linking to item variants?

ebullient commented 1 year ago

That is a good question. Have to look at how items are referenced in text (for when a variant should be used), and then: we either need sub-headings (###) or a block reference (^...) to link to the right place.

This is probably why I didn't do then out of the gate.. I wasn't sure which would work better.. a heading or a block reference, especially as I am not encumbered by making markdown look like a book. (I would go for a sub-heading first)

Caedis commented 1 year ago

Good thing I already have the variants in my PR as sub-headings