Mod cleanup

This commit is contained in:
Anuken
2019-10-05 16:05:54 -04:00
parent 4b99f7c819
commit a24321ae56
4 changed files with 36 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry.game;
import io.anuke.arc.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.*;
/** Holds objective classes. */
public class Objectives{
@@ -30,22 +31,22 @@ public class Objectives{
}
public static class Unlock implements Objective{
public @NonNull UnlockableContent content;
public @NonNull Block block;
public Unlock(UnlockableContent content){
this.content = content;
public Unlock(Block block){
this.block = block;
}
protected Unlock(){}
@Override
public boolean complete(){
return content.unlocked();
return block.unlocked();
}
@Override
public String display(){
return Core.bundle.format("requirement.unlock", content.localizedName);
return Core.bundle.format("requirement.unlock", block.localizedName);
}
}

View File

@@ -40,7 +40,7 @@ public class ContentParser{
put(BulletType.class, (type, data) -> {
Class<? extends BulletType> bc = data.has("type") ? resolve(data.getString("type"), "io.anuke.mindustry.entities.bullets") : BasicBulletType.class;
data.remove("type");
BulletType result = bc.getDeclaredConstructor().newInstance();
BulletType result = make(bc);
readFields(result, data);
return result;
});
@@ -62,9 +62,9 @@ public class ContentParser{
return Core.assets.get(path);
});
put(Objective.class, (type, data) -> {
Class<? extends Objective> oc = data.has("type") ? resolve(data.getString("type"), "io.anuke.mindustry.game.objectives") : ZoneWave.class;
Class<? extends Objective> oc = data.has("type") ? resolve(data.getString("type"), "io.anuke.mindustry.game.Objectives") : ZoneWave.class;
data.remove("type");
Objective obj = oc.getDeclaredConstructor().newInstance();
Objective obj = make(oc);
readFields(obj, data);
return obj;
});
@@ -123,6 +123,7 @@ public class ContentParser{
);
Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name);
currentContent = block;
read(() -> {
if(value.has("consumes")){
for(JsonValue child : value.get("consumes")){
@@ -167,6 +168,7 @@ public class ContentParser{
Class<BaseUnit> type = resolve(value.getString("type"), "io.anuke.mindustry.entities.type.base");
UnitType unit = new UnitType(mod + "-" + name, supply(type));
currentContent = unit;
read(() -> readFields(unit, value, true));
return unit;
@@ -187,6 +189,7 @@ public class ContentParser{
item = constructor.get(mod + "-" + name);
}
currentContent = item;
read(() -> readFields(item, value));
return item;
};
@@ -233,7 +236,11 @@ public class ContentParser{
}
public void finishParsing(){
reads.each(Runnable::run);
try{
reads.each(Runnable::run);
}catch(Exception e){
throw new RuntimeException("Error occurred parsing content: " + currentContent, e);
}
reads.clear();
}
@@ -261,6 +268,16 @@ public class ContentParser{
return c;
}
private <T> T make(Class<T> type){
try{
java.lang.reflect.Constructor<T> cons = type.getDeclaredConstructor();
cons.setAccessible(true);
return cons.newInstance();
}catch(Exception e){
throw new RuntimeException(e);
}
}
private <T> Supplier<T> supply(Class<T> type){
try{
java.lang.reflect.Constructor<T> cons = type.getDeclaredConstructor();
@@ -374,9 +391,13 @@ public class ContentParser{
try{
return (Class<T>)Class.forName(type + '.' + base);
}catch(Exception ignored){
try{
return (Class<T>)Class.forName(type + '$' + base);
}catch(Exception ignored2){
}
}
}
throw new IllegalArgumentException("Type not found: " + potentials[0]);
throw new IllegalArgumentException("Types not found: " + base + "." + potentials[0]);
}
private interface FieldParser{

View File

@@ -84,9 +84,9 @@ public class ZoneInfoDialog extends FloatingDialog{
r.add("$research.list").colspan(2).left();
r.row();
for(Unlock blocko : blocks){
r.addImage(blocko.content.icon(Cicon.small)).size(8 * 3).padRight(5);
r.add(blocko.content.localizedName).color(Color.lightGray).left();
r.addImage(blocko.content.unlocked() ? Icon.checkSmall : Icon.cancelSmall, blocko.content.unlocked() ? Color.lightGray : Color.scarlet).padLeft(3);
r.addImage(blocko.block.icon(Cicon.small)).size(8 * 3).padRight(5);
r.add(blocko.block.localizedName).color(Color.lightGray).left();
r.addImage(blocko.block.unlocked() ? Icon.checkSmall : Icon.cancelSmall, blocko.block.unlocked() ? Color.lightGray : Color.scarlet).padLeft(3);
r.row();
}