From a6d4454eb0c56b5843fc2032c69c9694f8208365 Mon Sep 17 00:00:00 2001 From: qcwxezda Date: Fri, 9 Jun 2023 22:35:12 -0400 Subject: [PATCH] 10.1 patch, see latest_changelog.txt --- latest_changelog.txt | 4 ++++ mod_info.json | 2 +- progsmod.version | 2 +- progsmod_settings.json | 3 +++ .../data/campaign/rulecmd/PSM_BuildInHullMod.java | 14 +++++++++++++- .../rulecmd/ui/plugins/BuildInSelector.java | 4 ++-- src/util/RecentBuildInTracker.java | 3 +-- src/util/SModUtils.java | 2 ++ 8 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 latest_changelog.txt diff --git a/latest_changelog.txt b/latest_changelog.txt new file mode 100644 index 0000000..b1a40b6 --- /dev/null +++ b/latest_changelog.txt @@ -0,0 +1,4 @@ +- Made recent built-in list size a setting, default size 10 -> 20 +- Recent built-in list is now sorted alphabetically +- Fix NPE on hull mods with null unapplicableReason +- Fix no_build_in being disregarded regardless of setting \ No newline at end of file diff --git a/mod_info.json b/mod_info.json index c41f00d..defcae9 100644 --- a/mod_info.json +++ b/mod_info.json @@ -2,7 +2,7 @@ "id": "progressiveSMods", "name": "Progressive S-Mods", "author": "qcwxezda", - "version": {"major":0, "minor":10, "patch":0}, + "version": {"major":0, "minor":10, "patch":1}, "dependencies": [], "description": "Ships gain XP during combat that can be spent to build in hull mods. Disables building in hull mods using story points.", "gameVersion": "0.96a-RC8", diff --git a/progsmod.version b/progsmod.version index 379ebc3..f41558c 100644 --- a/progsmod.version +++ b/progsmod.version @@ -6,6 +6,6 @@ { "major":0, "minor":10, - "patch":0, + "patch":1, }, } \ No newline at end of file diff --git a/progsmod_settings.json b/progsmod_settings.json index 59a9ff9..21ad1d7 100644 --- a/progsmod_settings.json +++ b/progsmod_settings.json @@ -1,4 +1,7 @@ { + # Maximum size of recently-built-in list + "recentlyBuiltInListSize": 20, + # Deployment cost increase per additional s-mod, # as fraction of base DP cost "deploymentCostPenalty": 0.08, diff --git a/src/progsmod/data/campaign/rulecmd/PSM_BuildInHullMod.java b/src/progsmod/data/campaign/rulecmd/PSM_BuildInHullMod.java index d755ab3..48260b5 100644 --- a/src/progsmod/data/campaign/rulecmd/PSM_BuildInHullMod.java +++ b/src/progsmod/data/campaign/rulecmd/PSM_BuildInHullMod.java @@ -171,7 +171,19 @@ public boolean hasCancelButton() { @Override public void showRecentPressed(CustomPanelAPI panel, TooltipMakerAPI tooltipMaker) { List newButtonData = new ArrayList<>(); - for (String id : RecentBuildInTracker.getRecentlyBuiltIn()) { + List recentlyBuiltIn = new ArrayList<>(RecentBuildInTracker.getRecentlyBuiltIn()); + Collections.sort(recentlyBuiltIn, new Comparator() { + @Override + public int compare(String s1, String s2) { + HullModSpecAPI spec1 = Global.getSettings().getHullModSpec(s1); + String name1 = spec1 == null ? "zzzunknown" : spec1.getDisplayName(); + HullModSpecAPI spec2 = Global.getSettings().getHullModSpec(s2); + String name2 = spec2 == null ? "zzzunknown" : spec2.getDisplayName(); + return name1.compareTo(name2); + } + }); + + for (String id : recentlyBuiltIn) { if (selectedVariant.hasHullMod(id)) { continue; } diff --git a/src/progsmod/data/campaign/rulecmd/ui/plugins/BuildInSelector.java b/src/progsmod/data/campaign/rulecmd/ui/plugins/BuildInSelector.java index 1b4f23c..2a816a5 100644 --- a/src/progsmod/data/campaign/rulecmd/ui/plugins/BuildInSelector.java +++ b/src/progsmod/data/campaign/rulecmd/ui/plugins/BuildInSelector.java @@ -133,7 +133,7 @@ private BitSet disableUnapplicable() { // Can build in any number of logistics hull mods // Don't use s-mods in the check ship as we want to be able to tell when incompatibilities arise // via forcible removing of non s-mods - if (!reason.startsWith("Maximum of 2 non-built-in \"Logistics\"")) { + if (reason != null && !reason.startsWith("Maximum of 2 non-built-in \"Logistics\"")) { disableText = SModUtils.shortenText(reason, button.description); shouldDisable = true; } @@ -149,7 +149,7 @@ else if (interactionTarget != null && interactionTarget.getMarket() != null) { button.description); } } - if (hullMod.hasTag("progsmod_no_build_in") && !SModUtils.Constants.IGNORE_NO_BUILD_IN) { + if (hullMod.hasTag("no_build_in") && !SModUtils.Constants.IGNORE_NO_BUILD_IN) { shouldDisable = true; disableText = hullMod.getDisplayName() + " can't be built in"; } diff --git a/src/util/RecentBuildInTracker.java b/src/util/RecentBuildInTracker.java index b9db84d..2078c08 100644 --- a/src/util/RecentBuildInTracker.java +++ b/src/util/RecentBuildInTracker.java @@ -7,7 +7,6 @@ import java.util.Map; public class RecentBuildInTracker { - public static final int recentlyBuiltInMaxSize = 10; public static final String DATA_KEY = "progsmod_RecentlyBuiltIn"; public static void addToRecentlyBuiltIn(String id) { @@ -22,7 +21,7 @@ public static void addToRecentlyBuiltIn(String id) { recentlyBuiltIn.remove(id); recentlyBuiltIn.addFirst(id); - if (recentlyBuiltIn.size() > recentlyBuiltInMaxSize) { + while (recentlyBuiltIn.size() > SModUtils.Constants.MAX_RECENTLY_BUILT_IN_SIZE) { recentlyBuiltIn.removeLast(); } } diff --git a/src/util/SModUtils.java b/src/util/SModUtils.java index cb81877..a9fa154 100644 --- a/src/util/SModUtils.java +++ b/src/util/SModUtils.java @@ -49,6 +49,7 @@ public enum GrowthType {LINEAR, EXPONENTIAL}; public static ReserveXPTable RESERVE_XP_TABLE = new ReserveXPTable(); public static class Constants { + public static int MAX_RECENTLY_BUILT_IN_SIZE; /** How many story points it costs to unlock the first extra SMod slot. */ public static int BASE_EXTRA_SMOD_SP_COST_FRIGATE; public static int BASE_EXTRA_SMOD_SP_COST_DESTROYER; @@ -123,6 +124,7 @@ public static class Constants { /** Load constants from a json file */ private static void load(String filePath) throws IOException, JSONException { JSONObject json = Global.getSettings().loadJSON(filePath); + MAX_RECENTLY_BUILT_IN_SIZE = json.getInt("recentlyBuiltInListSize"); JSONObject augmentSP = json.getJSONObject("baseExtraSModSPCost"); BASE_EXTRA_SMOD_SP_COST_FRIGATE = augmentSP.getInt("frigate"); BASE_EXTRA_SMOD_SP_COST_DESTROYER = augmentSP.getInt("destroyer");