-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ 🐉 Pf2e Bestiary * Add ability to export creatures with the CLI tool - just the name and level for now * Add defenses export to Pf2e creature support * Add support for perception to pf2e creature * Put AC note text in "notes" through tokenization Previously only note text in the "note" key was tokenized. This makes tests fail in creature stat blocks, which use e.g. ac: "notes": "{@spell mage armor}" * Add a creature2md template file * Add tests for the creature type * Add `std` as an enum type rather than using the string directly. * Add support for parsing languages for creatures. Added a `CreatureLanguages` type as an intermediate object to hold the language data. Not sure whether this is the desired style for these helper classes, or whether I should be prefacing the names with `Qute` and putting them in e.g. `QuteCreature` instead. * Move CreatureLanguages into QuteCreature, and fix up generated documentation. Add support for `MarkdownDoclet` to correctly format and parse record components. This was actually a pain to figure out, as it turns out that these aren't accessible as an Element and instead have to be parsed through the @param tags of the class comment. * Add support for skills to the creature importer * Collapse spaces in docstrings Prevents docstring spacing from rendering weird in markdown (such as indentation in @param tags) * Add a ^statblock block tag to the default creature template Also fix some import order formatting that I accidentally changed earlier. * Add support for parsing languages for creatures. Add support for `MarkdownDoclet` to correctly format and parse record components. This was actually a pain to figure out, as it turns out that these aren't accessible as an Element and instead have to be parsed through the @param tags of the class comment. * Use admonition block in the creature2md template
- Loading branch information
Showing
17 changed files
with
557 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# QuteCreature | ||
|
||
Pf2eTools Creature attributes (`creature2md.txt`) | ||
|
||
Use `%%--` to mark the end of the preamble (frontmatter and other leading content only appropriate to the standalone case). | ||
|
||
Extension of [Pf2eQuteBase](Pf2eQuteBase.md) | ||
|
||
## Attributes | ||
|
||
[aliases](#aliases), [defenses](#defenses), [description](#description), [hasSections](#hassections), [labeledSource](#labeledsource), [level](#level), [name](#name), [perception](#perception), [source](#source), [sourceAndPage](#sourceandpage), [tags](#tags), [text](#text), [traits](#traits), [vaultPath](#vaultpath) | ||
|
||
|
||
### aliases | ||
|
||
Aliases for this note (optional) | ||
|
||
### defenses | ||
|
||
Defenses (AC, saves, etc) as [QuteDataDefenses](QuteDataDefenses.md) | ||
|
||
### description | ||
|
||
Short creature description (optional) | ||
|
||
### hasSections | ||
|
||
True if the content (text) contains sections | ||
|
||
### labeledSource | ||
|
||
Formatted string describing the content's source(s): `_Source: <sources>_` | ||
|
||
### level | ||
|
||
Creature level (number, optional) | ||
|
||
### name | ||
|
||
Note name | ||
|
||
### perception | ||
|
||
Creature perception (number, optional) | ||
|
||
### source | ||
|
||
String describing the content's source(s) | ||
|
||
### sourceAndPage | ||
|
||
Book sources as list of [SourceAndPage](../SourceAndPage.md) | ||
|
||
### tags | ||
|
||
Collected tags for inclusion in frontmatter | ||
|
||
### text | ||
|
||
Formatted text. For most templates, this is the bulk of the content. | ||
|
||
### traits | ||
|
||
Collection of traits (decorated links, optional) | ||
|
||
### vaultPath | ||
|
||
Path to this note in the vault |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
src/main/java/dev/ebullient/convert/tools/pf2e/Json2QuteCreature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package dev.ebullient.convert.tools.pf2e; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import dev.ebullient.convert.tools.JsonNodeReader; | ||
import dev.ebullient.convert.tools.Tags; | ||
import dev.ebullient.convert.tools.pf2e.qute.QuteCreature; | ||
import dev.ebullient.convert.tools.pf2e.qute.QuteDataDefenses; | ||
|
||
public class Json2QuteCreature extends Json2QuteBase { | ||
|
||
public Json2QuteCreature(Pf2eIndex index, JsonNode rootNode) { | ||
super(index, Pf2eIndexType.creature, rootNode); | ||
} | ||
|
||
@Override | ||
protected QuteCreature buildQuteResource() { | ||
List<String> text = new ArrayList<>(); | ||
Tags tags = new Tags(sources); | ||
|
||
appendToText(text, SourceField.entries.getFrom(rootNode), "##"); | ||
|
||
Collection<String> traits = collectTraitsFrom(rootNode, tags); | ||
if (Pf2eCreature.alignment.existsIn(rootNode)) { | ||
traits.addAll(toAlignments(rootNode, Pf2eCreature.alignment)); | ||
} | ||
Optional<Integer> level = Pf2eCreature.level.getIntFrom(rootNode); | ||
|
||
return new QuteCreature(sources, text, tags, | ||
traits, | ||
Field.alias.replaceTextFromList(rootNode, this), | ||
Pf2eCreature.description.replaceTextFrom(rootNode, this), | ||
level.orElse(null), | ||
getPerception(), | ||
buildDefenses(), | ||
Pf2eCreatureLanguages.createCreatureLanguages(Pf2eCreature.languages.getFrom(rootNode), this), | ||
buildSkills()); | ||
} | ||
|
||
/** | ||
* Example JSON input: | ||
* | ||
* <pre> | ||
* "perception": { | ||
* "std": 6 | ||
* } | ||
* </pre> | ||
*/ | ||
private Integer getPerception() { | ||
JsonNode perceptionNode = Pf2eCreature.perception.getFrom(rootNode); | ||
if (perceptionNode == null || !perceptionNode.isObject()) { | ||
return null; | ||
} | ||
return Pf2eCreature.std.getIntOrThrow(perceptionNode); | ||
} | ||
|
||
/** | ||
* Example JSON input: | ||
* | ||
* <pre> | ||
* "defenses": { ... } | ||
* </pre> | ||
*/ | ||
private QuteDataDefenses buildDefenses() { | ||
JsonNode defenseNode = Pf2eCreature.defenses.getFrom(rootNode); | ||
if (defenseNode == null || !defenseNode.isObject()) { | ||
return null; | ||
} | ||
return Pf2eDefenses.createInlineDefenses(defenseNode, this); | ||
} | ||
|
||
/** | ||
* Example JSON input: | ||
* | ||
* <pre> | ||
* "skills": { | ||
* "athletics": 30, | ||
* "stealth": { | ||
* "std": 36, | ||
* "in forests": 42, | ||
* "note": "additional note" | ||
* }, | ||
* "notes": [ | ||
* "some note" | ||
* ] | ||
* } | ||
* </pre> | ||
*/ | ||
private QuteCreature.CreatureSkills buildSkills() { | ||
JsonNode skillsNode = Pf2eCreature.skills.getFrom(rootNode); | ||
if (skillsNode == null || !skillsNode.isObject()) { | ||
return null; | ||
} | ||
return new QuteCreature.CreatureSkills( | ||
skillsNode.properties().stream() | ||
.filter(e -> !e.getKey().equals(Pf2eCreature.notes.name())) | ||
.map(e -> Pf2eTypeReader.Pf2eSkillBonus.createSkillBonus(e.getKey(), e.getValue(), this)) | ||
.toList(), | ||
Pf2eCreature.notes.replaceTextFromList(rootNode, this)); | ||
} | ||
|
||
/** | ||
* Example JSON input: | ||
* | ||
* <pre> | ||
* "languages": { | ||
* "languages": ["Common", "Sylvan"], | ||
* "abilities": ["{@ability telepathy} 100 feet"], | ||
* "notes": ["some other notes"], | ||
* } | ||
* </pre> | ||
*/ | ||
enum Pf2eCreatureLanguages implements JsonNodeReader { | ||
languages, | ||
abilities, | ||
notes; | ||
|
||
static QuteCreature.CreatureLanguages createCreatureLanguages(JsonNode node, Pf2eTypeReader convert) { | ||
if (node == null) { | ||
return null; | ||
} | ||
return new QuteCreature.CreatureLanguages( | ||
languages.getListOfStrings(node, convert.tui()), | ||
abilities.getListOfStrings(node, convert.tui()).stream().map(convert::replaceText).toList(), | ||
notes.getListOfStrings(node, convert.tui()).stream().map(convert::replaceText).toList()); | ||
} | ||
} | ||
|
||
enum Pf2eCreature implements JsonNodeReader { | ||
abilities, | ||
abilityMods, | ||
alignment, | ||
attacks, | ||
defenses, | ||
description, | ||
hasImages, | ||
inflicts, | ||
isNpc, | ||
items, | ||
languages, | ||
level, | ||
notes, | ||
perception, | ||
rarity, | ||
rituals, | ||
senses, | ||
size, | ||
skills, | ||
speed, | ||
spellcasting, | ||
std, | ||
traits, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.