From 977f320122d6767ad2d2a6c9c023b6848eea6c7b Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 23 Oct 2025 22:37:15 -0400 Subject: [PATCH] More test fixes --- core/src/mindustry/mod/ContentParser.java | 11 ++++++++-- tests/src/test/java/PatcherTests.java | 25 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index e9b7bfbc79..954947e174 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -140,7 +140,7 @@ public class ContentParser{ }else if(data.isArray()){ 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"); BulletType result = (BulletType)make(bc); readFields(result, data); @@ -897,6 +897,8 @@ public class ContentParser{ if(!located){ c.minfo.mod = mod; } + + currentMod = null; return c; } @@ -1262,6 +1264,11 @@ public class ContentParser{ /** Tries to resolve a class from the class type map. */ Class resolve(String base, Class def){ + return resolve(base, def, true); + } + + /** Tries to resolve a class from the class type map. */ + Class resolve(String base, Class def, boolean warn){ //no base class specified if((base == null || base.isEmpty()) && def != null) return def; @@ -1282,7 +1289,7 @@ public class ContentParser{ } 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; } throw new IllegalArgumentException("Type not found: " + base); diff --git a/tests/src/test/java/PatcherTests.java b/tests/src/test/java/PatcherTests.java index 0b3964c61c..962a90589b 100644 --- a/tests/src/test/java/PatcherTests.java +++ b/tests/src/test/java/PatcherTests.java @@ -90,4 +90,29 @@ public class PatcherTests{ UnitTypes.dagger.checkStats(); 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); + } }