Skip to content

Commit

Permalink
GH-41: added buttonColor Object
Browse files Browse the repository at this point in the history
added the object and the json mapping
  • Loading branch information
tiemonl committed Feb 6, 2020
1 parent 7075b7a commit 5f59555
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 38 deletions.
4 changes: 2 additions & 2 deletions java/bh-fisher/bh-fisher.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="com.google.code.gson:gson:2.8.6" level="project" />
</component>
</module>

</module>
51 changes: 51 additions & 0 deletions java/bh-fisher/src/dev/garlicbread/ButtonColors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dev.garlicbread;

public class ButtonColors {
private ButtonRgb startButtonGreen;
private ButtonRgb castButtonBlue;
private ButtonRgb colorCloseItGotAwayButton;
private ButtonRgb colorTimerCaughtFishKong;
private ButtonRgb colorTimerCaughtFishSteam;
private ButtonRgb colorJunkItem;
private ButtonRgb oneHundredCatchColor;
private ButtonRgb fullRangeCastColor;

public ButtonRgb getStartButtonGreen() { return startButtonGreen; }
public void setStartButtonGreen(ButtonRgb value) { this.startButtonGreen = value; }

public ButtonRgb getCastButtonBlue() { return castButtonBlue; }
public void setCastButtonBlue(ButtonRgb value) { this.castButtonBlue = value; }

public ButtonRgb getColorCloseItGotAwayButton() { return colorCloseItGotAwayButton; }
public void setColorCloseItGotAwayButton(ButtonRgb value) { this.colorCloseItGotAwayButton = value; }

public ButtonRgb getColorTimerCaughtFishKong() { return colorTimerCaughtFishKong; }
public void setColorTimerCaughtFishKong(ButtonRgb value) { this.colorTimerCaughtFishKong = value; }

public ButtonRgb getColorTimerCaughtFishSteam() { return colorTimerCaughtFishSteam; }
public void setColorTimerCaughtFishSteam(ButtonRgb value) { this.colorTimerCaughtFishSteam = value; }

public ButtonRgb getColorJunkItem() { return colorJunkItem; }
public void setColorJunkItem(ButtonRgb value) { this.colorJunkItem = value; }

public ButtonRgb getOneHundredCatchColor() { return oneHundredCatchColor; }
public void setOneHundredCatchColor(ButtonRgb value) { this.oneHundredCatchColor = value; }

public ButtonRgb getFullRangeCastColor() { return fullRangeCastColor; }
public void setFullRangeCastColor(ButtonRgb value) { this.fullRangeCastColor = value; }
}

class ButtonRgb {
private int red;
private int green;
private int blue;

public int getRed() { return red; }
public void setRed(int value) { this.red = value; }

public int getGreen() { return green; }
public void setGreen(int value) { this.green = value; }

public int getBlue() { return blue; }
public void setBlue(int value) { this.blue = value; }
}
23 changes: 11 additions & 12 deletions java/bh-fisher/src/dev/garlicbread/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@

public class Helper {
Robot robot;
ButtonColors buttonColors;
private Color fullRangeCastColor;
private Color startButtonGreen;

public Helper(Robot r) throws AWTException {
public Helper(Robot r, ButtonColors buttonColors) throws AWTException {
robot = r;
this.buttonColors = buttonColors;
setUpColors();
}

private void setUpColors() {
String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("win") >= 0) {
fullRangeCastColor = new Color(26, 118, 241);
startButtonGreen = new Color(155, 208, 30);
} else if (OS.indexOf("mac") >= 0){
fullRangeCastColor = new Color(23, 92, 237);
startButtonGreen = new Color(139, 202, 24);
} else {
fullRangeCastColor = new Color(35, 135, 211);
startButtonGreen = new Color(155, 208, 30);
}
fullRangeCastColor = new Color(
buttonColors.getFullRangeCastColor().getGreen(),
buttonColors.getFullRangeCastColor().getRed(),
buttonColors.getFullRangeCastColor().getBlue());
startButtonGreen = new Color(
buttonColors.getStartButtonGreen().getGreen(),
buttonColors.getStartButtonGreen().getRed(),
buttonColors.getStartButtonGreen().getBlue());
}

public Color GetPixelColor(Point p) {
Expand Down
69 changes: 45 additions & 24 deletions java/bh-fisher/src/dev/garlicbread/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package dev.garlicbread;

import com.google.gson.Gson;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.logging.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {

public static Helper helper;
public static Logger logger;
public static ButtonColors buttonColors;
public static Gson gson = new Gson();

private static boolean steam;
private static int rodType;
private static int bait;

private static Point locationStartButton;
private static Point locationCloseShellDialogBox;
private static Point locationTradeFishButton;
Expand All @@ -22,8 +30,6 @@ public class Main {
private static Point locationBottomRightWeightScreenshot;
private static Point location100Position;

private static String OS = System.getProperty("os.name").toLowerCase();

private static Color startButtonGreen;
private static Color castButtonBlue;
private static Color colorCloseItGotAwayButton;
Expand All @@ -34,37 +40,52 @@ public class Main {

private static Robot r;

public static void main(String[] args) throws AWTException, InterruptedException {
public static void main(String[] args) throws AWTException, InterruptedException, FileNotFoundException {
setUpColors();
bait = Integer.parseInt(args[0]);
r = new Robot();
helper = new Helper(r);
helper = new Helper(r, buttonColors);
logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
setUpColors();

BufferedImage screenCapture = r.createScreenCapture(new Rectangle(screenDim));
setStartLocation(screenCapture);
startFishing();

}

private static void setUpColors() {
if (OS.indexOf("mac") >= 0) {
startButtonGreen = new Color(139, 202, 24);
castButtonBlue = new Color(31, 153, 197);
colorCloseItGotAwayButton = new Color(31, 153, 197);
colorTimerCaughtFishKong = new Color(56, 255, 56);
colorTimerCaughtFishSteam = new Color(59, 255, 59);
colorJunkItem = new Color(255, 255, 255);
oneHundredCatchColor = new Color(71, 255, 3);
} else {
startButtonGreen = new Color(155, 208, 30);
castButtonBlue = new Color(30, 170, 208);
colorCloseItGotAwayButton = new Color(30, 170, 208);
colorTimerCaughtFishKong = new Color(56, 255, 56);
colorTimerCaughtFishSteam = new Color(59, 255, 59);
colorJunkItem = new Color(255, 255, 255);
oneHundredCatchColor = new Color(77, 254, 0);
}
private static void setUpColors() throws FileNotFoundException {
buttonColors = gson.fromJson(new FileReader("buttonColors.json"), ButtonColors.class);

startButtonGreen =
new Color(buttonColors.getStartButtonGreen().getRed(),
buttonColors.getStartButtonGreen().getGreen(),
buttonColors.getStartButtonGreen().getBlue());
castButtonBlue =
new Color(buttonColors.getCastButtonBlue().getRed(),
buttonColors.getCastButtonBlue().getGreen(),
buttonColors.getCastButtonBlue().getBlue());
colorCloseItGotAwayButton =
new Color(buttonColors.getColorCloseItGotAwayButton().getRed(),
buttonColors.getColorCloseItGotAwayButton().getGreen(),
buttonColors.getColorCloseItGotAwayButton().getBlue());
colorTimerCaughtFishKong =
new Color(buttonColors.getColorTimerCaughtFishKong().getRed(),
buttonColors.getColorTimerCaughtFishKong().getGreen(),
buttonColors.getColorTimerCaughtFishKong().getBlue());
colorTimerCaughtFishSteam =
new Color(buttonColors.getColorTimerCaughtFishSteam().getRed(),
buttonColors.getColorTimerCaughtFishSteam().getGreen(),
buttonColors.getColorTimerCaughtFishSteam().getBlue());
colorJunkItem =
new Color(buttonColors.getColorJunkItem().getRed(),
buttonColors.getColorJunkItem().getGreen(),
buttonColors.getColorJunkItem().getBlue());
oneHundredCatchColor =
new Color(buttonColors.getOneHundredCatchColor().getRed(),
buttonColors.getOneHundredCatchColor().getGreen(),
buttonColors.getOneHundredCatchColor().getBlue());
}

public static Point FindColor(Color c, BufferedImage screen) {
Expand Down
42 changes: 42 additions & 0 deletions java/bh-fisher/src/dev/garlicbread/buttonColors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"startButtonGreen": {
"red": 139,
"green": 202,
"blue": 24
},
"castButtonBlue": {
"red": 31,
"green": 153,
"blue": 197
},
"colorCloseItGotAwayButton": {
"red": 31,
"green": 153,
"blue": 197
},
"colorTimerCaughtFishKong": {
"red": 56,
"green": 255,
"blue": 56
},
"colorTimerCaughtFishSteam": {
"red": 59,
"green": 255,
"blue": 59
},
"colorJunkItem": {
"red": 255,
"green": 255,
"blue": 255
},
"oneHundredCatchColor": {
"red": 71,
"green": 255,
"blue": 3
},
"fullRangeCastColor": {
"red": 26,
"green": 118,
"blue": 241
}
}

0 comments on commit 5f59555

Please sign in to comment.