Patcher support for array fields in object braces
This commit is contained in:
@@ -184,7 +184,7 @@ public class ContentPatcher{
|
|||||||
}else{
|
}else{
|
||||||
warn("Content '@' cannot be assigned.", field);
|
warn("Content '@' cannot be assigned.", field);
|
||||||
}
|
}
|
||||||
}else if(object instanceof Seq<?> || object.getClass().isArray()){ //TODO
|
}else if(object instanceof Seq<?> || object.getClass().isArray()){
|
||||||
|
|
||||||
if(field.equals("+")){
|
if(field.equals("+")){
|
||||||
var meta = new FieldData(metadata.type.isArray() ? metadata.type.getComponentType() : metadata.elementType, null, null);
|
var meta = new FieldData(metadata.type.isArray() ? metadata.type.getComponentType() : metadata.elementType, null, null);
|
||||||
@@ -411,6 +411,8 @@ public class ContentPatcher{
|
|||||||
if(child.name != null){
|
if(child.name != null){
|
||||||
assign(prevValue, child.name, child,
|
assign(prevValue, child.name, child,
|
||||||
metadata != null && (metadata.type == ObjectMap.class || metadata.type == ObjectFloatMap.class) ? metadata :
|
metadata != null && (metadata.type == ObjectMap.class || metadata.type == ObjectFloatMap.class) ? metadata :
|
||||||
|
metadata != null && metadata.type == Seq.class ? new FieldData(metadata.elementType, null, null) :
|
||||||
|
metadata != null && metadata.type.isArray() ? new FieldData(metadata.type.getComponentType(), null, null) :
|
||||||
!childFields.containsKey(child.name) ? null :
|
!childFields.containsKey(child.name) ? null :
|
||||||
new FieldData(childFields.get(child.name)), object, field);
|
new FieldData(childFields.get(child.name)), object, field);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,6 +299,25 @@ public class PatcherTests{
|
|||||||
assertEquals(0f, ((Drill)Blocks.mechanicalDrill).drillMultipliers.get(Items.surgeAlloy, 0f));
|
assertEquals(0f, ((Drill)Blocks.mechanicalDrill).drillMultipliers.get(Items.surgeAlloy, 0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSpecificArrayRequirements() throws Exception{
|
||||||
|
ItemStack[] reqs = Blocks.scatter.requirements.clone();
|
||||||
|
Vars.state.patcher.apply(Seq.with("""
|
||||||
|
block.scatter.requirements: {
|
||||||
|
0: surge-alloy/10
|
||||||
|
}
|
||||||
|
block.duo.requirements: [titanium/5, surge-alloy/20]
|
||||||
|
"""));
|
||||||
|
|
||||||
|
assertEquals(new Seq<>(), Vars.state.patcher.patches.first().warnings);
|
||||||
|
assertEquals(Blocks.scatter.requirements[0], new ItemStack(Items.surgeAlloy, 10));
|
||||||
|
assertEquals(Blocks.scatter.requirements[1], reqs[1]);
|
||||||
|
assertEquals(Blocks.duo.requirements[0], new ItemStack(Items.titanium, 5));
|
||||||
|
|
||||||
|
Vars.logic.reset();
|
||||||
|
assertArrayEquals(reqs, Blocks.scatter.requirements);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAttributes() throws Exception{
|
void testAttributes() throws Exception{
|
||||||
Vars.state.patcher.apply(Seq.with("""
|
Vars.state.patcher.apply(Seq.with("""
|
||||||
|
|||||||
Reference in New Issue
Block a user