diff --git a/README.adoc b/README.adoc index 06ed463c..f797daf2 100644 --- a/README.adoc +++ b/README.adoc @@ -562,7 +562,6 @@ All functions are case insensitiv. |max |`max(, ...)` |`max(4d6)` |returns the smallest elements (multiple if the smallest is not unique) of one or more inner expressions. Text is compared alphabetically |sort asc |`asc(, ...)` |`asc(4d6)` |sorts all elements ascending of one or more inner expressions. Text is compared alphabetically |sort desc |`desc(, ...)` |`desc(4d6)` |sorts all elements descending of one or more inner expressions. Text is compared alphabetically -|sort desc |`desc(, ...)` |`desc(4d6)` |sorts all elements descending of one or more inner expressions. Text is compared alphabetically |chancel |`chancel(, , )` |`chancel(8d10, 10, 1)` |the elements of listA and listB (can also be single elements) chancel each other and remove each other from the result. |replace |`replace(, , ...)` |`replace(8d10, [9/10], 'bonus')` | each element in `` that matches on of the elements in `` will be replaced with the elements in ``. `` can be an empty list `[]` or literal `''` and thereby removing the found elements. It is possible to add multiple / pairs to replace different elements in one replace. |if |`if(,,)` |`if(1d6=?6,'six','not six')` or `if(1d6=?6,'six')` or `val('$r',1d6), if('$r'=?1,'one','$r'=?2,'two','else') |if `` equal true then return the `` expression or else the `` expression. The `` expression is optional, if it is missing and `` is `false` then the result empty. It is possible to add more than `,` pair in the function, the result will be the `` of the first true ``, coming from left. All must be non-empty and contain only on element (therefor can't contain only `val`). `val` are will only set in the first . Use the following structure to use `if` to set different value in a `val`: `if(1d6>?4, val('$a',10), val('$a',-10))`, this will set '$a' to 10 if the 1d6 roll is bigger than 4 and to -10 otherwise. diff --git a/bot/build.gradle.kts b/bot/build.gradle.kts index f6ab5718..2efe5dc3 100644 --- a/bot/build.gradle.kts +++ b/bot/build.gradle.kts @@ -11,7 +11,7 @@ repositories { dependencies { implementation(project(":discord-connector")) implementation("com.github.twonirwana:dice-parser:0.7.1") - implementation("io.github.twonirwana:dice-evaluator:v0.5.1") + implementation("io.github.twonirwana:dice-evaluator:v0.5.2") implementation(libs.log4j.to.slf4j) implementation(libs.reactor.core) diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/DiceStyleAndColor.java b/bot/src/main/java/de/janno/discord/bot/dice/image/DiceStyleAndColor.java index a9e96375..ed6630ce 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/DiceStyleAndColor.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/DiceStyleAndColor.java @@ -1,6 +1,5 @@ package de.janno.discord.bot.dice.image; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Strings; import lombok.NonNull; @@ -41,11 +40,6 @@ public DiceStyleAndColor(@NonNull @JsonProperty("diceImageStyle") DiceImageStyle .orElse(configuredDefaultColor)); } - @JsonIgnore - public int getDieHighAndWith() { - return diceImageStyle.getImageProvider().getDieHighAndWide(); - } - @Override public String toString() { return DiceImageStyle.combineStyleAndColorName(diceImageStyle, configuredDefaultColor); diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/ImageResultCreator.java b/bot/src/main/java/de/janno/discord/bot/dice/image/ImageResultCreator.java index 70c84a20..0570dd07 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/ImageResultCreator.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/ImageResultCreator.java @@ -26,6 +26,7 @@ import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; @@ -161,9 +162,10 @@ private Supplier createNewFileForRoll(Roll roll, File fil ) .filter(l -> !l.isEmpty()) .toList(); - final int singleDiceSize = diceStyleAndColor.getDieHighAndWith(); + final int maxImageHight = images.stream().flatMap(Collection::stream) + .mapToInt(BufferedImage::getHeight).max().orElse(0); - BufferedImage separator = separatorImage.getUnchecked(singleDiceSize); + BufferedImage separator = separatorImage.getUnchecked(maxImageHight); ImmutableList.Builder builder = ImmutableList.builder(); for (int i = 0; i < images.size() - 1; i++) { builder.addAll(images.get(i)); @@ -179,7 +181,7 @@ private Supplier createNewFileForRoll(Roll roll, File fil final int numberOfImageLines = (int) Math.ceil(((double) allInOneLineWidth) / ((double) maxLineWidth)); final int w = Math.min(allInOneLineWidth, maxLineWidth); - final int h = singleDiceSize * numberOfImageLines; + final int h = maxImageHight * numberOfImageLines; BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); Graphics g = combined.getGraphics(); @@ -193,7 +195,7 @@ private Supplier createNewFileForRoll(Roll roll, File fil } else { currentLineWidth += image.getWidth(); } - g.drawImage(image, currentLineWidth - image.getWidth(), singleDiceSize * currentLine, image.getWidth(), singleDiceSize, null); + g.drawImage(image, currentLineWidth - image.getWidth(), maxImageHight * currentLine, image.getWidth(), image.getHeight(), null); } g.dispose(); diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/D6Dotted.java b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/D6Dotted.java index 7a6d610c..b6cb7bfc 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/D6Dotted.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/D6Dotted.java @@ -22,11 +22,6 @@ public D6Dotted() { .collect(ImmutableMap.toImmutableMap(Function.identity(), c -> new FileSidesDiceImageMap("d6_" + c, List.of(6)))); } - @Override - public int getDieHighAndWide() { - return 50; - } - @Override public @NonNull String getDefaultColor() { return WHITE; diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/FateBasic.java b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/FateBasic.java index 326b0735..75643856 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/FateBasic.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/FateBasic.java @@ -25,11 +25,6 @@ public FateBasic() { } } - @Override - public int getDieHighAndWide() { - return 50; - } - @Override public @NonNull String getDefaultColor() { return BLACK; diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/ImageProvider.java b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/ImageProvider.java index fa1a6399..461ab047 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/ImageProvider.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/ImageProvider.java @@ -10,8 +10,6 @@ public interface ImageProvider { @NonNull List getImageFor(Integer totalDieSides, Integer shownDieSide, @Nullable String color); - int getDieHighAndWide(); - @NonNull String getDefaultColor(); @NonNull List getSupportedColors(); diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/NoneProvider.java b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/NoneProvider.java index aba3c26a..be760a2a 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/NoneProvider.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/NoneProvider.java @@ -11,11 +11,6 @@ public final class NoneProvider implements ImageProvider { return List.of(); } - @Override - public int getDieHighAndWide() { - return 0; - } - @Override public @NonNull String getDefaultColor() { return "none"; diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralFileImageProvider.java b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralFileImageProvider.java index eb1def55..ae329e38 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralFileImageProvider.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralFileImageProvider.java @@ -30,11 +30,6 @@ public PolyhedralFileImageProvider(String styleFolder, List supportedCol this.supportedColors = supportedColors; } - @Override - public int getDieHighAndWide() { - return 100; - } - @Override public @NonNull String getDefaultColor() { return defaultColor; diff --git a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralSvgWithColor.java b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralSvgWithColor.java index ce62eebb..de54eb52 100644 --- a/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralSvgWithColor.java +++ b/bot/src/main/java/de/janno/discord/bot/dice/image/provider/PolyhedralSvgWithColor.java @@ -54,9 +54,9 @@ public class PolyhedralSvgWithColor implements ImageProvider { .put("magenta", Color.magenta) .put("cyan", Color.cyan) .put("blue", Color.blue) - .put("indigo", new Color( 75, 0, 130)) + .put("indigo", new Color(75, 0, 130)) .build(); - + private static final float IMAGE_SIZE = 100; @Override public @NonNull List getImageFor(Integer totalDieSides, Integer shownDieSide, String colorString) { @@ -103,8 +103,8 @@ private BufferedImage getImageAndSetNumberAndColor(Integer totalDieSides, String TranscoderInput transcoderInput = new TranscoderInput(IOUtils.toInputStream(svgString, StandardCharsets.UTF_8)); PNGTranscoder pngTranscoder = new PNGTranscoder(); - pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) getDieHighAndWide()); - pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) getDieHighAndWide()); + pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, IMAGE_SIZE); + pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, IMAGE_SIZE); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outputStream); @@ -121,11 +121,6 @@ private BufferedImage getImageAndSetNumberAndColor(Integer totalDieSides, String } } - @Override - public int getDieHighAndWide() { - return 100; - } - @Override public @NonNull String getDefaultColor() { return RED; diff --git a/bot/src/test/java/de/janno/discord/bot/dice/image/ImageResultCreatorTest.java b/bot/src/test/java/de/janno/discord/bot/dice/image/ImageResultCreatorTest.java index 62992a73..6b2edcd0 100644 --- a/bot/src/test/java/de/janno/discord/bot/dice/image/ImageResultCreatorTest.java +++ b/bot/src/test/java/de/janno/discord/bot/dice/image/ImageResultCreatorTest.java @@ -370,7 +370,7 @@ void getImageForRoll_d6DotsBlackAndGold() throws ExpressionException, IOExceptio Supplier res = underTest.getImageForRoll(rolls, new DiceStyleAndColor(DiceImageStyle.d6_dots, "black_and_gold")); assertThat(res).isNotNull(); - assertThat(getDataHash(res)).isEqualTo("d2cbedfb456d593a51fd5339c95b802ef1dc6157279083e4f9e947b86744226f"); + assertThat(getDataHash(res)).isEqualTo("acd0714a5dee4f9c3948933b194aa79786b5e4d46fd7e2d2c4386e7f90238527"); }