From b56ae6d2ba5e3646d277fab25748f3f3b755ab8c Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Tue, 6 Aug 2024 23:58:44 +0300 Subject: [PATCH] ColorManager: Fix colours being parsed as ints and not hex strings --- .../juuxel/adorn/client/resources/ColorManager.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/juuxel/adorn/client/resources/ColorManager.java b/common/src/main/java/juuxel/adorn/client/resources/ColorManager.java index 12737e6a6..a9e353e4d 100644 --- a/common/src/main/java/juuxel/adorn/client/resources/ColorManager.java +++ b/common/src/main/java/juuxel/adorn/client/resources/ColorManager.java @@ -68,7 +68,7 @@ protected void apply(Map> prepared, ResourceManager for (var json : jsons) { var partialPalette = PALETTE_CODEC.parse(JsonOps.INSTANCE, json).get() .map(Function.identity(), partial -> { - LOGGER.error("[Adorn] Could not parse color palette {}", id); + LOGGER.error("[Adorn] Could not parse color palette {}: {}", id, partial.message()); return null; }); if (partialPalette == null) continue; @@ -106,13 +106,14 @@ private static DataResult parseHexColor(String str) { public record ColorPair(int bg, int fg) { private static final int DEFAULT_FG = Colors.SCREEN_TEXT; + private static final Codec COLOR_CODEC = + Codec.STRING.comapFlatMap(ColorManager::parseHexColor, color -> HexFormat.of().withUpperCase().toHexDigits(color)); public static final Codec CODEC = Codecs.alternatively( RecordCodecBuilder.create(instance -> instance.group( - Codec.INT.fieldOf("bg").forGetter(ColorPair::bg), - Codec.INT.optionalFieldOf("fg", DEFAULT_FG).forGetter(ColorPair::bg) + COLOR_CODEC.fieldOf("bg").forGetter(ColorPair::bg), + COLOR_CODEC.optionalFieldOf("fg", DEFAULT_FG).forGetter(ColorPair::bg) ).apply(instance, ColorPair::new)), - Codec.STRING.comapFlatMap(ColorManager::parseHexColor, color -> HexFormat.of().withUpperCase().toHexDigits(color)) - .xmap(bg -> new ColorPair(bg, DEFAULT_FG), ColorPair::bg) + COLOR_CODEC.xmap(bg -> new ColorPair(bg, DEFAULT_FG), ColorPair::bg) ); } }