PowerMiner/src/InventorySlot.java

52 lines
1.7 KiB
Java
Raw Normal View History

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
2018-01-31 08:12:02 -05:00
public class InventorySlot {
2018-02-01 22:39:57 -05:00
private static final int INVENTORY_SLOT_WIDTH = 171 / 4;
private static final int INVENTORY_SLOT_HEIGHT = 254 / 7;
Rectangle rectangleToCapture;
BufferedImage inventorySlotImage;
2018-01-31 08:12:02 -05:00
public InventorySlot(int row, int column) {
initializeRectangleToCapture(row, column);
}
2018-01-31 08:12:02 -05:00
private void initializeRectangleToCapture(int row, int column) {
2018-02-01 22:39:57 -05:00
rectangleToCapture = new Rectangle(row * INVENTORY_SLOT_WIDTH, column * INVENTORY_SLOT_HEIGHT, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT);
2018-01-31 08:12:02 -05:00
}
2018-02-01 22:39:57 -05:00
public void updateInventorySlot(BufferedImage image) throws IOException {
this.inventorySlotImage = image.getSubimage(rectangleToCapture.x, rectangleToCapture.y, rectangleToCapture.width, rectangleToCapture.height);
}
2018-01-31 08:12:02 -05:00
public String getItemNameInInventorySlot(InventoryItems items) {
return items.getNameOfItemFromImage(this.inventorySlotImage);
}
2018-02-01 22:39:57 -05:00
public boolean isInventorySlotEmpty(InventoryItems items) {
return (items.getNameOfItemFromImage(this.inventorySlotImage).equals("empty"));
}
2018-02-02 05:25:00 -05:00
public Point getClickablePointWithinItemSlot() {
return new Point(INVENTORY_SLOT_WIDTH / 2, INVENTORY_SLOT_HEIGHT / 2);
}
// For test image generation only
/*public void writeInventorySlotImage(BufferedImage image, int row, int column) throws IOException {
2018-02-02 05:25:00 -05:00
updateInventorySlot(image);
ImageIO.write(this.inventorySlotImage, "png", new File(getImageName(row, column)));
}
// For test image generation only
2018-02-02 05:25:00 -05:00
private String getImageName(int row, int column) {
return ("/home/dpapp/Desktop/RunescapeAIPics/InventorySlots/inventorySlot_" + row + "_" + column + ".png");
}*/
2018-01-31 08:12:02 -05:00
}