diff --git a/src/Constants.java b/src/Constants.java index 63030d3..d58656a 100644 --- a/src/Constants.java +++ b/src/Constants.java @@ -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/"; } diff --git a/src/ImageCollector.java b/src/ImageCollector.java index b69f31b..037b648 100644 --- a/src/ImageCollector.java +++ b/src/ImageCollector.java @@ -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(); } } diff --git a/src/Inventory.java b/src/Inventory.java index b86476e..75a8483 100644 --- a/src/Inventory.java +++ b/src/Inventory.java @@ -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); diff --git a/src/InventoryItemsTest.java b/src/InventoryItemsTest.java index 2696f0f..9b5f90c 100644 --- a/src/InventoryItemsTest.java +++ b/src/InventoryItemsTest.java @@ -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()); diff --git a/src/InventorySlot.java b/src/InventorySlot.java index dad2d8c..b31c2e4 100644 --- a/src/InventorySlot.java +++ b/src/InventorySlot.java @@ -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))); } diff --git a/src/InventoryTest.java b/src/InventoryTest.java index 3b9b508..54cbb3a 100644 --- a/src/InventoryTest.java +++ b/src/InventoryTest.java @@ -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); - } - - - + } } diff --git a/target/classes/Constants.class b/target/classes/Constants.class index 1629fde..3131400 100644 Binary files a/target/classes/Constants.class and b/target/classes/Constants.class differ diff --git a/target/classes/ImageCollector.class b/target/classes/ImageCollector.class index 4bc1724..d8851a8 100644 Binary files a/target/classes/ImageCollector.class and b/target/classes/ImageCollector.class differ diff --git a/target/classes/Inventory.class b/target/classes/Inventory.class index c7a17db..74270db 100644 Binary files a/target/classes/Inventory.class and b/target/classes/Inventory.class differ diff --git a/target/classes/InventoryItemsTest.class b/target/classes/InventoryItemsTest.class index 177f4c0..4500f75 100644 Binary files a/target/classes/InventoryItemsTest.class and b/target/classes/InventoryItemsTest.class differ diff --git a/target/classes/InventorySlot.class b/target/classes/InventorySlot.class index acce7b4..68ea1c5 100644 Binary files a/target/classes/InventorySlot.class and b/target/classes/InventorySlot.class differ diff --git a/target/classes/InventoryTest.class b/target/classes/InventoryTest.class index 3e92f8e..7801a3e 100644 Binary files a/target/classes/InventoryTest.class and b/target/classes/InventoryTest.class differ