From 76f85df33f78d5228983b6573c58b719f7c6f2a5 Mon Sep 17 00:00:00 2001 From: Leo-MathGuy Date: Wed, 24 Apr 2024 20:12:57 +0500 Subject: [PATCH 1/6] 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 From 1622ecd0105d1998994a408c69f44d61ed0e7d62 Mon Sep 17 00:00:00 2001 From: Leo-MathGuy Date: Thu, 25 Apr 2024 19:41:05 +0500 Subject: [PATCH 2/6] Fixed double seq --- core/src/mindustry/mod/Mods.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 251452162d..c31f648637 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -748,21 +748,19 @@ public class Mods implements Loadable{ } } - Seq added = new Seq<>(); + Seq left = currentRun.keys().toSeq(); if(contentOrder != null){ for (String contentName : contentOrder){ LoadRun run = currentRun.get(contentName); if(run != null){ runs.add(run); - added.add(contentName); + left.remove(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()); } From 617953dd89dd99999f5e899de74590d975715652 Mon Sep 17 00:00:00 2001 From: Leo-MathGuy Date: Thu, 25 Apr 2024 19:44:44 +0500 Subject: [PATCH 3/6] format --- core/src/mindustry/mod/Mods.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index c31f648637..0e5580a944 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -738,11 +738,7 @@ 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"))){ - if(contentOrder == null){ - runs.add(new LoadRun(type, file, mod)); - }else{ - currentRun.put(file.nameWithoutExtension(), new LoadRun(type, file, mod)); - } + currentRun.put(file.nameWithoutExtension(), new LoadRun(type, file, mod)); } } } From 56c68fef9ccdbeca4a147a0d73c10d5b9fbe9b0e Mon Sep 17 00:00:00 2001 From: Leo-MathGuy Date: Thu, 25 Apr 2024 19:55:51 +0500 Subject: [PATCH 4/6] how did a format change make the test fail --- core/src/mindustry/mod/Mods.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 0e5580a944..98caf3c8b3 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -744,8 +744,8 @@ public class Mods implements Loadable{ } } - Seq left = currentRun.keys().toSeq(); if(contentOrder != null){ + Seq left = currentRun.keys().toSeq(); for (String contentName : contentOrder){ LoadRun run = currentRun.get(contentName); if(run != null){ @@ -755,9 +755,10 @@ public class Mods implements Loadable{ Log.warn("Cannot find content defined in contentOrder: @", contentName); } } + runs.addAll(left.map(name -> currentRun.get(name)).sort()); + }else{ + runs.addAll(currentRun.values().toSeq().sort()); } - - runs.addAll(left.map(name -> currentRun.get(name)).sort()); } for(LoadRun l : runs){ From d9cc2ef9a4fd806ce9fb858a949c873dcb728f96 Mon Sep 17 00:00:00 2001 From: Leo-MathGuy Date: Thu, 25 Apr 2024 19:59:08 +0500 Subject: [PATCH 5/6] sorting may be the problem --- core/src/mindustry/mod/Mods.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 98caf3c8b3..53acdc91c9 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -755,9 +755,9 @@ public class Mods implements Loadable{ Log.warn("Cannot find content defined in contentOrder: @", contentName); } } - runs.addAll(left.map(name -> currentRun.get(name)).sort()); + runs.addAll(left.map(name -> currentRun.get(name))); }else{ - runs.addAll(currentRun.values().toSeq().sort()); + runs.addAll(currentRun.values().toSeq()); } } From 0a7a3dc295ca1490f26d7681b4e1a330d36008dd Mon Sep 17 00:00:00 2001 From: Leo-MathGuy Date: Thu, 25 Apr 2024 20:03:38 +0500 Subject: [PATCH 6/6] Revert 3 commits --- core/src/mindustry/mod/Mods.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 53acdc91c9..c31f648637 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -738,14 +738,18 @@ 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"))){ - currentRun.put(file.nameWithoutExtension(), 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 left = currentRun.keys().toSeq(); if(contentOrder != null){ - Seq left = currentRun.keys().toSeq(); for (String contentName : contentOrder){ LoadRun run = currentRun.get(contentName); if(run != null){ @@ -755,10 +759,9 @@ public class Mods implements Loadable{ Log.warn("Cannot find content defined in contentOrder: @", contentName); } } - runs.addAll(left.map(name -> currentRun.get(name))); - }else{ - runs.addAll(currentRun.values().toSeq()); } + + runs.addAll(left.map(name -> currentRun.get(name)).sort()); } for(LoadRun l : runs){