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.*;
import io.anuke.arc.util.ArcAnnotate.*; import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.*;
/** Holds objective classes. */ /** Holds objective classes. */
public class Objectives{ public class Objectives{
@@ -30,22 +31,22 @@ public class Objectives{
} }
public static class Unlock implements Objective{ public static class Unlock implements Objective{
public @NonNull UnlockableContent content; public @NonNull Block block;
public Unlock(UnlockableContent content){ public Unlock(Block block){
this.content = content; this.block = block;
} }
protected Unlock(){} protected Unlock(){}
@Override @Override
public boolean complete(){ public boolean complete(){
return content.unlocked(); return block.unlocked();
} }
@Override @Override
public String display(){ 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) -> { put(BulletType.class, (type, data) -> {
Class<? extends BulletType> bc = data.has("type") ? resolve(data.getString("type"), "io.anuke.mindustry.entities.bullets") : BasicBulletType.class; Class<? extends BulletType> bc = data.has("type") ? resolve(data.getString("type"), "io.anuke.mindustry.entities.bullets") : BasicBulletType.class;
data.remove("type"); data.remove("type");
BulletType result = bc.getDeclaredConstructor().newInstance(); BulletType result = make(bc);
readFields(result, data); readFields(result, data);
return result; return result;
}); });
@@ -62,9 +62,9 @@ public class ContentParser{
return Core.assets.get(path); return Core.assets.get(path);
}); });
put(Objective.class, (type, data) -> { 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"); data.remove("type");
Objective obj = oc.getDeclaredConstructor().newInstance(); Objective obj = make(oc);
readFields(obj, data); readFields(obj, data);
return obj; return obj;
}); });
@@ -123,6 +123,7 @@ public class ContentParser{
); );
Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name); Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name);
currentContent = block;
read(() -> { read(() -> {
if(value.has("consumes")){ if(value.has("consumes")){
for(JsonValue child : value.get("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"); Class<BaseUnit> type = resolve(value.getString("type"), "io.anuke.mindustry.entities.type.base");
UnitType unit = new UnitType(mod + "-" + name, supply(type)); UnitType unit = new UnitType(mod + "-" + name, supply(type));
currentContent = unit;
read(() -> readFields(unit, value, true)); read(() -> readFields(unit, value, true));
return unit; return unit;
@@ -187,6 +189,7 @@ public class ContentParser{
item = constructor.get(mod + "-" + name); item = constructor.get(mod + "-" + name);
} }
currentContent = item;
read(() -> readFields(item, value)); read(() -> readFields(item, value));
return item; return item;
}; };
@@ -233,7 +236,11 @@ public class ContentParser{
} }
public void finishParsing(){ 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(); reads.clear();
} }
@@ -261,6 +268,16 @@ public class ContentParser{
return c; 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){ private <T> Supplier<T> supply(Class<T> type){
try{ try{
java.lang.reflect.Constructor<T> cons = type.getDeclaredConstructor(); java.lang.reflect.Constructor<T> cons = type.getDeclaredConstructor();
@@ -374,9 +391,13 @@ public class ContentParser{
try{ try{
return (Class<T>)Class.forName(type + '.' + base); return (Class<T>)Class.forName(type + '.' + base);
}catch(Exception ignored){ }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{ private interface FieldParser{

View File

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

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=feb8c35e143c0a048488341ae916c7732ea7a84e archash=59cff366c4d46577b659e153183eb824eaafd7f7