Skip to content

Commit

Permalink
Split image style and color (#276)
Browse files Browse the repository at this point in the history
* wip

* working and new style

* working and new style

* cleanup

* working

* fix custom parameter with long paramters and add doc

* add blue and dark style
  • Loading branch information
twonirwana authored May 31, 2023
1 parent cb5c5e3 commit 5dd7704
Show file tree
Hide file tree
Showing 842 changed files with 1,381 additions and 824 deletions.
98 changes: 47 additions & 51 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ image:image/minimal.png[image,320]

=== Dice Images

The `custom_dice`, `sum_custom_dice` and `custom_parameter` commands have an `result_image` option that can be configured to add an image of the rolled dice.
The `custom_dice`, `sum_custom_dice` and `custom_parameter` commands have a `dice_image_style` and a `dice_image_color` option that can be configured to add an image of the rolled dice.
The color of specific dice can be overwritten, with valid colors for the style, in the expression.
For example:

`/custom_dice start buttons: 2d6+color(2d10, 'red_and_gold')+color(2d20,'green_and_gold')@color roll answer_format: without_expression dice_image_style: polyhedral_alies_v2 dice_image_color: blue_and_gold`

produces:

image:image/colorRoll.png[image,320]

For the direct rolls it can be configured with the `channel_config` command.
The images will only be shown if the following conditions are met:

Expand All @@ -174,92 +183,78 @@ There are the following options:

No image will be shown.

==== polyhedral_3d_red_and_white
==== polyhedral_3d

image:image/3d_red_and_white.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100
Valid for d4, d6, d10, d8, d12, d20, d100 and the only supported color is: `red_and_white`

==== fate_black
==== fate

image:image/fate_image.png[image,360]

Valid for d[-1,1,1]
Valid for d[-1,1,1] and the only supported color is: `black`

==== d6_dots_white
==== d6_dots

image:image/d6White.png[image,360]

Valid for d6
Valid for d6 and the only supported color is: `white`

==== polyhedral_draw_color
==== polyhedral_2d

image:image/draw_color.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100.
Generates the dice images in the given color of the die (default is red).
The color of a die can be set with the `color` function.

The supported colors are: 'white', 'gray', 'black', 'red', 'pink', 'orange', 'yellow', 'green', 'magenta', 'cyan', 'blue'.

For example:
`color(1d4,'gray') + color(1d6,'black') + color(1d8,'white') + color(1d10,'red') + color(1d12,'blue') + color(1d20,'green') + color(1d100,'orange')` rolls each die type in another color.
Valid for d4, d6, d10, d8, d12, d20, d100 and the supported colors are: `white`, `gray`, `black`, `red`, `pink`, `orange`, `yellow`, `green`, `magenta`, `cyan`, `blue`.

==== polyhedral_black_and_gold
==== polyhedral_alies_v1

image:image/black_and_gold.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100.
Valid for d4, d6, d10, d8, d12, d20, d100 and the only supported color is: `black_and_gold`
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].

==== polyhedral_black_and_gold_v2

image:image/polyhedral_black_and_gold_v2.png[image,600]
==== polyhedral_alies_v2

Valid for d4, d6, d10, d8, d12, d20, d100.
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].
Valid for d4, d6, d10, d8, d12, d20, d100 and supported colors are: `black_and_gold`, `blue_and_silver`, `blue_and_gold`, `green_and_gold`, `orange_and_silver`, `red_and_gold`, `purple_and_silver`

==== polyhedral_alies_blue_and_silver
.black_and_gold
image:image/polyhedral_black_and_gold_v2.png[image,600]

.blue_and_silver
image:image/blue_and_silver.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100.
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].

==== polyhedral_green_and_gold

.green_and_gold
image:image/green_and_gold.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100.
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].

==== polyhedral_red_and_gold

.red_and_gold
image:image/red_and_gold.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100.
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].
.blue_and_gold
image:image/polyhedral_blue_and_gold.png[image,600]

==== polyhedral_blue_and_gold
.orange_and_silver
image:image/polyhedral_orange_and_silver.png[image,600]

image:image/polyhedral_blue_and_gold.png[image,600]
.purple_and_silver
image:image/polyhedral_purple_and_silver.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100.
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].

==== polyhedral_orange_and_silver
==== polyhedral_knots

image:image/polyhedral_orange_and_silver.png[image,600]
.blue
image:image/polyhedral_knots_blue.png[image,600]

Valid for d4, d6, d10, d8, d12, d20, d100.
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].
.purple_dark
image:image/polyhedral_knots_purple-dark.png[image,600]

==== polyhedral_purple_and_silver
.purple_white
image:image/polyhedral_knots_purple-white.png[image,600]

image:image/polyhedral_purple_and_silver.png[image,600]
Valid for d4, d6, d10, d8, d12, d20, d100 and the supported color is: `blue`, `purple_dark` and `purple_white`

Valid for d4, d6, d10, d8, d12, d20, d100.
This set was designed and contributed by https://www.instagram.com/alie_in_beanland/[alieinbeanland].
This set was designed and contributed by mailto:[email protected][Myrynvalona].

=== Custom Dice Buttons

Expand Down Expand Up @@ -467,7 +462,7 @@ The maximum are 23 buttons.
It is possible to add an optional label to each value in the format `value@label`.
For example `{bonus:0@None/3@Small Bonus/5@Big Bonus}` will show on the buttons 'None', 'Small Bonus' and 'Big Bonus' but apply the values 0, 3 or 5 to the expression

A expression can have up to 4 parameter.
An expression can have up to 4 parameter.
The user can click on the buttons to fill all open parameter of the expression.
If all parameter are selected then the expression will be rolled.
The first user that clicks on a button add his name to the message and only this user can select further parameter.
Expand Down Expand Up @@ -577,6 +572,7 @@ All functions are case insensitiv.

== Contributors

* Special thank to https://www.instagram.com/alie_in_beanland/[alieinbeanland ] for the design of the dice images.
* The `polyhedral_3d_red_and_white` dice images where adapted from https://blendswap.com/blend/16634
* The `d6_dots_white` dice images are from https://game-icons.net/
* Special thank to https://www.instagram.com/alie_in_beanland/[alieinbeanland] for the design of the dice images for `polyhedral_alies_v1` and `polyhedral_alies_v2`
* Special thank to mailto:[email protected][Myrynvalona] for the design of the dice images for `polyhedral_knots`
* The `polyhedral_3d` dice images where adapted from https://blendswap.com/blend/16634
* The `d6_dot` dice images are from https://game-icons.net/
5 changes: 3 additions & 2 deletions bot/src/main/java/de/janno/discord/bot/BotMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sun.net.httpserver.SimpleFileServer;
import de.janno.discord.bot.command.AnswerFormatType;
import de.janno.discord.bot.dice.DiceParserSystem;
import de.janno.discord.bot.dice.image.DiceStyleAndColor;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.Timer;
Expand Down Expand Up @@ -126,8 +127,8 @@ public static void incrementImageResultMetricCounter(@NonNull CacheTag tag) {
}


public static void incrementUseImageResultMetricCounter(@NonNull ResultImage resultImage) {
globalRegistry.counter(METRIC_PREFIX + METRIC_USE_IMAGE_RESULT_PREFIX, Tags.of(IMAGE_RESULT_TAG, resultImage.name())).increment();
public static void incrementUseImageResultMetricCounter(@NonNull DiceStyleAndColor resultImage) {
globalRegistry.counter(METRIC_PREFIX + METRIC_USE_IMAGE_RESULT_PREFIX, Tags.of(IMAGE_RESULT_TAG, resultImage.toString())).increment();
}

public static void incrementAliasUseMetricCounter(@NonNull String type, @NonNull String alias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import de.janno.discord.bot.BotMetrics;
import de.janno.discord.bot.ResultImage;
import de.janno.discord.bot.persistance.Mapper;
import de.janno.discord.bot.persistance.MessageConfigDTO;
import de.janno.discord.bot.persistance.MessageDataDTO;
Expand All @@ -31,7 +30,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static de.janno.discord.bot.command.DefaultCommandOptions.*;
import static de.janno.discord.bot.command.BaseCommandOptions.*;
import static de.janno.discord.connector.api.BottomCustomIdUtils.CUSTOM_ID_DELIMITER;

@Slf4j
Expand All @@ -58,11 +57,6 @@ protected Set<String> getStartOptionIds() {
return Set.of(ACTION_START);
}


protected ResultImage defaultResultImage() {
return ResultImage.polyhedral_3d_red_and_white;
}

protected AnswerFormatType defaultAnswerFormat() {
return AnswerFormatType.full;
}
Expand All @@ -85,7 +79,8 @@ public boolean matchingComponentCustomId(@NonNull String buttonCustomId) {
baseOptions.add(ANSWER_FORMAT_COMMAND_OPTION);
}
if (supportsResultImages()) {
baseOptions.add(RESULT_IMAGE_COMMAND_OPTION);
baseOptions.add(DICE_IMAGE_STYLE_COMMAND_OPTION);
baseOptions.add(DICE_IMAGE_COLOR_COMMAND_OPTION);
}
return CommandDefinition.builder()
.name(getCommandId())
Expand Down Expand Up @@ -122,6 +117,11 @@ protected Collection<CommandDefinitionOption> additionalCommandOptions() {
return Collections.emptyList();
}

@Override
public @NonNull List<AutoCompleteAnswer> getAutoCompleteAnswer(AutoCompleteRequest autoCompleteRequest) {
return BaseCommandOptions.autoCompleteColorOption(autoCompleteRequest);
}

protected Optional<List<ComponentRowDefinition>> getCurrentMessageComponentChange(UUID configUUID, C config, State<S> state, long channelId, long userId) {
return Optional.empty();
}
Expand Down Expand Up @@ -350,7 +350,7 @@ Mono<Void> deleteOldAndConcurrentMessageAndData(
if (startOption.isPresent()) {
CommandInteractionOption options = startOption.get();

Optional<Long> answerTargetChannelId = DefaultCommandOptions.getAnswerTargetChannelIdFromStartCommandOption(options);
Optional<Long> answerTargetChannelId = BaseCommandOptions.getAnswerTargetChannelIdFromStartCommandOption(options);
if (answerTargetChannelId.isPresent() && answerTargetChannelId.get().equals(event.getChannelId())) {
log.info("{}:same answer channel for {}", event.getRequester().toLogString(), commandString);
return event.reply("The answer target channel must be not the same as the current channel, keep this option empty if the answer should appear in this channel", true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package de.janno.discord.bot.command;

import de.janno.discord.bot.dice.image.DiceImageStyle;
import de.janno.discord.connector.api.AutoCompleteAnswer;
import de.janno.discord.connector.api.AutoCompleteRequest;
import de.janno.discord.connector.api.OptionValue;
import de.janno.discord.connector.api.slash.CommandDefinitionOption;
import de.janno.discord.connector.api.slash.CommandDefinitionOptionChoice;
import de.janno.discord.connector.api.slash.CommandInteractionOption;
import lombok.NonNull;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public final class BaseCommandOptions {
private static final String ANSWER_TARGET_CHANNEL_OPTION = "target_channel";
public static final CommandDefinitionOption ANSWER_TARGET_CHANNEL_COMMAND_OPTION = CommandDefinitionOption.builder()
.name(ANSWER_TARGET_CHANNEL_OPTION)
.description("Another channel where the answer will be given")
.type(CommandDefinitionOption.Type.CHANNEL)
.build();
private static final String ANSWER_FORMAT_OPTION = "answer_format";
public static final CommandDefinitionOption ANSWER_FORMAT_COMMAND_OPTION = CommandDefinitionOption.builder()
.name(ANSWER_FORMAT_OPTION)
.description("How the answer will be displayed")
.type(CommandDefinitionOption.Type.STRING)
.choices(Arrays.stream(AnswerFormatType.values())
.map(answerFormatType -> CommandDefinitionOptionChoice.builder()
.name(answerFormatType.name())
.value(answerFormatType.name())
.build())
.collect(Collectors.toList()))
.build();
private static final String DICE_IMAGE_STYLE_OPTION = "dice_image_style";
public static final CommandDefinitionOption DICE_IMAGE_STYLE_COMMAND_OPTION = CommandDefinitionOption.builder()
.name(DICE_IMAGE_STYLE_OPTION)
.description("If and in what style the dice throw should be shown as image")
.type(CommandDefinitionOption.Type.STRING)
.choices(Arrays.stream(DiceImageStyle.values())
.map(ri -> CommandDefinitionOptionChoice.builder()
.name(ri.name())
.value(ri.name())
.build())
.collect(Collectors.toList()))
.build();
private static final String DICE_IMAGE_COLOR_OPTION = "dice_image_color";
public static final CommandDefinitionOption DICE_IMAGE_COLOR_COMMAND_OPTION = CommandDefinitionOption.builder()
.name(DICE_IMAGE_COLOR_OPTION)
.description("The default color option. Can be influenced by the `color` method")
.type(CommandDefinitionOption.Type.STRING)
.autoComplete(true)
.build();

public static List<AutoCompleteAnswer> autoCompleteColorOption(AutoCompleteRequest autoCompleteRequest) {
if (!DICE_IMAGE_COLOR_OPTION.equals(autoCompleteRequest.getFocusedOptionName())) {
return List.of();
}
Optional<String> styleOptionValue = autoCompleteRequest.getOptionValues().stream()
.filter(o -> DICE_IMAGE_STYLE_OPTION.equals(o.getOptionName()))
.map(OptionValue::getOptionValue)
.findFirst();
if (styleOptionValue.isEmpty() || !DiceImageStyle.isValidStyle(styleOptionValue.get())) {
return List.of(new AutoCompleteAnswer("Select the dice image style first", "none"));
}
return DiceImageStyle.valueOf(styleOptionValue.get()).getSupportedColors().stream()
.filter(s -> s.contains(autoCompleteRequest.getFocusedOptionValue()))
.limit(25)
.map(c -> new AutoCompleteAnswer(c, c))
.collect(Collectors.toList());
}

public static Optional<Long> getAnswerTargetChannelIdFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getChannelIdSubOptionWithName(ANSWER_TARGET_CHANNEL_OPTION);
}

public static Optional<AnswerFormatType> getAnswerTypeFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getStringSubOptionWithName(ANSWER_FORMAT_OPTION)
.map(AnswerFormatType::valueOf);
}

public static Optional<DiceImageStyle> getDiceStyleOptionFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getStringSubOptionWithName(DICE_IMAGE_STYLE_OPTION)
.map(DiceImageStyle::valueOf);
}

public static Optional<String> getDiceColorOptionFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getStringSubOptionWithName(DICE_IMAGE_COLOR_OPTION);
}
}
19 changes: 15 additions & 4 deletions bot/src/main/java/de/janno/discord/bot/command/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.janno.discord.bot.ResultImage;
import de.janno.discord.bot.dice.image.DiceImageStyle;
import de.janno.discord.bot.dice.image.DiceStyleAndColor;
import de.janno.discord.bot.dice.image.LegacyImageConfigHelper;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
Expand All @@ -24,19 +27,27 @@ public class Config implements Serializable {
private final AnswerFormatType answerFormatType;

@NonNull
private final ResultImage resultImage;
private final DiceStyleAndColor diceStyleAndColor;

@JsonCreator
public Config(@JsonProperty("answerTargetChannelId") Long answerTargetChannelId,
@JsonProperty("answerFormatType") AnswerFormatType answerFormatType,
@JsonProperty("resultImage") ResultImage resultImage) {
@JsonProperty("resultImage") ResultImage resultImage,
@JsonProperty("diceImageStyle") DiceStyleAndColor diceStyleAndColor) {
this.answerTargetChannelId = answerTargetChannelId;
this.answerFormatType = answerFormatType == null ? AnswerFormatType.full : answerFormatType;
this.resultImage = resultImage == null ? ResultImage.none : resultImage;

if (resultImage != null) {
this.diceStyleAndColor = LegacyImageConfigHelper.getStyleAndColor(resultImage);
} else if (diceStyleAndColor != null) {
this.diceStyleAndColor = diceStyleAndColor;
} else {
this.diceStyleAndColor = new DiceStyleAndColor(DiceImageStyle.none, DiceImageStyle.none.getDefaultColor());
}
}

public String toShortString() {
return String.format("[%s, %s, %s]", getTargetChannelShortString(), answerFormatType, resultImage);
return String.format("[%s, %s, %s]", getTargetChannelShortString(), answerFormatType, diceStyleAndColor);
}

protected String getTargetChannelShortString() {
Expand Down
Loading

0 comments on commit 5dd7704

Please sign in to comment.