Cleanup
This commit is contained in:
@@ -16,7 +16,7 @@ import io.anuke.arc.util.serialization.Json.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.content.TechTree.*;
|
||||
import io.anuke.mindustry.ctype.UnlockableContent;
|
||||
import io.anuke.mindustry.ctype.*;
|
||||
import io.anuke.mindustry.entities.Effects.*;
|
||||
import io.anuke.mindustry.entities.bullet.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
@@ -54,7 +54,7 @@ public class ContentParser{
|
||||
if(fieldOpt(Sounds.class, data) != null) return fieldOpt(Sounds.class, data);
|
||||
|
||||
String path = "sounds/" + data.asString() + (Vars.ios ? ".mp3" : ".ogg");
|
||||
ProxySound sound = new ProxySound();
|
||||
ModLoadingSound sound = new ModLoadingSound();
|
||||
Core.assets.load(path, Sound.class).loaded = result -> {
|
||||
sound.sound = (Sound)result;
|
||||
};
|
||||
@@ -67,13 +67,19 @@ public class ContentParser{
|
||||
readFields(obj, data);
|
||||
return obj;
|
||||
});
|
||||
put(Weapon.class, (type, data) -> {
|
||||
Weapon weapon = new Weapon();
|
||||
readFields(weapon, data);
|
||||
weapon.name = currentMod.name + "-" + weapon.name;
|
||||
return weapon;
|
||||
});
|
||||
}};
|
||||
/** Stores things that need to be parsed fully, e.g. reading fields of content.
|
||||
* This is done to accomodate binding of content names first.*/
|
||||
private Array<Runnable> reads = new Array<>();
|
||||
private Array<Runnable> postreads = new Array<>();
|
||||
private LoadedMod currentMod;
|
||||
private io.anuke.mindustry.ctype.Content currentContent;
|
||||
private Content currentContent;
|
||||
|
||||
private Json parser = new Json(){
|
||||
@Override
|
||||
@@ -93,7 +99,7 @@ public class ContentParser{
|
||||
}
|
||||
}
|
||||
|
||||
if(io.anuke.mindustry.ctype.Content.class.isAssignableFrom(type)){
|
||||
if(Content.class.isAssignableFrom(type)){
|
||||
ContentType ctype = contentTypes.getThrow(type, () -> new IllegalArgumentException("No content type for class: " + type.getSimpleName()));
|
||||
String prefix = currentMod != null ? currentMod.name + "-" : "";
|
||||
T one = (T)Vars.content.getByName(ctype, prefix + jsonData.asString());
|
||||
@@ -213,14 +219,14 @@ public class ContentParser{
|
||||
ContentType.zone, parser(ContentType.zone, Zone::new)
|
||||
);
|
||||
|
||||
private <T extends io.anuke.mindustry.ctype.Content> T find(ContentType type, String name){
|
||||
io.anuke.mindustry.ctype.Content c = Vars.content.getByName(type, name);
|
||||
private <T extends Content> T find(ContentType type, String name){
|
||||
Content c = Vars.content.getByName(type, name);
|
||||
if(c == null) c = Vars.content.getByName(type, currentMod.name + "-" + name);
|
||||
if(c == null) throw new IllegalArgumentException("No " + type + " found with name '" + name + "'");
|
||||
return (T)c;
|
||||
}
|
||||
|
||||
private <T extends io.anuke.mindustry.ctype.Content> TypeParser<T> parser(ContentType type, Function<String, T> constructor){
|
||||
private <T extends Content> TypeParser<T> parser(ContentType type, Function<String, T> constructor){
|
||||
return (mod, name, value) -> {
|
||||
T item;
|
||||
if(Vars.content.getByName(type, name) != null){
|
||||
@@ -237,7 +243,7 @@ public class ContentParser{
|
||||
}
|
||||
|
||||
private void readBundle(ContentType type, String name, JsonValue value){
|
||||
io.anuke.mindustry.ctype.UnlockableContent cont = Vars.content.getByName(type, name) instanceof io.anuke.mindustry.ctype.UnlockableContent ?
|
||||
UnlockableContent cont = Vars.content.getByName(type, name) instanceof UnlockableContent ?
|
||||
Vars.content.getByName(type, name) : null;
|
||||
|
||||
String entryName = cont == null ? type + "." + currentMod.name + "-" + name + "." : type + "." + cont.name + ".";
|
||||
@@ -259,7 +265,7 @@ public class ContentParser{
|
||||
|
||||
/** Call to read a content's extra info later.*/
|
||||
private void read(Runnable run){
|
||||
io.anuke.mindustry.ctype.Content cont = currentContent;
|
||||
Content cont = currentContent;
|
||||
LoadedMod mod = currentMod;
|
||||
reads.add(() -> {
|
||||
this.currentMod = mod;
|
||||
@@ -270,11 +276,11 @@ public class ContentParser{
|
||||
|
||||
private void init(){
|
||||
for(ContentType type : ContentType.all){
|
||||
Array<io.anuke.mindustry.ctype.Content> arr = Vars.content.getBy(type);
|
||||
Array<Content> arr = Vars.content.getBy(type);
|
||||
if(!arr.isEmpty()){
|
||||
Class<?> c = arr.first().getClass();
|
||||
//get base content class, skipping intermediates
|
||||
while(!(c.getSuperclass() == io.anuke.mindustry.ctype.Content.class || c.getSuperclass() == UnlockableContent.class || Modifier.isAbstract(c.getSuperclass().getModifiers()))){
|
||||
while(!(c.getSuperclass() == Content.class || c.getSuperclass() == UnlockableContent.class || Modifier.isAbstract(c.getSuperclass().getModifiers()))){
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
|
||||
@@ -302,7 +308,7 @@ public class ContentParser{
|
||||
* @param file file that this content is being parsed from
|
||||
* @return the content that was parsed
|
||||
*/
|
||||
public io.anuke.mindustry.ctype.Content parse(LoadedMod mod, String name, String json, FileHandle file, ContentType type) throws Exception{
|
||||
public Content parse(LoadedMod mod, String name, String json, FileHandle file, ContentType type) throws Exception{
|
||||
if(contentTypes.isEmpty()){
|
||||
init();
|
||||
}
|
||||
@@ -314,7 +320,7 @@ public class ContentParser{
|
||||
|
||||
currentMod = mod;
|
||||
boolean exists = Vars.content.getByName(type, name) != null;
|
||||
io.anuke.mindustry.ctype.Content c = parsers.get(type).parse(mod.name, name, value);
|
||||
Content c = parsers.get(type).parse(mod.name, name, value);
|
||||
if(!exists){
|
||||
c.sourceFile = file;
|
||||
c.mod = mod;
|
||||
@@ -454,7 +460,7 @@ public class ContentParser{
|
||||
Object parse(Class<?> type, JsonValue value) throws Exception;
|
||||
}
|
||||
|
||||
private interface TypeParser<T extends io.anuke.mindustry.ctype.Content>{
|
||||
private interface TypeParser<T extends Content>{
|
||||
T parse(String mod, String name, JsonValue value) throws Exception;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import io.anuke.arc.audio.mock.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
|
||||
public class ProxySound implements Sound{
|
||||
public class ModLoadingSound implements Sound{
|
||||
public @NonNull Sound sound = new MockSound();
|
||||
|
||||
@Override
|
||||
@@ -14,8 +14,8 @@ import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.io.*;
|
||||
import io.anuke.arc.util.serialization.*;
|
||||
import io.anuke.mindustry.core.Version;
|
||||
import io.anuke.mindustry.ctype.UnlockableContent;
|
||||
import io.anuke.mindustry.core.*;
|
||||
import io.anuke.mindustry.ctype.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.plugin.*;
|
||||
@@ -130,10 +130,10 @@ public class Mods implements Loadable{
|
||||
|
||||
packer.updateTextureAtlas(Core.atlas, filter, filter, false);
|
||||
//generate new icons
|
||||
for(Array<io.anuke.mindustry.ctype.Content> arr : content.getContentMap()){
|
||||
for(Array<Content> arr : content.getContentMap()){
|
||||
arr.each(c -> {
|
||||
if(c instanceof io.anuke.mindustry.ctype.UnlockableContent && c.mod != null){
|
||||
io.anuke.mindustry.ctype.UnlockableContent u = (io.anuke.mindustry.ctype.UnlockableContent)c;
|
||||
if(c instanceof UnlockableContent && c.mod != null){
|
||||
UnlockableContent u = (UnlockableContent)c;
|
||||
u.createIcons(packer, editorPacker);
|
||||
}
|
||||
});
|
||||
@@ -285,9 +285,9 @@ public class Mods implements Loadable{
|
||||
if(file.extension().equals("json")){
|
||||
try{
|
||||
//this binds the content but does not load it entirely
|
||||
io.anuke.mindustry.ctype.Content loaded = parser.parse(mod, file.nameWithoutExtension(), file.readString("UTF-8"), file, type);
|
||||
Content loaded = parser.parse(mod, file.nameWithoutExtension(), file.readString("UTF-8"), file, type);
|
||||
Log.info("[{0}] Loaded '{1}'.", mod.meta.name,
|
||||
(loaded instanceof io.anuke.mindustry.ctype.UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded));
|
||||
(loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded));
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException("Failed to parse content file '" + file + "' for mod '" + mod.meta.name + "'.", e);
|
||||
}
|
||||
@@ -362,7 +362,7 @@ public class Mods implements Loadable{
|
||||
|
||||
public void handleError(Throwable t, LoadedMod mod){
|
||||
Array<Throwable> causes = Strings.getCauses(t);
|
||||
io.anuke.mindustry.ctype.Content content = null;
|
||||
Content content = null;
|
||||
for(Throwable e : causes){
|
||||
if(e instanceof ModLoadException && ((ModLoadException) e).content != null){
|
||||
content = ((ModLoadException) e).content;
|
||||
@@ -553,14 +553,14 @@ public class Mods implements Loadable{
|
||||
|
||||
/** Thrown when an error occurs while loading a mod.*/
|
||||
public static class ModLoadException extends RuntimeException{
|
||||
public io.anuke.mindustry.ctype.Content content;
|
||||
public Content content;
|
||||
public LoadedMod mod;
|
||||
|
||||
public ModLoadException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ModLoadException(String message, @Nullable io.anuke.mindustry.ctype.Content content, Throwable cause){
|
||||
public ModLoadException(String message, @Nullable Content content, Throwable cause){
|
||||
super(message, cause);
|
||||
this.content = content;
|
||||
if(content != null){
|
||||
|
||||
Reference in New Issue
Block a user