From 19778c743c43cb69b1e7e705614da28a8f5d7b4c Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 3 Apr 2021 01:28:19 -0400 Subject: [PATCH] Fewer methods --- .../annotations/entity/EntityProcess.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java b/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java index ec6cbb3fef..6067b986b5 100644 --- a/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java +++ b/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java @@ -273,7 +273,10 @@ public class EntityProcess extends BaseProcessor{ name += "Entity"; } - if(ann.legacy()){ + boolean legacy = ann.legacy(); + + if(legacy){ + baseClass = tname(packageName + "." + name); name += "Legacy" + Strings.capitalize(type.name()); } @@ -338,7 +341,8 @@ public class EntityProcess extends BaseProcessor{ boolean isVisible = !f.is(Modifier.STATIC) && !f.is(Modifier.PRIVATE) && !f.has(ReadOnly.class); //add the field only if it isn't visible or it wasn't implemented by the base class - if(!isShadowed || !isVisible){ + //legacy classes have no extra fields + if((!isShadowed || !isVisible) && !legacy){ builder.addField(spec); } @@ -348,7 +352,7 @@ public class EntityProcess extends BaseProcessor{ allFields.add(f); //add extra sync fields - if(f.has(SyncField.class) && isSync){ + if(f.has(SyncField.class) && isSync && !legacy){ if(!f.tname().toString().equals("float")) err("All SyncFields must be of type float", f); syncedFields.add(f); @@ -442,11 +446,14 @@ public class EntityProcess extends BaseProcessor{ } } + boolean specialIO = false; + if(hasIO){ //SPECIAL CASE: I/O code //note that serialization is generated even for non-serializing entities for manual usage if((first.name().equals("read") || first.name().equals("write"))){ io.write(mbuilder, first.name().equals("write")); + specialIO = true; } //SPECIAL CASE: sync I/O code @@ -525,7 +532,9 @@ public class EntityProcess extends BaseProcessor{ mbuilder.addStatement("mindustry.gen.Groups.queueFree(($T)this)", Poolable.class); } - builder.addMethod(mbuilder.build()); + if(!legacy || specialIO){ + builder.addMethod(mbuilder.build()); + } } //add pool reset method and implement Poolable @@ -560,7 +569,7 @@ public class EntityProcess extends BaseProcessor{ .returns(tname(packageName + "." + name)) .addStatement(ann.pooled() ? "return Pools.obtain($L.class, " +name +"::new)" : "return new $L()", name).build()); - definitions.add(new EntityDefinition(packageName + "." + name, builder, type, typeIsBase ? null : baseClass, components, groups, allFieldSpecs)); + definitions.add(new EntityDefinition(packageName + "." + name, builder, type, typeIsBase ? null : baseClass, components, groups, allFieldSpecs, legacy)); } //generate groups @@ -725,6 +734,8 @@ public class EntityProcess extends BaseProcessor{ def.builder.addSuperinterface(inter.tname()); + if(def.legacy) continue; + //generate getter/setter for each method for(Smethod method : inter.methods()){ String var = method.name(); @@ -951,9 +962,10 @@ public class EntityProcess extends BaseProcessor{ final Selement naming; final String name; final @Nullable TypeName extend; + final boolean legacy; int classID; - public EntityDefinition(String name, Builder builder, Selement naming, TypeName extend, Seq components, Seq groups, Seq fieldSpec){ + public EntityDefinition(String name, Builder builder, Selement naming, TypeName extend, Seq components, Seq groups, Seq fieldSpec, boolean legacy){ this.builder = builder; this.name = name; this.naming = naming; @@ -961,6 +973,7 @@ public class EntityProcess extends BaseProcessor{ this.components = components; this.extend = extend; this.fieldSpecs = fieldSpec; + this.legacy = legacy; } @Override