diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index 4721512..de31cfa 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -16,7 +16,7 @@ public class Shop { public ArrayList currentShopItems; public Shop(){ - allItems = loadCurrentShopItems(); + allItems = loadAllItems(); currentShopItems = loadPartofItems(allItems, 2); } @@ -128,6 +128,25 @@ public class Shop { return true; } + private ArrayList loadAllItems(){ + File file = new File("src/main/resources/items.json"); + ArrayList arrayList = new ArrayList(); + try { + String content = new String(Files.readAllBytes(Paths.get(file.toURI())), "UTF-8"); + JSONObject jsonObject = new JSONObject(content); + + JSONArray jsonArray = jsonObject.getJSONArray("items"); + for(int i = 0; i < jsonArray.length(); i++){ + JSONObject tempJSON = jsonArray.getJSONObject(i); + arrayList.add(new Item(tempJSON.getString("name"), tempJSON.getInt("amountShop"), tempJSON.getInt("gold"))); + } + }catch (Exception e){ + e.printStackTrace(); + } + + return arrayList; + } + private ArrayList loadCurrentShopItems(){ File file = new File("src/main/resources/gameconfig.json"); ArrayList arrayList = new ArrayList();