Compile fixes

This commit is contained in:
Anuken
2019-12-14 12:53:37 -05:00
parent 1f5a6e1bf8
commit 9d3dda035c
9 changed files with 49 additions and 59 deletions

View File

@@ -18,7 +18,6 @@ import io.anuke.arc.util.*;
import io.anuke.arc.util.serialization.*; import io.anuke.arc.util.serialization.*;
import io.anuke.mindustry.game.Saves.*; import io.anuke.mindustry.game.Saves.*;
import io.anuke.mindustry.io.*; import io.anuke.mindustry.io.*;
import io.anuke.mindustry.mod.*;
import io.anuke.mindustry.ui.dialogs.*; import io.anuke.mindustry.ui.dialogs.*;
import java.io.*; import java.io.*;
@@ -144,7 +143,7 @@ public class AndroidLauncher extends AndroidApplication{
useImmersiveMode = true; useImmersiveMode = true;
depth = 0; depth = 0;
hideStatusBar = true; hideStatusBar = true;
errorHandler = ModCrashHandler::handle; //errorHandler = ModCrashHandler::handle;
}}); }});
checkFiles(getIntent()); checkFiles(getIntent());
} }

View File

@@ -115,8 +115,8 @@ public class ContentLoader{
try{ try{
callable.get(content); callable.get(content);
}catch(Throwable e){ }catch(Throwable e){
if(content.mod != null){ if(content.minfo.mod != null){
mods.handleError(new ModLoadException(content, e), content.mod); mods.handleContentError(content, e);
}else{ }else{
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -180,7 +180,7 @@ public class ContentLoader{
throw new IllegalArgumentException("Two content objects cannot have the same name! (issue: '" + content.name + "')"); throw new IllegalArgumentException("Two content objects cannot have the same name! (issue: '" + content.name + "')");
} }
if(currentMod != null){ if(currentMod != null){
content.mod = currentMod; content.minfo.mod = currentMod;
} }
contentNameMap[content.getContentType().ordinal()].put(content.name, content); contentNameMap[content.getContentType().ordinal()].put(content.name, content);
} }

View File

@@ -1,8 +1,9 @@
package io.anuke.mindustry.ctype; package io.anuke.mindustry.ctype;
import io.anuke.arc.files.*;
import io.anuke.arc.util.ArcAnnotate.*; import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.*; import io.anuke.mindustry.*;
import io.anuke.mindustry.mod.*; import io.anuke.mindustry.mod.Mods.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
@@ -10,7 +11,7 @@ import io.anuke.mindustry.type.*;
public abstract class Content implements Comparable<Content>{ public abstract class Content implements Comparable<Content>{
public final short id; public final short id;
/** Info on which mod this content was loaded from. */ /** Info on which mod this content was loaded from. */
public @Nullable ModContentInfo minfo; public @NonNull ModContentInfo minfo = new ModContentInfo();
public Content(){ public Content(){
@@ -37,7 +38,7 @@ public abstract class Content implements Comparable<Content>{
/** @return whether an error ocurred during mod loading. */ /** @return whether an error ocurred during mod loading. */
public boolean hasErrored(){ public boolean hasErrored(){
return minfo != null && minfo.error != null; return minfo.error != null;
} }
@Override @Override
@@ -49,4 +50,13 @@ public abstract class Content implements Comparable<Content>{
public String toString(){ public String toString(){
return getContentType().name() + "#" + id; return getContentType().name() + "#" + id;
} }
public static class ModContentInfo{
/** The mod that loaded this piece of content. */
public @Nullable LoadedMod mod;
/** File that this content was loaded from. */
public @Nullable FileHandle sourceFile;
/** The error that occurred during loading, if applicable. Null if no error occurred. */
public @Nullable String error;
}
} }

View File

@@ -266,7 +266,7 @@ public class ContentParser{
TechNode parnode = TechTree.all.find(t -> t.block == parent); TechNode parnode = TechTree.all.find(t -> t.block == parent);
if(parnode == null){ if(parnode == null){
throw new ModLoadException("Block '" + parent.name + "' isn't in the tech tree, but '" + block.name + "' requires it to be researched.", block); throw new IllegalArgumentException("Block '" + parent.name + "' isn't in the tech tree, but '" + block.name + "' requires it to be researched.");
} }
if(!parnode.children.contains(baseNode)){ if(!parnode.children.contains(baseNode)){
parnode.children.add(baseNode); parnode.children.add(baseNode);
@@ -386,21 +386,18 @@ public class ContentParser{
} }
} }
public void finishParsing(){ private void attempt(Runnable run){
reads.each(c -> {
try{
c.run();
}catch(Throwable t){
}
});
try{ try{
reads.each(Runnable::run); run.run();
postreads.each(Runnable::run); }catch(Throwable t){
}catch(Exception e){ //don't overwrite double errors
Vars.mods.handleError(new ModLoadException("Error occurred parsing content: " + currentContent, currentContent, e), currentMod); markError(currentContent, t);
} }
}
public void finishParsing(){
reads.each(this::attempt);
postreads.each(this::attempt);
reads.clear(); reads.clear();
postreads.clear(); postreads.clear();
toBeParsed.clear(); toBeParsed.clear();
@@ -433,7 +430,6 @@ public class ContentParser{
currentMod = mod; currentMod = mod;
boolean located = locate(type, name) != null; boolean located = locate(type, name) != null;
Content c = parsers.get(type).parse(mod.name, name, value); Content c = parsers.get(type).parse(mod.name, name, value);
c.minfo = new ModContentInfo();
c.minfo.sourceFile = file; c.minfo.sourceFile = file;
toBeParsed.add(c); toBeParsed.add(c);
@@ -444,15 +440,17 @@ public class ContentParser{
} }
public void markError(Content content, LoadedMod mod, FileHandle file, Throwable error){ public void markError(Content content, LoadedMod mod, FileHandle file, Throwable error){
if(content.minfo == null){
content.minfo = new ModContentInfo();
}
content.minfo.mod = mod; content.minfo.mod = mod;
content.minfo.sourceFile = file; content.minfo.sourceFile = file;
content.minfo.error = Strings.parseException(error, true); content.minfo.error = Strings.parseException(error, true);
} }
public void markError(Content content, Throwable error){
if(content.minfo != null && !content.hasErrored()){
markError(content, content.minfo.mod, content.minfo.sourceFile, error);
}
}
private <T extends MappableContent> T locate(ContentType type, String name){ private <T extends MappableContent> T locate(ContentType type, String name){
T first = Vars.content.getByName(type, name); //try vanilla replacement T first = Vars.content.getByName(type, name); //try vanilla replacement
return first != null ? first : Vars.content.getByName(type, currentMod.name + "-" + name); return first != null ? first : Vars.content.getByName(type, currentMod.name + "-" + name);

View File

@@ -1,14 +0,0 @@
package io.anuke.mindustry.mod;
import io.anuke.arc.files.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.mod.Mods.*;
public class ModContentInfo{
/** The mod that loaded this piece of content. */
public @Nullable LoadedMod mod;
/** File that this content was loaded from. */
public FileHandle sourceFile;
/** The error that occurred during loading, if applicable. Null if no error occurred. */
public @Nullable String error;
}

View File

@@ -1,19 +1,9 @@
package io.anuke.mindustry.mod; package io.anuke.mindustry.mod;
import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.mod.Mods.*;
import io.anuke.mindustry.ui.*;
public class ModCrashHandler{ public class ModCrashHandler{
public static void handle(Throwable t){ public static void handle(Throwable t){
/*
Array<Throwable> list = Strings.getCauses(t); Array<Throwable> list = Strings.getCauses(t);
Throwable modCause = list.find(e -> e instanceof ModLoadException); Throwable modCause = list.find(e -> e instanceof ModLoadException);
@@ -62,6 +52,6 @@ public class ModCrashHandler{
}); });
}else{ }else{
throw new RuntimeException(t); throw new RuntimeException(t);
} }*/
} }
} }

View File

@@ -149,7 +149,7 @@ public class Mods implements Loadable{
//generate new icons //generate new icons
for(Array<Content> arr : content.getContentMap()){ for(Array<Content> arr : content.getContentMap()){
arr.each(c -> { arr.each(c -> {
if(c instanceof UnlockableContent && c.minfo != null && c.minfo.mod != null){ if(c instanceof UnlockableContent && c.minfo.mod != null){
UnlockableContent u = (UnlockableContent)c; UnlockableContent u = (UnlockableContent)c;
u.createIcons(packer); u.createIcons(packer);
} }
@@ -465,12 +465,16 @@ public class Mods implements Loadable{
//make sure mod content is in proper order //make sure mod content is in proper order
runs.sort(); runs.sort();
for(LoadRun l : runs){ for(LoadRun l : runs){
Content current = content.getLastAdded();
try{ try{
//this binds the content but does not load it entirely //this binds the content but does not load it entirely
Content loaded = parser.parse(l.mod, l.file.nameWithoutExtension(), l.file.readString("UTF-8"), l.file, l.type); Content loaded = parser.parse(l.mod, l.file.nameWithoutExtension(), l.file.readString("UTF-8"), l.file, l.type);
Log.debug("[{0}] Loaded '{1}'.", l.mod.meta.name, (loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded)); Log.debug("[{0}] Loaded '{1}'.", l.mod.meta.name, (loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded));
}catch(Throwable e){ }catch(Throwable e){
throw new RuntimeException("Failed to parse content file '" + l.file + "' for mod '" + l.mod.meta.name + "'.", e); if(current != content.getLastAdded() && content.getLastAdded() != null){
parser.markError(content.getLastAdded(), l.mod, l.file, e);
}
//throw new RuntimeException("Failed to parse content file '" + l.file + "' for mod '" + l.mod.meta.name + "'.", e);
} }
} }
@@ -478,6 +482,10 @@ public class Mods implements Loadable{
parser.finishParsing(); parser.finishParsing();
} }
public void handleContentError(Content content, Throwable error){
parser.markError(content, error);
}
/** @return all loaded mods. */ /** @return all loaded mods. */
public Array<LoadedMod> all(){ public Array<LoadedMod> all(){
return loaded; return loaded;

View File

@@ -172,8 +172,8 @@ public class Zone extends UnlockableContent{
@Override @Override
public void init(){ public void init(){
if(generator instanceof MapGenerator && mod != null){ if(generator instanceof MapGenerator && minfo.mod != null){
((MapGenerator)generator).removePrefix(mod.name); ((MapGenerator)generator).removePrefix(minfo.mod.name);
} }
generator.init(loadout); generator.init(loadout);

View File

@@ -10,7 +10,6 @@ import io.anuke.arc.util.io.*;
import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.Saves.*; import io.anuke.mindustry.game.Saves.*;
import io.anuke.mindustry.io.*; import io.anuke.mindustry.io.*;
import io.anuke.mindustry.mod.*;
import io.anuke.mindustry.ui.*; import io.anuke.mindustry.ui.*;
import org.robovm.apple.coregraphics.*; import org.robovm.apple.coregraphics.*;
import org.robovm.apple.foundation.*; import org.robovm.apple.foundation.*;
@@ -153,7 +152,7 @@ public class IOSLauncher extends IOSApplication.Delegate{
UINavigationController.attemptRotationToDeviceOrientation(); UINavigationController.attemptRotationToDeviceOrientation();
} }
}, new IOSApplicationConfiguration(){{ }, new IOSApplicationConfiguration(){{
errorHandler = ModCrashHandler::handle; //errorHandler = ModCrashHandler::handle;
}}); }});
} }