From 9d3dda035c2fc2d9fdf9614a99194b78e8aff44a Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 14 Dec 2019 12:53:37 -0500 Subject: [PATCH] Compile fixes --- .../io/anuke/mindustry/AndroidLauncher.java | 3 +- .../anuke/mindustry/core/ContentLoader.java | 6 ++-- .../src/io/anuke/mindustry/ctype/Content.java | 16 +++++++-- .../io/anuke/mindustry/mod/ContentParser.java | 36 +++++++++---------- .../anuke/mindustry/mod/ModContentInfo.java | 14 -------- .../anuke/mindustry/mod/ModCrashHandler.java | 14 ++------ core/src/io/anuke/mindustry/mod/Mods.java | 12 +++++-- core/src/io/anuke/mindustry/type/Zone.java | 4 +-- ios/src/io/anuke/mindustry/IOSLauncher.java | 3 +- 9 files changed, 49 insertions(+), 59 deletions(-) delete mode 100644 core/src/io/anuke/mindustry/mod/ModContentInfo.java diff --git a/android/src/io/anuke/mindustry/AndroidLauncher.java b/android/src/io/anuke/mindustry/AndroidLauncher.java index 24c223d2d6..e34e7ee1c4 100644 --- a/android/src/io/anuke/mindustry/AndroidLauncher.java +++ b/android/src/io/anuke/mindustry/AndroidLauncher.java @@ -18,7 +18,6 @@ import io.anuke.arc.util.*; import io.anuke.arc.util.serialization.*; import io.anuke.mindustry.game.Saves.*; import io.anuke.mindustry.io.*; -import io.anuke.mindustry.mod.*; import io.anuke.mindustry.ui.dialogs.*; import java.io.*; @@ -144,7 +143,7 @@ public class AndroidLauncher extends AndroidApplication{ useImmersiveMode = true; depth = 0; hideStatusBar = true; - errorHandler = ModCrashHandler::handle; + //errorHandler = ModCrashHandler::handle; }}); checkFiles(getIntent()); } diff --git a/core/src/io/anuke/mindustry/core/ContentLoader.java b/core/src/io/anuke/mindustry/core/ContentLoader.java index 52c2c865e0..25f425c8f9 100644 --- a/core/src/io/anuke/mindustry/core/ContentLoader.java +++ b/core/src/io/anuke/mindustry/core/ContentLoader.java @@ -115,8 +115,8 @@ public class ContentLoader{ try{ callable.get(content); }catch(Throwable e){ - if(content.mod != null){ - mods.handleError(new ModLoadException(content, e), content.mod); + if(content.minfo.mod != null){ + mods.handleContentError(content, e); }else{ 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 + "')"); } if(currentMod != null){ - content.mod = currentMod; + content.minfo.mod = currentMod; } contentNameMap[content.getContentType().ordinal()].put(content.name, content); } diff --git a/core/src/io/anuke/mindustry/ctype/Content.java b/core/src/io/anuke/mindustry/ctype/Content.java index 0e3706746b..0bcc89af14 100644 --- a/core/src/io/anuke/mindustry/ctype/Content.java +++ b/core/src/io/anuke/mindustry/ctype/Content.java @@ -1,8 +1,9 @@ package io.anuke.mindustry.ctype; +import io.anuke.arc.files.*; import io.anuke.arc.util.ArcAnnotate.*; import io.anuke.mindustry.*; -import io.anuke.mindustry.mod.*; +import io.anuke.mindustry.mod.Mods.*; import io.anuke.mindustry.type.*; @@ -10,7 +11,7 @@ import io.anuke.mindustry.type.*; public abstract class Content implements Comparable{ public final short id; /** Info on which mod this content was loaded from. */ - public @Nullable ModContentInfo minfo; + public @NonNull ModContentInfo minfo = new ModContentInfo(); public Content(){ @@ -37,7 +38,7 @@ public abstract class Content implements Comparable{ /** @return whether an error ocurred during mod loading. */ public boolean hasErrored(){ - return minfo != null && minfo.error != null; + return minfo.error != null; } @Override @@ -49,4 +50,13 @@ public abstract class Content implements Comparable{ public String toString(){ 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; + } } diff --git a/core/src/io/anuke/mindustry/mod/ContentParser.java b/core/src/io/anuke/mindustry/mod/ContentParser.java index 99def211c7..09a030e1e6 100644 --- a/core/src/io/anuke/mindustry/mod/ContentParser.java +++ b/core/src/io/anuke/mindustry/mod/ContentParser.java @@ -266,7 +266,7 @@ public class ContentParser{ TechNode parnode = TechTree.all.find(t -> t.block == parent); 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)){ parnode.children.add(baseNode); @@ -386,21 +386,18 @@ public class ContentParser{ } } - public void finishParsing(){ - reads.each(c -> { - try{ - c.run(); - }catch(Throwable t){ - - } - }); - + private void attempt(Runnable run){ try{ - reads.each(Runnable::run); - postreads.each(Runnable::run); - }catch(Exception e){ - Vars.mods.handleError(new ModLoadException("Error occurred parsing content: " + currentContent, currentContent, e), currentMod); + run.run(); + }catch(Throwable t){ + //don't overwrite double errors + markError(currentContent, t); } + } + + public void finishParsing(){ + reads.each(this::attempt); + postreads.each(this::attempt); reads.clear(); postreads.clear(); toBeParsed.clear(); @@ -433,7 +430,6 @@ public class ContentParser{ currentMod = mod; boolean located = locate(type, name) != null; Content c = parsers.get(type).parse(mod.name, name, value); - c.minfo = new ModContentInfo(); c.minfo.sourceFile = file; toBeParsed.add(c); @@ -444,15 +440,17 @@ public class ContentParser{ } 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.sourceFile = file; 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 locate(ContentType type, String name){ T first = Vars.content.getByName(type, name); //try vanilla replacement return first != null ? first : Vars.content.getByName(type, currentMod.name + "-" + name); diff --git a/core/src/io/anuke/mindustry/mod/ModContentInfo.java b/core/src/io/anuke/mindustry/mod/ModContentInfo.java deleted file mode 100644 index 7d1fd105ca..0000000000 --- a/core/src/io/anuke/mindustry/mod/ModContentInfo.java +++ /dev/null @@ -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; -} diff --git a/core/src/io/anuke/mindustry/mod/ModCrashHandler.java b/core/src/io/anuke/mindustry/mod/ModCrashHandler.java index 77f3c68aba..507057acad 100644 --- a/core/src/io/anuke/mindustry/mod/ModCrashHandler.java +++ b/core/src/io/anuke/mindustry/mod/ModCrashHandler.java @@ -1,19 +1,9 @@ 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 static void handle(Throwable t){ + /* Array list = Strings.getCauses(t); Throwable modCause = list.find(e -> e instanceof ModLoadException); @@ -62,6 +52,6 @@ public class ModCrashHandler{ }); }else{ throw new RuntimeException(t); - } + }*/ } } diff --git a/core/src/io/anuke/mindustry/mod/Mods.java b/core/src/io/anuke/mindustry/mod/Mods.java index 7aa5fa21ea..737aa0ede6 100644 --- a/core/src/io/anuke/mindustry/mod/Mods.java +++ b/core/src/io/anuke/mindustry/mod/Mods.java @@ -149,7 +149,7 @@ public class Mods implements Loadable{ //generate new icons for(Array arr : content.getContentMap()){ 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; u.createIcons(packer); } @@ -465,12 +465,16 @@ public class Mods implements Loadable{ //make sure mod content is in proper order runs.sort(); for(LoadRun l : runs){ + Content current = content.getLastAdded(); try{ //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); Log.debug("[{0}] Loaded '{1}'.", l.mod.meta.name, (loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded)); }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(); } + public void handleContentError(Content content, Throwable error){ + parser.markError(content, error); + } + /** @return all loaded mods. */ public Array all(){ return loaded; diff --git a/core/src/io/anuke/mindustry/type/Zone.java b/core/src/io/anuke/mindustry/type/Zone.java index c60249b223..12686bb3da 100644 --- a/core/src/io/anuke/mindustry/type/Zone.java +++ b/core/src/io/anuke/mindustry/type/Zone.java @@ -172,8 +172,8 @@ public class Zone extends UnlockableContent{ @Override public void init(){ - if(generator instanceof MapGenerator && mod != null){ - ((MapGenerator)generator).removePrefix(mod.name); + if(generator instanceof MapGenerator && minfo.mod != null){ + ((MapGenerator)generator).removePrefix(minfo.mod.name); } generator.init(loadout); diff --git a/ios/src/io/anuke/mindustry/IOSLauncher.java b/ios/src/io/anuke/mindustry/IOSLauncher.java index 7f4783d1a8..50b1732892 100644 --- a/ios/src/io/anuke/mindustry/IOSLauncher.java +++ b/ios/src/io/anuke/mindustry/IOSLauncher.java @@ -10,7 +10,6 @@ import io.anuke.arc.util.io.*; import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.Saves.*; import io.anuke.mindustry.io.*; -import io.anuke.mindustry.mod.*; import io.anuke.mindustry.ui.*; import org.robovm.apple.coregraphics.*; import org.robovm.apple.foundation.*; @@ -153,7 +152,7 @@ public class IOSLauncher extends IOSApplication.Delegate{ UINavigationController.attemptRotationToDeviceOrientation(); } }, new IOSApplicationConfiguration(){{ - errorHandler = ModCrashHandler::handle; + //errorHandler = ModCrashHandler::handle; }}); }