More test fixes
This commit is contained in:
@@ -140,7 +140,7 @@ public class ContentParser{
|
|||||||
}else if(data.isArray()){
|
}else if(data.isArray()){
|
||||||
return new MultiBulletType(parser.readValue(BulletType[].class, data));
|
return new MultiBulletType(parser.readValue(BulletType[].class, data));
|
||||||
}
|
}
|
||||||
Class<?> bc = resolve(data.getString("type", ""), BasicBulletType.class);
|
Class<?> bc = resolve(data.getString("type", ""), resolve(Strings.capitalize(data.getString("type", "")) + "BulletType", BasicBulletType.class), false);
|
||||||
data.remove("type");
|
data.remove("type");
|
||||||
BulletType result = (BulletType)make(bc);
|
BulletType result = (BulletType)make(bc);
|
||||||
readFields(result, data);
|
readFields(result, data);
|
||||||
@@ -897,6 +897,8 @@ public class ContentParser{
|
|||||||
if(!located){
|
if(!located){
|
||||||
c.minfo.mod = mod;
|
c.minfo.mod = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentMod = null;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1262,6 +1264,11 @@ public class ContentParser{
|
|||||||
|
|
||||||
/** Tries to resolve a class from the class type map. */
|
/** Tries to resolve a class from the class type map. */
|
||||||
<T> Class<T> resolve(String base, Class<T> def){
|
<T> Class<T> resolve(String base, Class<T> def){
|
||||||
|
return resolve(base, def, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tries to resolve a class from the class type map. */
|
||||||
|
<T> Class<T> resolve(String base, Class<T> def, boolean warn){
|
||||||
//no base class specified
|
//no base class specified
|
||||||
if((base == null || base.isEmpty()) && def != null) return def;
|
if((base == null || base.isEmpty()) && def != null) return def;
|
||||||
|
|
||||||
@@ -1282,7 +1289,7 @@ public class ContentParser{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(def != null){
|
if(def != null){
|
||||||
Log.warn("[@] No type '" + base + "' found, defaulting to type '" + def.getSimpleName() + "'", currentContent == null && currentMod != null ? currentMod.name : "");
|
if(warn) Log.warn("[@] No type '" + base + "' found, defaulting to type '" + def.getSimpleName() + "'", currentContent == null && currentMod != null ? currentMod.name : "");
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Type not found: " + base);
|
throw new IllegalArgumentException("Type not found: " + base);
|
||||||
|
|||||||
@@ -90,4 +90,29 @@ public class PatcherTests{
|
|||||||
UnitTypes.dagger.checkStats();
|
UnitTypes.dagger.checkStats();
|
||||||
assertNull(UnitTypes.dagger.stats.toMap().get(StatCat.general).get(Stat.charge));
|
assertNull(UnitTypes.dagger.stats.toMap().get(StatCat.general).get(Stat.charge));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUnitWeaponReassign() throws Exception{
|
||||||
|
Vars.state.patcher.apply(Seq.with("""
|
||||||
|
unit.dagger.weapons: [
|
||||||
|
{
|
||||||
|
name: megapoop
|
||||||
|
bullet: {
|
||||||
|
type: rail
|
||||||
|
lightningLength: 999
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
"""));
|
||||||
|
|
||||||
|
assertEquals(1, UnitTypes.dagger.weapons.size);
|
||||||
|
assertEquals("megapoop", UnitTypes.dagger.weapons.get(0).name);
|
||||||
|
assertEquals(RailBulletType.class, UnitTypes.dagger.weapons.get(0).bullet.getClass());
|
||||||
|
assertEquals(999, UnitTypes.dagger.weapons.get(0).bullet.lightningLength);
|
||||||
|
|
||||||
|
Vars.logic.reset();
|
||||||
|
|
||||||
|
assertEquals(2, UnitTypes.dagger.weapons.size);
|
||||||
|
assertEquals("large-weapon", UnitTypes.dagger.weapons.get(0).name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user