From 4cba88a50494dffdeb26a241dd6aa9720464b3bc Mon Sep 17 00:00:00 2001 From: BytingBulldogs3539 Date: Fri, 3 Feb 2023 23:58:32 -0500 Subject: [PATCH] Update INIConfig.java Adjust the ini configuration format. --- .../INIConfiguration/INIConfig.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java b/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java index 1a2cad9..4e0a66f 100644 --- a/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java +++ b/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java @@ -30,24 +30,23 @@ public INIConfig(String filename) { public void autoPopulate(Object o) { if (ini != null) { Field[] fields = o.getClass().getFields(); + String className = o.getClass().getSimpleName(); + for (Field field : fields) { - String[] split = field.getName().split("_"); - int length = split.length; - if (length >= 2) { - try { - - if(getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType())!=null) - { - field.set(o, - getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType())); - } - - } catch (IllegalArgumentException | IllegalAccessException e) { - DriverStation.reportWarning("Could not load item " + field.getName() + " from file " + filename, - e.getStackTrace()); + String fieldName = field.getName(); + + try { + if (getOrDefault(className, fieldName, null, field.getType()) != null) { + field.setAccessible(true); + + field.set(o, getOrDefault(className, fieldName, null, field.getType())); + } + + } catch (IllegalArgumentException | IllegalAccessException e) { + DriverStation.reportWarning("Could not load item " + field.getName() + " from file " + filename, + e.getStackTrace()); } - field.getType(); } } }