From 76f85df33f78d5228983b6573c58b719f7c6f2a5 Mon Sep 17 00:00:00 2001 From: Leo-MathGuy Date: Wed, 24 Apr 2024 20:12:57 +0500 Subject: [PATCH] Added content order --- core/src/mindustry/mod/Mods.java | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 9e8e6b2b2b..251452162d 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -728,6 +728,9 @@ public class Mods implements Loadable{ Seq runs = new Seq<>(); for(LoadedMod mod : orderedMods()){ + ObjectMap currentRun = new ObjectMap<>(); + String[] contentOrder = mod.meta.contentOrder; + if(mod.root.child("content").exists()){ Fi contentRoot = mod.root.child("content"); for(ContentType type : ContentType.all){ @@ -735,15 +738,34 @@ public class Mods implements Loadable{ Fi folder = contentRoot.child(lower + (lower.endsWith("s") ? "" : "s")); if(folder.exists()){ for(Fi file : folder.findAll(f -> f.extension().equals("json") || f.extension().equals("hjson"))){ - runs.add(new LoadRun(type, file, mod)); + if(contentOrder == null){ + runs.add(new LoadRun(type, file, mod)); + }else{ + currentRun.put(file.nameWithoutExtension(), new LoadRun(type, file, mod)); + } } } } } + + Seq added = new Seq<>(); + if(contentOrder != null){ + for (String contentName : contentOrder){ + LoadRun run = currentRun.get(contentName); + if(run != null){ + runs.add(run); + added.add(contentName); + }else{ + Log.warn("Cannot find content defined in contentOrder: @", contentName); + } + } + } + + Seq left = currentRun.keys().toSeq(); + left.removeAll(added); + runs.addAll(left.map(name -> currentRun.get(name)).sort()); } - //make sure mod content is in proper order - runs.sort(); for(LoadRun l : runs){ Content current = content.getLastAdded(); try{ @@ -1210,6 +1232,8 @@ public class Mods implements Loadable{ public float texturescale = 1.0f; /** If true, bleeding is skipped and no content icons are generated. */ public boolean pregenerated; + /** If set, load the mod content in this order by content names */ + public String[] contentOrder; public String displayName(){ //useless, kept for legacy reasons