Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sign colours to enum #21

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,86 +1,13 @@
package com.technicjelle.bluemapsignextractor.common;


import java.util.Map;

public class HTMLUtils {
private static final Map<String, String> mc2css = Map.ofEntries(
Map.entry("white", "#646464"),
Map.entry("orange", "#64280c"),
Map.entry("magenta", "#640064"),
Map.entry("light_blue", "#3c4b51"),
Map.entry("yellow", "#646400"),
Map.entry("lime", "#4b6400"),
Map.entry("pink", "#642947"),
Map.entry("gray", "#323232"),
Map.entry("light_gray", "#535353"),
Map.entry("cyan", "#006464"),
Map.entry("purple", "#3f0c5e"),
Map.entry("blue", "#000064"),
Map.entry("brown", "#361b07"),
Map.entry("green", "#006400"),
Map.entry("red", "#640000"),
Map.entry("black", "#000000")
);

private static final Map<String, String> glowCenter2css = Map.ofEntries(
Map.entry("white", "#ffffff"),
Map.entry("orange", "#fc671f"),
Map.entry("magenta", "#fc00fc"),
Map.entry("light_blue", "#98becb"),
Map.entry("yellow", "#fcfc00"),
Map.entry("lime", "#bdfc00"),
Map.entry("pink", "#fc68b2"),
Map.entry("gray", "#7e7e7e"),
Map.entry("light_gray", "#d0d0d0"),
Map.entry("cyan", "#00fcfc"),
Map.entry("purple", "#9e20ed"),
Map.entry("blue", "#0000fc"),
Map.entry("brown", "#894413"),
Map.entry("green", "#00fc00"),
Map.entry("red", "#fc0000"),
Map.entry("black", "#000000")
);

private static final Map<String, String> glowOutline2css = Map.ofEntries(
Map.entry("white", "#656565"),
Map.entry("orange", "#65280c"),
Map.entry("magenta", "#650065"),
Map.entry("light_blue", "#3c4b51"),
Map.entry("yellow", "#656500"),
Map.entry("lime", "#4b6500"),
Map.entry("pink", "#652947"),
Map.entry("gray", "#323232"),
Map.entry("light_gray", "#535353"),
Map.entry("cyan", "#006565"),
Map.entry("purple", "#3f0c5f"),
Map.entry("blue", "#000065"),
Map.entry("brown", "#361b07"),
Map.entry("green", "#006500"),
Map.entry("red", "#650000"),
Map.entry("black", "#ede8ca")
);

public static String minecraftColourToCSSColour(String minecraftColour) {
return mc2css.get(minecraftColour);
}

public static String minecraftColourToGlowCenterCSSColour(String minecraftColour) {
return glowCenter2css.get(minecraftColour);
}

private static String minecraftColourToGlowOutlineCSSColour(String minecraftColour) {
return glowOutline2css.get(minecraftColour);
}

public static String formatSignLineToHTML(String text, String minecraftColour, boolean isGlowing) {
private HTMLUtils() {}
public static String formatSignLineToHTML(String text, SignColour signColour, boolean isGlowing) {
if (isGlowing) {
final String centerColour = minecraftColourToGlowCenterCSSColour(minecraftColour);
final String outlineColour = minecraftColourToGlowOutlineCSSColour(minecraftColour);
return "<span class='glowing' style='color:" + centerColour + ";--sign-glow-colour:" + outlineColour + ";'>" + text + "</span>";
return "<span class='glowing' style='color:" + signColour.glowCenter + ";--sign-glow-colour:" + signColour.glowOutline + ";'>" + text + "</span>";
} else {
final String textColour = minecraftColourToCSSColour(minecraftColour);
return "<span style='color:" + textColour + ";'>" + text + "</span>";
return "<span style='color:" + signColour.standard + ";'>" + text + "</span>";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.technicjelle.bluemapsignextractor.common;

import java.util.HashMap;
import java.util.Map;

public enum SignColour {
WHITE("white", "#646464", "#ffffff", "#656565"),
ORANGE("orange", "#64280c", "#fc671f", "#65280c"),
MAGENTA("magenta", "#640064", "#fc00fc", "#650065"),
LIGHT_BLUE("light_blue", "#3c4b51", "#98becb", "#3c4b51"),
YELLOW("yellow", "#646400", "#fcfc00", "#656500"),
LIME("lime", "#4b6400", "#bdfc00", "#4b6500"),
PINK("pink", "#642947", "#fc68b2", "#652947"),
GRAY("gray", "#323232", "#7e7e7e", "#323232"),
LIGHT_GRAY("light_gray", "#535353", "#d0d0d0", "#535353"),
CYAN("cyan", "#006464", "#00fcfc", "#006565"),
PURPLE("purple", "#3f0c5e", "#9e20ed", "#3f0c5f"),
BLUE("blue", "#000064", "#0000fc", "#000065"),
BROWN("brown", "#361b07", "#894413", "#361b07"),
GREEN("green", "#006400", "#00fc00", "#006500"),
RED("red", "#640000", "#fc0000", "#650000"),
BLACK("black", "#000000", "#000000", "#ede8ca");

private static final Map<String, SignColour> BY_NAME = new HashMap<>();

static {
for (SignColour c : values()) {
BY_NAME.put(c.minecraftName, c);
}
}

private final String minecraftName;
public final String standard;
public final String glowCenter;
public final String glowOutline;

SignColour(String minecraftName, String standard, String glowCenter, String glowOutline) {
this.minecraftName = minecraftName;
this.standard = standard;
this.glowCenter = glowCenter;
this.glowOutline = glowOutline;
}

public static SignColour get(String name) {
return BY_NAME.get(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import com.technicjelle.bluemapsignextractor.common.BlockEntity;
import com.technicjelle.bluemapsignextractor.common.SignColour;
import com.technicjelle.bluemapsignextractor.common.HTMLUtils;
import de.bluecolored.bluenbt.NBTName;

Expand All @@ -27,10 +28,10 @@ public static String unJSON(String text) {

@Override
public String getFormattedHTML() {
return HTMLUtils.formatSignLineToHTML(unJSON(text1), "black", false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text2), "black", false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text3), "black", false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text4), "black", false);
return HTMLUtils.formatSignLineToHTML(unJSON(text1), SignColour.BLACK, false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text2), SignColour.BLACK, false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text3), SignColour.BLACK, false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text4), SignColour.BLACK, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.technicjelle.bluemapsignextractor.versions.MC_1_14_4;

import com.technicjelle.bluemapsignextractor.common.SignColour;
import com.technicjelle.bluemapsignextractor.common.HTMLUtils;
import com.technicjelle.bluemapsignextractor.versions.MC_1_13_2.MC_1_13_2_Sign;
import de.bluecolored.bluenbt.NBTName;
Expand All @@ -10,9 +11,9 @@ public class MC_1_14_4_Sign extends MC_1_13_2_Sign {

@Override
public String getFormattedHTML() {
return HTMLUtils.formatSignLineToHTML(unJSON(text1), colour, false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text2), colour, false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text3), colour, false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text4), colour, false);
return HTMLUtils.formatSignLineToHTML(unJSON(text1), SignColour.get(colour), false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text2), SignColour.get(colour), false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text3), SignColour.get(colour), false) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text4), SignColour.get(colour), false);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.technicjelle.bluemapsignextractor.versions.MC_1_17_1;

import com.technicjelle.bluemapsignextractor.common.SignColour;
import com.technicjelle.bluemapsignextractor.common.HTMLUtils;
import com.technicjelle.bluemapsignextractor.versions.MC_1_14_4.MC_1_14_4_Sign;
import de.bluecolored.bluenbt.NBTName;
Expand All @@ -10,9 +11,9 @@ public class MC_1_17_1_Sign extends MC_1_14_4_Sign {

@Override
public String getFormattedHTML() {
return HTMLUtils.formatSignLineToHTML(unJSON(text1), colour, isGlowing) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text2), colour, isGlowing) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text3), colour, isGlowing) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text4), colour, isGlowing);
return HTMLUtils.formatSignLineToHTML(unJSON(text1), SignColour.get(colour), isGlowing) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text2), SignColour.get(colour), isGlowing) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text3), SignColour.get(colour), isGlowing) + "\n" +
HTMLUtils.formatSignLineToHTML(unJSON(text4), SignColour.get(colour), isGlowing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.technicjelle.bluemapsignextractor.common.BlockEntity;
import com.technicjelle.bluemapsignextractor.common.SignColour;
import com.technicjelle.bluemapsignextractor.common.HTMLUtils;
import com.technicjelle.bluemapsignextractor.versions.MC_1_13_2.MC_1_13_2_Sign;
import de.bluecolored.bluenbt.NBTName;
Expand Down Expand Up @@ -46,7 +47,7 @@ public boolean isWrittenOn() {
public String getFormattedHTML() {
final StringBuilder sb = new StringBuilder();
for (String message : messages) {
sb.append(HTMLUtils.formatSignLineToHTML(unJSON(message), colour, isGlowing)).append("\n");
sb.append(HTMLUtils.formatSignLineToHTML(unJSON(message), SignColour.get(colour), isGlowing)).append("\n");
}
return sb.toString();
}
Expand Down