Skip to content

Commit

Permalink
✨ Item costCp attribute (as number)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Jan 14, 2024
1 parent 42b83c0 commit 9508a1f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
6 changes: 5 additions & 1 deletion docs/templates/dnd5e/QuteItem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Extension of [Tools5eQuteBase](../Tools5eQuteBase.md).

## Attributes

[armorClass](#armorclass), [cost](#cost), [damage](#damage), [damage2h](#damage2h), [detail](#detail), [fluffImages](#fluffimages), [hasSections](#hassections), [labeledSource](#labeledsource), [name](#name), [prerequisite](#prerequisite), [properties](#properties), [range](#range), [source](#source), [sourceAndPage](#sourceandpage), [stealthPenalty](#stealthpenalty), [strengthRequirement](#strengthrequirement), [tags](#tags), [text](#text), [variantAliases](#variantaliases), [variantSectionLinks](#variantsectionlinks), [variants](#variants), [vaultPath](#vaultpath), [weight](#weight)
[armorClass](#armorclass), [cost](#cost), [costCp](#costcp), [damage](#damage), [damage2h](#damage2h), [detail](#detail), [fluffImages](#fluffimages), [hasSections](#hassections), [labeledSource](#labeledsource), [name](#name), [prerequisite](#prerequisite), [properties](#properties), [range](#range), [source](#source), [sourceAndPage](#sourceandpage), [stealthPenalty](#stealthpenalty), [strengthRequirement](#strengthrequirement), [tags](#tags), [text](#text), [variantAliases](#variantaliases), [variantSectionLinks](#variantsectionlinks), [variants](#variants), [vaultPath](#vaultpath), [weight](#weight)


### armorClass
Expand All @@ -17,6 +17,10 @@ Changes to armor class provided by the item, if applicable

Cost of the item (gp, sp, cp). Usually missing for magic items.

### costCp

Cost of the item (cp) as number. Usually missing for magic items.

### damage

One-handed Damage string, if applicable. Contains dice formula and damage type
Expand Down
6 changes: 5 additions & 1 deletion docs/templates/dnd5e/QuteItem/Variant.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Attributes

[armorClass](#armorclass), [cost](#cost), [damage](#damage), [damage2h](#damage2h), [name](#name), [prerequisite](#prerequisite), [properties](#properties), [range](#range), [stealthPenalty](#stealthpenalty), [strengthRequirement](#strengthrequirement), [weight](#weight)
[armorClass](#armorclass), [cost](#cost), [costCp](#costcp), [damage](#damage), [damage2h](#damage2h), [name](#name), [prerequisite](#prerequisite), [properties](#properties), [range](#range), [stealthPenalty](#stealthpenalty), [strengthRequirement](#strengthrequirement), [weight](#weight)


### armorClass
Expand All @@ -14,6 +14,10 @@ Changes to armor class provided by the item, if applicable

Cost of the item (gp, sp, cp). Usually missing for magic items.

### costCp

Cost of the item (cp) as number. Usually missing for magic items.

### damage

One-handed Damage string, if applicable. Contains dice formula and damage type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected Tools5eQuteBase buildQuteResource() {
rootVariant.strengthRequirement,
rootVariant.stealthPenalty,
rootVariant.cost,
rootVariant.costCp,
rootVariant.weight,
rootVariant.prerequisite,
text,
Expand Down Expand Up @@ -111,12 +112,13 @@ private Variant createVariant(JsonNode variantNode, Set<ItemProperty> itemProper
properties,
strength,
booleanOrDefault(variantNode, "stealth", false),
gpValue(variantNode),
coinValue(variantNode),
ItemFields.value.getIntFrom(variantNode).orElse(null), // cpValue
weight,
listPrerequisites(variantNode));
}

private String gpValue(JsonNode variantNode) {
private String coinValue(JsonNode variantNode) {
if (variantNode.has("value")) {
return convertCurrency(variantNode.get("value").asInt());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class QuteItem extends Tools5eQuteBase {
public final boolean stealthPenalty;
/** Cost of the item (gp, sp, cp). Usually missing for magic items. */
public final String cost;
/** Cost of the item (cp) as number. Usually missing for magic items. */
public final Integer costCp;
/** Weight of the item (pounds) as a decimal value */
public final Double weight;
/** List of images for this item (as {@link dev.ebullient.convert.qute.ImageRef}) */
Expand All @@ -49,7 +51,7 @@ public class QuteItem extends Tools5eQuteBase {
public QuteItem(Tools5eSources sources, String name, String source, String detail,
String armorClass, String damage, String damage2h,
String range, String properties, Integer strengthRequirement, boolean stealthPenalty,
String costGp, Double weightLbs, String prerequisite,
String costGp, Integer costCp, Double weightLbs, String prerequisite,
String text, List<ImageRef> images, List<Variant> variants, Tags tags) {
super(sources, name, source, text, tags);

Expand All @@ -62,6 +64,7 @@ public QuteItem(Tools5eSources sources, String name, String source, String detai
this.strengthRequirement = strengthRequirement;
this.stealthPenalty = stealthPenalty;
this.cost = costGp;
this.costCp = costCp;
this.weight = weightLbs;
this.fluffImages = images == null ? List.of() : images;
this.prerequisite = prerequisite; // optional
Expand Down Expand Up @@ -115,14 +118,16 @@ public static class Variant {
public final boolean stealthPenalty;
/** Cost of the item (gp, sp, cp). Usually missing for magic items. */
public final String cost;
/** Cost of the item (cp) as number. Usually missing for magic items. */
public final Integer costCp;
/** Weight of the item (pounds) as a decimal value */
public final Double weight;
/** Formatted text listing other prerequisite conditions (optional) */
public final String prerequisite;

public Variant(String name, String armorClass, String damage, String damage2h,
String range, String properties, Integer strengthRequirement, boolean stealthPenalty,
String costGp, Double weightLbs, String prerequisite) {
String cost, Integer costCp, Double weightLbs, String prerequisite) {
this.name = name;
this.armorClass = armorClass;
this.damage = damage;
Expand All @@ -131,7 +136,8 @@ public Variant(String name, String armorClass, String damage, String damage2h,
this.properties = properties;
this.strengthRequirement = strengthRequirement;
this.stealthPenalty = stealthPenalty;
this.cost = costGp;
this.cost = cost;
this.costCp = costCp;
this.weight = weightLbs;
this.prerequisite = prerequisite; // optional
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/dev/ebullient/convert/CustomTemplatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void setupDir() {
public static void setupDir(String root) {
tui = new Tui();
tui.init(null, false, false);
testOutput = TestUtils.OUTPUT_ROOT_PF2.resolve(root).resolve("test-cli");
testOutput = TestUtils.OUTPUT_ROOT_5E.resolve(root).resolve("test-cli");
testOutput.toFile().mkdirs();
}

Expand Down Expand Up @@ -158,6 +158,11 @@ void testCommandTemplates_5eJson(QuarkusMainLauncher launcher) {
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);

// test extra cp value attribute in yaml frontmatter
Path abacus = target.resolve("compendium/items/abacus.md");
assertThat(abacus).exists();
assertThat(abacus).content().contains("cost: 200");

List.of(
target.resolve("compendium/backgrounds"),
target.resolve("compendium/classes"),
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/other/item.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
obsidianUIMode: preview
cssclasses: json5e-item
{#if resource.costCp }
cost: {resource.costCp}
{/if}
tags:
- test
{#if resource.tags }{#for tag in resource.tags}
Expand Down

0 comments on commit 9508a1f

Please sign in to comment.