Last active
November 24, 2016 22:46
-
-
Save CalebWhiting/cc77ec848b253a675ebe to your computer and use it in GitHub Desktop.
DTMSubPoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.dang.api.script.methods.DUtils; | |
import org.runedream.api.methods.Game; | |
import java.awt.*; | |
import java.awt.image.BufferedImage; | |
/** | |
* @author Caleb Date: 28/03/12 Time: 15:22 | |
*/ | |
public class DTMSubPoint { | |
/** | |
* @param string "r_g_b_x_y_t" | |
* | |
* @return returns the String converted into a DTMSubPoint | |
*/ | |
public static DTMSubPoint fromString(final String string) { | |
final String[] split = string.split("_"); | |
for (int x = 0; x < split.length; x++) { | |
split[x] = split[x].replaceFirst("_", ""); | |
} | |
final int r = Integer.parseInt(split[0]); | |
final int g = Integer.parseInt(split[1]); | |
final int b = Integer.parseInt(split[2]); | |
final int x = Integer.parseInt(split[3]); | |
final int y = Integer.parseInt(split[4]); | |
final int t = Integer.parseInt(split[5]); | |
return new DTMSubPoint(new Color(r, g, b), x, y, t); | |
} | |
private final Color color; | |
private final int plusX; | |
private final int plusY; | |
private final int tolerance; | |
public DTMSubPoint(final Color color, final int plusX, final int plusY, final int tolerance) { | |
this.color = color; | |
this.plusX = plusX; | |
this.plusY = plusY; | |
this.tolerance = tolerance; | |
} | |
public Color getColor() { | |
return this.color; | |
} | |
public int getPlusX() { | |
return this.plusX; | |
} | |
public int getPlusY() { | |
return this.plusY; | |
} | |
public int getTolerance() { | |
return this.tolerance; | |
} | |
public boolean isAt(final Point p) { | |
return DUtils.isColor(Game.getColorAt(p.x + this.getPlusX(), p.y + this.getPlusY()), this.getColor(), this.getTolerance()); | |
} | |
public boolean isAt(final Point p, final BufferedImage image) { | |
final int w = image.getWidth(); | |
final int h = image.getHeight(); | |
final int x = p.x + this.getPlusX(); | |
final int y = p.y + this.getPlusY(); | |
if (x >= w || y >= h) { | |
return false; | |
} | |
try{ | |
return DUtils.isColor(new Color(image.getRGB(x, y)), this.getColor(), this.getTolerance()); | |
}catch (ArrayIndexOutOfBoundsException e) { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment