Skip to content

Commit

Permalink
🎨 Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
miscoined committed Jun 5, 2024
1 parent a539349 commit c287b08
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import static dev.ebullient.convert.StringUtil.toTitleCase;

import java.util.Collection;

import dev.ebullient.convert.StringUtil;
import io.quarkus.qute.TemplateExtension;

import java.util.Collection;

@TemplateExtension
public class TtrpgTemplateExtension {
/** Return the value formatted with a bonus with a +/- prefix */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package dev.ebullient.convert.tools.pf2e;

import static dev.ebullient.convert.StringUtil.join;
import static dev.ebullient.convert.StringUtil.parenthesize;

import java.util.Set;

import com.fasterxml.jackson.databind.JsonNode;

import dev.ebullient.convert.tools.Tags;
import dev.ebullient.convert.tools.pf2e.qute.QuteAbility;

import java.util.Set;

public class Json2QuteAbility extends Json2QuteBase {

public Json2QuteAbility(Pf2eIndex index, Pf2eIndexType type, JsonNode rootNode) {
Expand All @@ -21,8 +24,6 @@ protected QuteAbility buildQuteNote() {
public enum Pf2eAbility implements Pf2eJsonNodeReader {
/** e.g. {@code "Dirty Bomb"} */
name,
/** @see dev.ebullient.convert.tools.pf2e.Json2QuteAction.ActionType */
actionType, // TODO
/** @see Pf2eActivity */
activity,
/**
Expand All @@ -39,9 +40,9 @@ public enum Pf2eAbility implements Pf2eJsonNodeReader {
/**
* If present this is a generic ability, defined further in a standalone note.
*
* @see Pf2eAbilityGeneric
* @see Pf2eGenericAbilityReference
*/
generic, // TODO
generic,
/** e.g. {@code "The corpselight is in wisp form and is adjacent to a Medium corpse"} */
prerequisites,
/** How to display this block, {@code "compact"} or {@code "full"} */
Expand All @@ -66,12 +67,17 @@ private static QuteAbility createAbility(JsonNode node, JsonSource convert, Pf2e
Tags tags = new Tags();
Set<String> traits = convert.collectTraitsFrom(node, tags);

if (!entries.isArrayIn(node) && !generic.isObjectIn(node) && !actionType.isObjectIn(node)) {
convert.tui().debugf("No ability text or link for %s", node.toPrettyString());
if (!entries.isArrayIn(node) && !generic.isObjectIn(node)) {
convert.tui().debugf("missing %s (%s)", name.getTextOrEmpty(node), node);
}

if (generic.isObjectIn(node) && !generic.getLinkFrom(node, convert).contains(".md")) {
convert.tui().debugf("generic %s (%s)", generic.getFrom(node), name.getTextOrEmpty(node), node);
}

return new QuteAbility(sources,
name.getTextFrom(node).map(convert::replaceText).orElse("Activate"),
generic.getLinkFrom(node, convert),
entries.transformTextFrom(node, "\n", convert),
tags,
traits,
Expand All @@ -94,9 +100,29 @@ public static QuteAbility createEmbeddedAbility(JsonNode node, JsonSource conver
return createAbility(node, convert, null);
}

// TODO
enum Pf2eAbilityGeneric {
public String getLinkFrom(JsonNode node, JsonSource convert) {
return getObjectFrom(node)
.map(n -> convert.linkify(
Pf2eGenericAbilityReference.tag.getEnumValueFrom(n, Pf2eIndexType.class),
join("|",
Pf2eGenericAbilityReference.name.getTextFrom(n)
.or(() -> name.getTextFrom(node))
// Add the hash as a parenthesized string after the name
.map(s -> s + Pf2eGenericAbilityReference.add_hash.getTextFrom(n)
.map(hash -> " " + parenthesize(hash)).orElse(""))
.orElse(null),
Pf2eGenericAbilityReference.source.getTextOrNull(n))))
.orElse(null);
}

private enum Pf2eGenericAbilityReference implements Pf2eJsonNodeReader {
/** An extra string to add to an ability for finding its link, e.g. {@code "Rogue"} */
add_hash,
/** e.g. {@code "Curse of the Werecreature"}, or {@code "Nimble Dodge (Rogue)"} */
name,
/** The type of the resource, e.g. {@code "ability"} or {@code "feat"} */
tag,
/** The source, e.g. {@code "B1"} */
source;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
@TemplateData
public final class QuteAbility extends Pf2eQuteNote implements QuteUtil.Renderable, QuteAbilityOrAffliction {

/** A formatted string which is a link to the base ability that this ability references. Embedded only. */
public final String reference;
/**
* Collection of trait links. Use `{#for}` or `{#each}` to iterate over the collection.
* See <a href="#traitlist">traitList</a> or <a href="#baretraitlist">bareTraitList</a>.
Expand Down Expand Up @@ -66,13 +68,14 @@ public final class QuteAbility extends Pf2eQuteNote implements QuteUtil.Renderab
// Internal only.
private final JsonSource _converter;

public QuteAbility(Pf2eSources sources, String name, String text, Tags tags,
public QuteAbility(Pf2eSources sources, String name, String reference, String text, Tags tags,
Collection<String> traits, QuteDataActivity activity, QuteDataRange range,
List<String> components, String requirements, String prerequisites,
String cost, String trigger, QuteDataFrequency frequency, String special, String note,
boolean embedded, JsonSource converter) {
super(Pf2eIndexType.ability, sources, name, text, tags);

this.reference = reference;
this.traits = traits;
this.activity = activity;
this.range = range;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```ad-embed-ability
{#if resource.hasDetails }
title: **{resource.name}** {resource.activity}{resource.components.join(", ").prefixSpace}{#if resource.traits} ({resource.bareTraitList}){/if}
title: **{#if resource.reference}{resource.reference}{#else}{resource.name}{/if}** {resource.activity}{resource.components.join(", ").prefixSpace}{#if resource.traits} ({resource.bareTraitList}){/if}
{#if resource.note}
> [!pf2-note]
> {resource.note}
Expand Down

0 comments on commit c287b08

Please sign in to comment.