Skip to content

Commit

Permalink
Fix hsv360 parser. Closes #133
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Nov 23, 2024
1 parent 05d0cf3 commit dc524f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@ public Color overlayColors(Color bottom, Color top) {

private Color evaluateColorDefinition(String color, GameFileContext ctx) {
// For inline colors like rgb { ... }
var tagged = Arrays.stream(TaggedNode.COLORS)
.filter(tagType -> color != null && color.startsWith(tagType.getId()))
.findAny()
.map(tagType -> new TaggedNode(tagType, Arrays.stream(color.substring(tagType.getId().length() + 2, color.length() - 1).split(" "))
.filter(s -> s.length() > 0)
.map(s -> new ValueNode(s, false)).toList()));
if (tagged.isPresent()) {
return ColorHelper.fromGameColor(GameColor.fromColorNode(tagged.get()));
var taggedType = Arrays.stream(TaggedNode.COLORS).sorted(Comparator.comparingInt(value -> -value.getId().length()))
.filter(tagType -> color != null && color.startsWith(tagType.getId()))
.findFirst();
if (taggedType.isPresent()) {
var values = Arrays.stream(color.substring(taggedType.get().getId().length() + 2, color.length() - 1).split(" "))
.filter(s -> !s.isEmpty())
.map(s -> new ValueNode(s, false)).toList();
var node = new TaggedNode(taggedType.get(), values);
return ColorHelper.fromGameColor(GameColor.fromColorNode(node));
}

var colors = getPredefinedColors(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static Color fromGameColor(GameColor color) {
var c = color.getValues();

try {

if (color.getType().equals(TaggedNode.TagType.HEX)) {
var c0 = c.size() > 0 ? color.getValues().get(0) : "000000";
return Color.valueOf("#" + c0);
Expand All @@ -77,12 +76,14 @@ public static Color fromGameColor(GameColor color) {
return switch (color.getType()) {
case HSV -> Color.hsb(
d0 * 360,
d1,
d2);
Math.min(d1, 1.0),
Math.min(d2, 1.0)
);
case HSV360 -> Color.hsb(
d0,
d1 / 100.0,
d2 / 100.0);
Math.min(d1 / 100.0, 1.0),
Math.min(d2 / 100.0, 1.0)
);
case RGB -> {
var isDecimal = c.get(0).contains(".") || c.get(1).contains(".") || c.get(2).contains(".");
var denominator = isDecimal ? 1.0 : 255.0;
Expand Down

0 comments on commit dc524f6

Please sign in to comment.