1
0
mirror of https://github.com/davpapp/PowerMiner synced 2024-11-14 21:45:14 -05:00
PowerMiner/src/Inventory.java

87 lines
2.6 KiB
Java
Raw Normal View History

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
2018-02-02 05:25:00 -05:00
import java.io.File;
import java.io.IOException;
2018-01-31 08:12:02 -05:00
2018-02-02 05:25:00 -05:00
import javax.imageio.ImageIO;
2018-01-31 08:12:02 -05:00
public class Inventory {
public static final int INVENTORY_OFFSET_WIDTH = 655; //top left corner of inventory, fromm top left corner of screen
public static final int INVENTORY_OFFSET_HEIGHT = 290;
public static final int INVENTORY_WIDTH = 820 - 649;// 820
public static final int INVENTORY_HEIGHT = 350; // 530
public static final int NUM_ROWS = 4;
public static final int NUM_COLUMNS = 7;
Robot robot;
Rectangle inventoryRectangleToCapture;
2018-01-31 08:12:02 -05:00
InventorySlot[][] inventorySlots;
InventoryItems items;
2018-01-31 08:12:02 -05:00
public Inventory() throws AWTException, IOException {
initializeInventoryRectangle();
initializeInventorySlots();
initializeItems();
robot = new Robot();
}
private void initializeInventoryRectangle() {
inventoryRectangleToCapture = new Rectangle(INVENTORY_OFFSET_WIDTH, INVENTORY_OFFSET_HEIGHT, INVENTORY_WIDTH, INVENTORY_HEIGHT);
}
private void initializeInventorySlots() {
2018-01-31 08:12:02 -05:00
inventorySlots = new InventorySlot[4][7];
for (int row = 0; row < 4; row++) {
for (int column = 0; column < 7; column++) {
inventorySlots[row][column] = new InventorySlot(row, column);
2018-01-31 08:12:02 -05:00
}
}
}
private void initializeItems() throws IOException {
items = new InventoryItems("/home/dpapp/Desktop/RunescapeAIPics/Items/");
}
public void update() throws IOException {
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
2018-02-02 05:25:00 -05:00
ImageIO.write(image, "png", new File(getImageName()));
updateAllInventorySlots(image);
}
2018-02-02 05:25:00 -05:00
private String getImageName() {
return ("/home/dpapp/Desktop/RunescapeAIPics/Tests/Inventory/inventory.png");
}
public void updateWithFakeImageForTests(BufferedImage testImage) throws IOException {
updateAllInventorySlots(testImage);
}
private void updateAllInventorySlots(BufferedImage image) throws IOException {
for (int row = 0; row < 4; row++) {
for (int column = 0; column < 7; column++) {
2018-02-01 22:39:57 -05:00
inventorySlots[row][column].updateInventorySlot(image);
2018-02-02 05:25:00 -05:00
//inventorySlots[row][column].writeInventorySlotImage(image, row, column);
}
}
2018-01-31 08:12:02 -05:00
}
public String getItemNameInInventorySlot(int row, int column) {
return inventorySlots[row][column].getItemNameInInventorySlot(items);
}
2018-02-02 05:25:00 -05:00
/*public boolean isInventoryFull() {
for (int row = 0; row < 4; row++) {
for (int column = 0; column < 7; column++) {
if (!inventorySlots[row][column].isInventorySlotEmpty(items)) {
return false;
}
}
}
return true;
2018-02-02 05:25:00 -05:00
}*/
2018-01-31 08:12:02 -05:00
}