Fewer methods

This commit is contained in:
Anuken
2021-04-03 01:28:19 -04:00
parent 28a2e7c697
commit 19778c743c

View File

@ -273,7 +273,10 @@ public class EntityProcess extends BaseProcessor{
name += "Entity"; name += "Entity";
} }
if(ann.legacy()){ boolean legacy = ann.legacy();
if(legacy){
baseClass = tname(packageName + "." + name);
name += "Legacy" + Strings.capitalize(type.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); 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 //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); builder.addField(spec);
} }
@ -348,7 +352,7 @@ public class EntityProcess extends BaseProcessor{
allFields.add(f); allFields.add(f);
//add extra sync fields //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); if(!f.tname().toString().equals("float")) err("All SyncFields must be of type float", f);
syncedFields.add(f); syncedFields.add(f);
@ -442,11 +446,14 @@ public class EntityProcess extends BaseProcessor{
} }
} }
boolean specialIO = false;
if(hasIO){ if(hasIO){
//SPECIAL CASE: I/O code //SPECIAL CASE: I/O code
//note that serialization is generated even for non-serializing entities for manual usage //note that serialization is generated even for non-serializing entities for manual usage
if((first.name().equals("read") || first.name().equals("write"))){ if((first.name().equals("read") || first.name().equals("write"))){
io.write(mbuilder, first.name().equals("write")); io.write(mbuilder, first.name().equals("write"));
specialIO = true;
} }
//SPECIAL CASE: sync I/O code //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); 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 //add pool reset method and implement Poolable
@ -560,7 +569,7 @@ public class EntityProcess extends BaseProcessor{
.returns(tname(packageName + "." + name)) .returns(tname(packageName + "." + name))
.addStatement(ann.pooled() ? "return Pools.obtain($L.class, " +name +"::new)" : "return new $L()", name).build()); .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 //generate groups
@ -725,6 +734,8 @@ public class EntityProcess extends BaseProcessor{
def.builder.addSuperinterface(inter.tname()); def.builder.addSuperinterface(inter.tname());
if(def.legacy) continue;
//generate getter/setter for each method //generate getter/setter for each method
for(Smethod method : inter.methods()){ for(Smethod method : inter.methods()){
String var = method.name(); String var = method.name();
@ -951,9 +962,10 @@ public class EntityProcess extends BaseProcessor{
final Selement naming; final Selement naming;
final String name; final String name;
final @Nullable TypeName extend; final @Nullable TypeName extend;
final boolean legacy;
int classID; int classID;
public EntityDefinition(String name, Builder builder, Selement naming, TypeName extend, Seq<Stype> components, Seq<GroupDefinition> groups, Seq<FieldSpec> fieldSpec){ public EntityDefinition(String name, Builder builder, Selement naming, TypeName extend, Seq<Stype> components, Seq<GroupDefinition> groups, Seq<FieldSpec> fieldSpec, boolean legacy){
this.builder = builder; this.builder = builder;
this.name = name; this.name = name;
this.naming = naming; this.naming = naming;
@ -961,6 +973,7 @@ public class EntityProcess extends BaseProcessor{
this.components = components; this.components = components;
this.extend = extend; this.extend = extend;
this.fieldSpecs = fieldSpec; this.fieldSpecs = fieldSpec;
this.legacy = legacy;
} }
@Override @Override