From 6f1881c65faa6762413889fbb7496470cd49e237 Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Tue, 18 Jun 2019 01:01:40 -0700 Subject: [PATCH] + Added help and error text --- locStrings.config | 3 ++- src/commands/CommandColor.java | 18 +++++++++++------- src/network/NetworkTheColorAPI.java | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/locStrings.config b/locStrings.config index f5358b0..d402f1e 100644 --- a/locStrings.config +++ b/locStrings.config @@ -97,7 +97,8 @@ CharacterSearchOneCharacter=I found one character with that name! \n Owner: %s | CharacterSearchInfo=Find a character with their name or Unique ID! `charactersearch name` or `charactersearch UniqueID` [CommandColor] -ColorInfo= +ColorNotSearchable=Your color couldn't be parsed! Make sure it's in hex format. Try this! `!color 3F5D54` +ColorInfo=Looks up the provided hex color and outputs it as hex, rgb, hsl, hsv, xyz, and cmyk. Also attempts to name the color, and provies a sample of it! Usage example: `!color #365345` (the # can be omitted) [CommandDoWork] DoWorkFinished=I finished with my work! :D diff --git a/src/commands/CommandColor.java b/src/commands/CommandColor.java index 53e221b..2e50bd8 100644 --- a/src/commands/CommandColor.java +++ b/src/commands/CommandColor.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; +import java.text.DecimalFormat; import core.Command; import core.LocStrings; @@ -41,8 +42,8 @@ public class CommandColor extends Command return; } - // Config - int sideLength = 150; + // Set up the variables we'll be using based on the color, and get the color itself. + int sideLength = 80; // It's 80x80 because as far as I know, that's the size of a thumbnail in discord. int r = colorData.rgb.r; int g = colorData.rgb.g; int b = colorData.rgb.b; @@ -61,16 +62,19 @@ public class CommandColor extends Command // Build the response KittyEmbed response = new KittyEmbed(); + String postEntry = ", "; response.title = colorData.name.value + (colorData.name.exact_match_name ? "" : " (ish)"); response.color = parsed; response.descriptionText = "```"; - response.descriptionText += "\nrgb: " + String.format("%1$03d", r) + " " + String.format("%1$03d", g) + " " + String.format("%1$03d", b); - response.descriptionText += "\nhsl: " + String.format("%1$03d", colorData.hsl.h) + " " + String.format("%1$02d", colorData.hsl.s) + "% " + String.format("%1$02d", colorData.hsl.l) + "%"; - response.descriptionText += "\nhsv: " + String.format("%1$03d", colorData.hsv.h) + " " + String.format("%1$02d", colorData.hsv.s) + "% " + String.format("%1$02d", colorData.hsv.v) + "%"; - response.descriptionText += "\nhex: #" + colorData.hex.clean; + response.descriptionText += "\n hex: #" + colorData.hex.clean; + response.descriptionText += "\n rgb: " + String.format("%1$03d", r) + postEntry + String.format("%1$03d", g) + postEntry + String.format("%1$03d", b); + response.descriptionText += "\n hsl: " + String.format("%1$03d", colorData.hsl.h) + postEntry + String.format("%1$02d", colorData.hsl.s) + "%" + postEntry + String.format("%1$02d", colorData.hsl.l) + "%"; + response.descriptionText += "\n hsv: " + String.format("%1$03d", colorData.hsv.h) + postEntry + String.format("%1$02d", colorData.hsv.s) + "%" + postEntry + String.format("%1$02d", colorData.hsv.v) + "%"; + response.descriptionText += "\n xyz: " + String.format("%1$03d", colorData.XYZ.X) + postEntry + String.format("%1$03d", colorData.XYZ.Y) + postEntry + String.format("%1$03d", colorData.XYZ.Z); + response.descriptionText += "\ncmyk: " + String.format("%1$03d", colorData.cmyk.c) + postEntry + String.format("%1$03d", colorData.cmyk.m) + postEntry + String.format("%1$03d", colorData.cmyk.y) + postEntry + String.format("%1$03d", colorData.cmyk.k); response.descriptionText += "```"; response.thumbnailURL = "attachment://" + tempFileName; - response.footerText = "All percentages and values are rounded to the nearest whole number." + (colorData.name.exact_match_name ? "" : " " + colorData.name.value + " is actually " + colorData.name.closest_named_hex + "."); + response.footerText = "All percentages and values are rounded to the nearest whole number!" + (colorData.name.exact_match_name ? "" : " '" + colorData.name.value + "' is actually " + colorData.name.closest_named_hex + "."); // Send then delete the temp local files res.CallEmbed(response); diff --git a/src/network/NetworkTheColorAPI.java b/src/network/NetworkTheColorAPI.java index 333bff0..2bb9f0d 100644 --- a/src/network/NetworkTheColorAPI.java +++ b/src/network/NetworkTheColorAPI.java @@ -10,6 +10,23 @@ public class NetworkTheColorAPI { private static final Gson jsonParser = new Gson(); + public class tca_XYZ + { + // This is also known as the CIE 1931 colorspace. + // Value meanings: https://en.wikipedia.org/wiki/CIE_1931_color_space + public int X; + public int Y; + public int Z; + } + + public class tca_cymk + { + public int c; // 0-100 + public int m; // 0-100 + public int y; // 0-100 + public int k; // 0-100 + } + public class tca_name { public String value; // The name of the color in english @@ -50,6 +67,8 @@ public class NetworkTheColorAPI public tca_rgb rgb; public tca_hsl hsl; public tca_hsv hsv; + public tca_cymk cmyk; + public tca_XYZ XYZ; } public ColorData LookupHex(String hex)