From 6080a7e4bcb9972c208630a8295c92f328a9054a Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 26 Dec 2019 20:53:53 -0500 Subject: [PATCH] Possibly fixed tests / Added support for mod icons --- core/src/mindustry/mod/Mods.java | 25 +++++++++++++++++-- .../src/test/java/power/PowerTestFixture.java | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index e4da45357b..b92b2fefc5 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -2,7 +2,6 @@ package mindustry.mod; import arc.*; import arc.assets.*; -import arc.struct.*; import arc.files.*; import arc.func.*; import arc.graphics.*; @@ -10,6 +9,7 @@ import arc.graphics.Texture.*; import arc.graphics.g2d.*; import arc.graphics.g2d.TextureAtlas.*; import arc.scene.ui.*; +import arc.struct.*; import arc.util.*; import arc.util.ArcAnnotate.*; import arc.util.io.*; @@ -142,6 +142,17 @@ public class Mods implements Loadable{ @Override public void loadSync(){ + for(LoadedMod mod : mods){ + //try to load icon for each mod that can have one + if(mod.root.child("icon.png").exists()){ + try{ + mod.iconTexture = new Texture(mod.root.child("icon.png")); + }catch(Throwable t){ + Log.err("Failed to load icon for mod '" + mod.name + "'.", t); + } + } + } + if(packer == null) return; Time.mark(); @@ -408,6 +419,7 @@ public class Mods implements Loadable{ //TODO make it less epic Core.atlas = new TextureAtlas(Core.files.internal("sprites/sprites.atlas")); + mods.each(LoadedMod::dispose); mods.clear(); Core.bundle = I18NBundle.createBundle(Core.files.internal("bundles/bundle"), Core.bundle.getLocale()); load(); @@ -643,7 +655,7 @@ public class Mods implements Loadable{ } /** Represents a plugin that has been loaded from a jar file.*/ - public static class LoadedMod implements Publishable{ + public static class LoadedMod implements Publishable, Disposable{ /** The location of this mod's zip file/folder on the disk. */ public final Fi file; /** The root zip file; points to the contents of this mod. In the case of folders, this is the same as the mod's file. */ @@ -664,6 +676,8 @@ public class Mods implements Loadable{ public ObjectSet erroredContent = new ObjectSet<>(); /** Current state of this mod. */ public ModState state = ModState.enabled; + /** Icon texture. Should be disposed. */ + public @Nullable Texture iconTexture; public LoadedMod(Fi file, Fi root, Mod main, ModMeta meta){ this.root = root; @@ -701,6 +715,13 @@ public class Mods implements Loadable{ return Version.build >= Strings.parseInt(meta.minGameVersion, 0); } + @Override + public void dispose(){ + if(iconTexture != null){ + iconTexture.dispose(); + } + } + @Override public String getSteamID(){ return Core.settings.getString(name + "-steamid", null); diff --git a/tests/src/test/java/power/PowerTestFixture.java b/tests/src/test/java/power/PowerTestFixture.java index fd445a2c25..e5735052f5 100644 --- a/tests/src/test/java/power/PowerTestFixture.java +++ b/tests/src/test/java/power/PowerTestFixture.java @@ -27,6 +27,7 @@ public class PowerTestFixture{ @BeforeAll static void initializeDependencies(){ Core.graphics = new FakeGraphics(); + Vars.state = new GameState(); Vars.content = new ContentLoader(){ @Override public void handleMappableContent(MappableContent content){