Possibly fixed tests / Added support for mod icons

This commit is contained in:
Anuken
2019-12-26 20:53:53 -05:00
parent c339a0ecdf
commit 6080a7e4bc
2 changed files with 24 additions and 2 deletions

View File

@@ -2,7 +2,6 @@ package mindustry.mod;
import arc.*; import arc.*;
import arc.assets.*; import arc.assets.*;
import arc.struct.*;
import arc.files.*; import arc.files.*;
import arc.func.*; import arc.func.*;
import arc.graphics.*; import arc.graphics.*;
@@ -10,6 +9,7 @@ import arc.graphics.Texture.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.graphics.g2d.TextureAtlas.*; import arc.graphics.g2d.TextureAtlas.*;
import arc.scene.ui.*; import arc.scene.ui.*;
import arc.struct.*;
import arc.util.*; import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.io.*; import arc.util.io.*;
@@ -142,6 +142,17 @@ public class Mods implements Loadable{
@Override @Override
public void loadSync(){ 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; if(packer == null) return;
Time.mark(); Time.mark();
@@ -408,6 +419,7 @@ public class Mods implements Loadable{
//TODO make it less epic //TODO make it less epic
Core.atlas = new TextureAtlas(Core.files.internal("sprites/sprites.atlas")); Core.atlas = new TextureAtlas(Core.files.internal("sprites/sprites.atlas"));
mods.each(LoadedMod::dispose);
mods.clear(); mods.clear();
Core.bundle = I18NBundle.createBundle(Core.files.internal("bundles/bundle"), Core.bundle.getLocale()); Core.bundle = I18NBundle.createBundle(Core.files.internal("bundles/bundle"), Core.bundle.getLocale());
load(); load();
@@ -643,7 +655,7 @@ public class Mods implements Loadable{
} }
/** Represents a plugin that has been loaded from a jar file.*/ /** 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. */ /** The location of this mod's zip file/folder on the disk. */
public final Fi file; 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. */ /** 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<Content> erroredContent = new ObjectSet<>(); public ObjectSet<Content> erroredContent = new ObjectSet<>();
/** Current state of this mod. */ /** Current state of this mod. */
public ModState state = ModState.enabled; public ModState state = ModState.enabled;
/** Icon texture. Should be disposed. */
public @Nullable Texture iconTexture;
public LoadedMod(Fi file, Fi root, Mod main, ModMeta meta){ public LoadedMod(Fi file, Fi root, Mod main, ModMeta meta){
this.root = root; this.root = root;
@@ -701,6 +715,13 @@ public class Mods implements Loadable{
return Version.build >= Strings.parseInt(meta.minGameVersion, 0); return Version.build >= Strings.parseInt(meta.minGameVersion, 0);
} }
@Override
public void dispose(){
if(iconTexture != null){
iconTexture.dispose();
}
}
@Override @Override
public String getSteamID(){ public String getSteamID(){
return Core.settings.getString(name + "-steamid", null); return Core.settings.getString(name + "-steamid", null);

View File

@@ -27,6 +27,7 @@ public class PowerTestFixture{
@BeforeAll @BeforeAll
static void initializeDependencies(){ static void initializeDependencies(){
Core.graphics = new FakeGraphics(); Core.graphics = new FakeGraphics();
Vars.state = new GameState();
Vars.content = new ContentLoader(){ Vars.content = new ContentLoader(){
@Override @Override
public void handleMappableContent(MappableContent content){ public void handleMappableContent(MappableContent content){