mirror of
https://github.com/davpapp/PowerMiner
synced 2025-01-08 12:28:06 -05:00
Putting constants in separate class
This commit is contained in:
parent
58c9b94f50
commit
04f997e044
@ -12,7 +12,10 @@ public class Constants {
|
||||
public static final int INVENTORY_WINDOW_HEIGHT = 350;
|
||||
public static final int INVENTORY_SLOT_WIDTH = 171 / 4;
|
||||
public static final int INVENTORY_SLOT_HEIGHT = 254 / 7;
|
||||
|
||||
public static final int INVENTORY_NUM_ROWS = 4;
|
||||
public static final int INVENTORY_NUM_COLUMNS = 7;
|
||||
|
||||
public static final String INVENTORY_TEST_DIRECTORY_PATH = "/home/dpapp/Desktop/RunescapeAI/Tests/Inventory/";
|
||||
public static final String INVENTORY_ITEMS_TEST_DIRECTORY_PATH = "/home/dpapp/Desktop/RunescapeAI/Tests/ItemNameRecognition/";
|
||||
public static final String INVENTORY_ITEMS_DIRECTORY_PATH = "/home/dpapp/Desktop/RunescapeAI/Items/";
|
||||
}
|
||||
|
@ -77,15 +77,16 @@ public class ImageCollector {
|
||||
return screenshotOutputDirectory + itemName + "_" + counter + ".jpg";
|
||||
}
|
||||
|
||||
private void generateInventorySlotImages() throws AWTException, IOException {
|
||||
|
||||
private void generateInventoryImages() throws AWTException, IOException {
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.updateAndWriteAllInventorySlotsToImages();
|
||||
inventory.updateAndWriteAllInventoryImages();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
ImageCollector imageCollector = new ImageCollector("/home/dpapp/Desktop/RunescapeAI/TensorFlow/IronOre/");
|
||||
//imageCollector.collectImages("ironOre");
|
||||
imageCollector.generateInventorySlotImages();
|
||||
imageCollector.generateInventoryImages();
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class Inventory {
|
||||
}
|
||||
|
||||
private void initializeItems() throws IOException {
|
||||
items = new InventoryItems("/home/dpapp/Desktop/RunescapeAI/Items/");
|
||||
items = new InventoryItems(Constants.INVENTORY_ITEMS_DIRECTORY_PATH);
|
||||
}
|
||||
|
||||
public void update() throws IOException {
|
||||
@ -52,12 +52,13 @@ public class Inventory {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAndWriteAllInventorySlotsToImages() throws IOException {
|
||||
public void updateAndWriteAllInventoryImages() throws IOException {
|
||||
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
||||
writeAllInventorySlotsToImages(image);
|
||||
ImageIO.write(image, "png", new File("/home/dpapp/Desktop/RunescapeAI/Tests/Inventory/inventory_TO_RENAME.png"));
|
||||
writeAllInventorySlotImages(image);
|
||||
}
|
||||
|
||||
private void writeAllInventorySlotsToImages(BufferedImage image) throws IOException {
|
||||
private void writeAllInventorySlotImages(BufferedImage image) throws IOException {
|
||||
for (int row = 0; row < Constants.INVENTORY_NUM_ROWS; row++) {
|
||||
for (int column = 0; column < Constants.INVENTORY_NUM_COLUMNS; column++) {
|
||||
inventorySlots[row][column].writeInventorySlotImage(image, row, column);
|
||||
|
@ -17,14 +17,13 @@ class InventoryItemsTest {
|
||||
String testingItemDirectoryPath;
|
||||
|
||||
public void initialize() throws IOException {
|
||||
items = new InventoryItems("/home/dpapp/Desktop/RunescapeAI/Items/");
|
||||
this.testingItemDirectoryPath = "/home/dpapp/Desktop/RunescapeAI/Tests/ItemNameRecognition/";
|
||||
items = new InventoryItems(Constants.INVENTORY_ITEMS_DIRECTORY_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNameOfItemFromImage() throws IOException {
|
||||
initialize();
|
||||
for (File itemFile : items.getListOfFilesFromItemDirectory(this.testingItemDirectoryPath)) {
|
||||
for (File itemFile : items.getListOfFilesFromItemDirectory(Constants.INVENTORY_ITEMS_TEST_DIRECTORY_PATH)) {
|
||||
if (itemFile.isFile()) {
|
||||
BufferedImage itemImage = ImageIO.read(itemFile);
|
||||
String expectedItemName = getItemNameForTest(itemFile.getName());
|
||||
@ -36,7 +35,7 @@ class InventoryItemsTest {
|
||||
@Test
|
||||
public void testIsImageThisItem() throws IOException {
|
||||
initialize();
|
||||
for (File itemFile : items.getListOfFilesFromItemDirectory(this.testingItemDirectoryPath)) {
|
||||
for (File itemFile : items.getListOfFilesFromItemDirectory(Constants.INVENTORY_ITEMS_TEST_DIRECTORY_PATH)) {
|
||||
if (itemFile.isFile()) {
|
||||
BufferedImage itemImage = ImageIO.read(itemFile);
|
||||
String expectedItemName = getItemNameForTest(itemFile.getName());
|
||||
|
@ -40,7 +40,6 @@ public class InventorySlot {
|
||||
|
||||
// For test image generation only
|
||||
public void writeInventorySlotImage(BufferedImage image, int row, int column) throws IOException {
|
||||
System.out.println("Written inventory slot image...");
|
||||
updateInventorySlot(image);
|
||||
ImageIO.write(this.inventorySlotImage, "png", new File(getImageName(row, column)));
|
||||
}
|
||||
|
@ -12,17 +12,15 @@ import org.junit.jupiter.api.Test;
|
||||
class InventoryTest {
|
||||
|
||||
Inventory inventory;
|
||||
String testingInventoryDirectoryPath;
|
||||
|
||||
public void initialize() throws AWTException, IOException {
|
||||
inventory = new Inventory();
|
||||
this.testingInventoryDirectoryPath = "/home/dpapp/Desktop/RunescapeAI/Tests/Inventory/";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNameInItemInventorySlot() throws IOException, AWTException {
|
||||
initialize();
|
||||
|
||||
// TODO: Coal is recognized as ironOre
|
||||
String[][] expectedItemNames0 = {{"willowLogs", "oakLogs", "oakLogs", "willowLogs", "willowLogs", "willowLogs", "willowLogs"},
|
||||
{"empty", "empty", "empty", "willowLogs", "willowLogs", "willowLogs", "willowLogs"},
|
||||
{"empty", "willowLogs", "logs", "logs", "empty", "willowLogs", "willowLogs"},
|
||||
@ -35,24 +33,24 @@ class InventoryTest {
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
String[][] expectedItemNames3 = {{"oakLogs", "willowLogs", "willowLogs", "willowLogs", "oakLogs", "willowLogs", "logs"},
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
String[][] expectedItemNames4 = {{"oakLogs", "willowLogs", "willowLogs", "willowLogs", "oakLogs", "willowLogs", "logs"},
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
String[][] expectedItemNames5 = {{"oakLogs", "willowLogs", "willowLogs", "willowLogs", "oakLogs", "willowLogs", "logs"},
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
String[][] expectedItemNames3 = {{"ironOre", "empty", "ironOre", "empty", "ironOre", "empty", "ironOre"},
|
||||
{"empty", "ironOre", "empty", "ironOre", "ironOre", "ironOre", "ironOre"},
|
||||
{"ironOre", "empty", "ironOre", "empty", "empty", "ironOre", "empty"},
|
||||
{"empty", "ironOre", "empty", "ironOre", "ironOre", "empty", "empty"}};
|
||||
String[][] expectedItemNames4 = {{"ironOre", "empty", "empty", "ironOre", "ironOre", "empty", "empty"},
|
||||
{"empty", "ironOre", "empty", "empty", "ironOre", "ironOre", "empty"},
|
||||
{"empty", "ironOre", "ironOre", "ironOre", "empty", "ironOre", "ironOre"},
|
||||
{"empty", "ironOre", "empty", "ironOre", "ironOre", "empty", "ironOre"}};
|
||||
String[][] expectedItemNames5 = {{"ironOre", "empty", "ironOre", "ironOre", "empty", "empty", "ironOre"},
|
||||
{"empty", "ironOre", "empty", "empty", "ironOre", "ironOre", "empty"},
|
||||
{"empty", "empty", "ironOre", "ironOre", "empty", "ironOre", "ironOre"},
|
||||
{"ironOre", "ironOre", "ironOre", "empty", "ironOre", "empty", "empty"}};
|
||||
testGetNameInItemInventorySlotHelper("inventory_0.png", expectedItemNames0);
|
||||
testGetNameInItemInventorySlotHelper("inventory_1.png", expectedItemNames1);
|
||||
testGetNameInItemInventorySlotHelper("inventory_2.png", expectedItemNames2);
|
||||
testGetNameInItemInventorySlotHelper("inventory_3.png", expectedItemNames2);
|
||||
testGetNameInItemInventorySlotHelper("inventory_4.png", expectedItemNames2);
|
||||
testGetNameInItemInventorySlotHelper("inventory_5.png", expectedItemNames2);
|
||||
testGetNameInItemInventorySlotHelper("inventory_3.png", expectedItemNames3);
|
||||
testGetNameInItemInventorySlotHelper("inventory_4.png", expectedItemNames4);
|
||||
testGetNameInItemInventorySlotHelper("inventory_5.png", expectedItemNames5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -77,15 +75,15 @@ class InventoryTest {
|
||||
public void testGetNameInItemInventorySlotHelper(String inventoryFileName, String[][] expectedItemNames) throws IOException {
|
||||
loadTestingImageToInventory(inventoryFileName);
|
||||
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 7; column++) {
|
||||
for (int row = 0; row < Constants.INVENTORY_NUM_ROWS; row++) {
|
||||
for (int column = 0; column < Constants.INVENTORY_NUM_COLUMNS; column++) {
|
||||
assertEquals(inventory.getItemNameInInventorySlot(row, column), expectedItemNames[row][column]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage loadBufferedImage(String fileName) throws IOException {
|
||||
File itemFile = new File(this.testingInventoryDirectoryPath + fileName);
|
||||
File itemFile = new File(Constants.INVENTORY_TEST_DIRECTORY_PATH + fileName);
|
||||
BufferedImage itemImage = ImageIO.read(itemFile);
|
||||
return itemImage;
|
||||
}
|
||||
@ -93,8 +91,5 @@ class InventoryTest {
|
||||
public void loadTestingImageToInventory(String inventoryFileName) throws IOException {
|
||||
BufferedImage testImage = loadBufferedImage(inventoryFileName);
|
||||
inventory.updateWithFakeImageForTests(testImage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user