Some Ability Helpers

This commit is contained in:
Kam committed 2026-02-03 04:27:54 -05:00
1 parent 8fc0155df8
commit 8aa6e926f6
12 files changed
+326 -92

No files matched your search

@@ -297,4 +297,55 @@ public class FieldDef {
public FieldDef getLeftChild() { return leftChild; }
public FieldDef getRightChild() { return rightChild; }
// ═══════════════════════════════════════════════════════════════════
// LIST MANIPULATION (for mod injection)
// ═══════════════════════════════════════════════════════════════════
/**
* Insert a field before the first field matching the target label.
* Searches top-level labels and ROW children.
*
* @param fields The field list to modify
* @param targetLabel The label of the field to insert before
* @param newField The field to insert
* @return true if the target was found and the field was inserted
*/
public static boolean insertBefore(java.util.List<FieldDef> fields, String targetLabel, FieldDef newField) {
for (int i = 0; i < fields.size(); i++) {
if (matchesLabel(fields.get(i), targetLabel)) {
fields.add(i, newField);
return true;
}
}
return false;
}
/**
* Insert a field after the first field matching the target label.
* Searches top-level labels and ROW children.
*
* @param fields The field list to modify
* @param targetLabel The label of the field to insert after
* @param newField The field to insert
* @return true if the target was found and the field was inserted
*/
public static boolean insertAfter(java.util.List<FieldDef> fields, String targetLabel, FieldDef newField) {
for (int i = 0; i < fields.size(); i++) {
if (matchesLabel(fields.get(i), targetLabel)) {
fields.add(i + 1, newField);
return true;
}
}
return false;
}
private static boolean matchesLabel(FieldDef def, String targetLabel) {
if (targetLabel.equals(def.label)) return true;
if (def.type == FieldType.ROW) {
if (def.leftChild != null && targetLabel.equals(def.leftChild.label)) return true;
if (def.rightChild != null && targetLabel.equals(def.rightChild.label)) return true;
}
return false;
}
}