From 7680773885cfcbf7c99911441f442e67abff5ff7 Mon Sep 17 00:00:00 2001 From: Max Gerbeth Date: Sun, 15 Jan 2023 19:23:44 +0100 Subject: [PATCH] implements: loadAllItems() --- src/main/java/org/bitbiome/shop/Shop.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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();