Added more types, changed how items and stuff will work. Began work on audio and npcs.

This commit is contained in:
Raktbastr 2026-05-15 16:18:51 -05:00
parent 05a97e072a
commit 33957c55dc
28 changed files with 472 additions and 518 deletions

View file

@ -1,7 +1,8 @@
package net.halfheart.ventricleengine;
import net.halfheart.ventricleengine.objects.Armor;
import net.halfheart.lonesomeroad.ID;
import org.json.*;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
@ -14,67 +15,42 @@ import java.util.Objects;
import java.util.stream.Collectors;
public class ArmorsHandler {
// Creates Armor object by parsing JSON
public static Armor constructArmor(String armorName) {
String filename = "/armors.json";
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
String jsonText = new BufferedReader(
new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
try (InputStream inputStream = ItemsHandler.class.getResourceAsStream(filename); BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8))) {
String jsonText = reader.lines().collect(Collectors.joining("\n"));
JSONArray jsonArray = new JSONArray(jsonText);
JSONObject wantedItem = null;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
if (item.opt("name").toString().equals(armorName)) {
wantedItem = item;
}
}
assert wantedItem != null;
JSONObject resistances = wantedItem.getJSONObject("resistances");
String name = wantedItem.opt("name").toString();
String description = wantedItem.opt("desc").toString();
String armorType = wantedItem.opt("type").toString();
String resUnit = wantedItem.opt("unit").toString();
List<Byte> resList = new ArrayList<>();
for (String key : resistances.keySet()) {
byte res = (byte) resistances.opt(key);
resList.add(res);
}
byte weight = (byte) wantedItem.opt("weight");
short cost = (short) wantedItem.opt("cost");
return new Armor(name, description, armorType, resList, resUnit, cost, weight);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (wantedItem == null) return null;
// Returns Armor from String of name
public static Armor findArmor(String armorName) {
return switch (armorName) {
case "Nothing" -> ID.NOTHING;
case "Leather Armor" -> ID.LEATHERARMOR;
case "Sturdy Leather Armor" -> ID.STURDYLEATHERARMOR;
case "Raider Armor" -> ID.RAIDERARMOR;
case "Metal Armor" -> ID.METALARMOR;
case "Combat Armor" -> ID.COMBATARMOR;
case "Centurion Armor" -> ID.CENTURIONARMOR;
case "NCR Ranger Armor" -> ID.NCRRANGERARMOR;
case "T-45 Power Armor" -> ID.T45POWERARMOR;
case "T-60 Power Armor" -> ID.T60POWERARMOR;
case "T-65 Power Armor" -> ID.T65POWERARMOR;
case "X-01 Power Armor" -> ID.X01POWERARMOR;
case "APA MkI Power Armor" -> ID.APAMKIORPOWERARMOR;
case "APA MkII Power Armor" -> ID.APAMKIIPOWERARMOR;
case "Raider Power Armor" -> ID.RAIDERPOWERARMOR;
case "Ultracite Power Armor" -> ID.ULTRACITEPOWERARMOR;
case "T-51 Power Armor" -> ID.T51POWERARMOR;
case "Enclave Uniform" -> ID.ENCLAVEUNIFORM;
case "Excavator Power Armor" -> ID.EXCAVATORPOWERARMOR;
default -> null;
};
String name = wantedItem.getString("name");
String description = wantedItem.getString("description");
byte weight = (byte) wantedItem.getInt("weight");
short cost = (short) wantedItem.getInt("cost");
String type = wantedItem.getString("type");
String resUnit = wantedItem.getString("resUnit");
JSONArray resArray = wantedItem.getJSONArray("resistances");
List<Byte> resistances = new ArrayList<>();
for (int i = 0; i < resArray.length(); i++) {
resistances.add((byte) resArray.getInt(i));
}
return new Armor(name, description, weight, cost, type, resistances, resUnit);
} catch (IOException e) {
throw new RuntimeException("Could not load armor data", e);
}
}
}
}