Skip to content

Commit

Permalink
Fixed issues with Anuken#7972
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Feb 21, 2023
1 parent b00c5b4 commit df11dd7
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions core/src/mindustry/mod/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public class Mods implements Loadable{
private ObjectSet<String> specialFolders = ObjectSet.with("bundles", "sprites", "sprites-override");

private int totalSprites;
private static ObjectFloatMap<String> textureResize = new ObjectFloatMap<>();
private ObjectFloatMap<String> textureResize = new ObjectFloatMap<>();
private MultiPacker packer;

/** Ordered mods cache. Set to null to invalidate. */
private @Nullable Seq<LoadedMod> lastOrderedMods = new Seq<>();

private ModClassLoader mainLoader = new ModClassLoader(getClass().getClassLoader());

Seq<LoadedMod> mods = new Seq<>();
Expand Down Expand Up @@ -106,6 +109,8 @@ public LoadedMod importMod(Fi file) throws IOException{
try{
var loaded = loadMod(dest, true, true);
mods.add(loaded);
//invalidate ordered mods cache
lastOrderedMods = null;
requiresReload = true;
//enable the mod on import
Core.settings.put("mod-" + loaded.name + "-enabled", true);
Expand Down Expand Up @@ -463,6 +468,8 @@ public void load(){
LoadedMod mod = loadMod(file, false, entry.value == ModState.enabled);
mod.state = entry.value;
mods.add(mod);
//invalidate ordered mods cache
lastOrderedMods = null;
if(steam) mod.addSteamID(file.name());
}catch(Throwable e){
if(e instanceof ClassNotFoundException && e.getMessage().contains("mindustry.plugin.Plugin")){
Expand All @@ -481,7 +488,7 @@ public void load(){
mods.each(this::updateDependencies);
for(var mod : mods){
// Skip mods where the state has already been resolved
if(mod.state != ModState.enabled)continue;
if(mod.state != ModState.enabled) continue;
if(!mod.isSupported()){
mod.state = ModState.unsupported;
}else if(!mod.shouldBeEnabled()){
Expand Down Expand Up @@ -512,8 +519,15 @@ private void updateDependencies(LoadedMod mod){

/** @return mods ordered in the correct way needed for dependencies. */
public Seq<LoadedMod> orderedMods(){
var mapping = mods.asMap(m -> m.meta.name);
return resolveDependencies(mods.map(m -> m.meta)).orderedKeys().map(mapping::get);
//update cache if it's "dirty"/empty
if(lastOrderedMods == null){
//only enabled mods participate; this state is resolved in load()
Seq<LoadedMod> enabled = mods.select(LoadedMod::enabled);

var mapping = enabled.asMap(m -> m.meta.name);
lastOrderedMods = resolveDependencies(enabled.map(m -> m.meta)).orderedKeys().map(mapping::get);
}
return lastOrderedMods;
}

public LoadedMod locateMod(String name){
Expand All @@ -522,8 +536,6 @@ public LoadedMod locateMod(String name){

private void buildFiles(){
for(LoadedMod mod : orderedMods()){
if(!mod.shouldBeEnabled()) continue;

boolean zipFolder = !mod.file.isDirectory() && mod.root.parent() != null;
String parentName = zipFolder ? mod.root.name() : null;
for(Fi file : mod.root.list()){
Expand Down

0 comments on commit df11dd7

Please sign in to comment.