From e053c9240fa1656a6a7f5305cdb620dcd8ddd06f Mon Sep 17 00:00:00 2001 From: FortressNebula Date: Sun, 6 Nov 2022 12:24:37 +0000 Subject: [PATCH] AllLangPartials also now supports more mod ids --- .../foundation/data/AllLangPartials.java | 22 +++++++------- .../create/foundation/data/ILangPartial.java | 29 +++++++++++++++++++ .../create/foundation/data/LangMerger.java | 12 +++++--- 3 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/data/ILangPartial.java diff --git a/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java b/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java index 436839f30..a88966147 100644 --- a/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java +++ b/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java @@ -9,7 +9,9 @@ import com.simibubi.create.foundation.ponder.PonderLocalization; import com.simibubi.create.foundation.utility.FilesHelper; import com.simibubi.create.foundation.utility.Lang; -public enum AllLangPartials { +import java.util.List; + +public enum AllLangPartials implements ILangPartial { ADVANCEMENTS("Advancements", AllAdvancements::provideLangEntries), INTERFACE("UI & Messages"), @@ -24,7 +26,7 @@ public enum AllLangPartials { private AllLangPartials(String display) { this.display = display; - this.provider = this::fromResource; + this.provider = getDefault(); } private AllLangPartials(String display, Supplier customProvider) { @@ -32,21 +34,19 @@ public enum AllLangPartials { this.provider = customProvider; } + @Override public String getDisplay() { return display; } + @Override + public String getFileName() { + return Lang.asId(name()); + } + + @Override public JsonElement provide() { return provider.get(); } - private JsonElement fromResource() { - String fileName = Lang.asId(name()); - String filepath = "assets/" + Create.ID + "/lang/default/" + fileName + ".json"; - JsonElement element = FilesHelper.loadJsonResource(filepath); - if (element == null) - throw new IllegalStateException(String.format("Could not find default lang file: %s", filepath)); - return element; - } - } diff --git a/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java b/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java new file mode 100644 index 000000000..f74d44fe8 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java @@ -0,0 +1,29 @@ +package com.simibubi.create.foundation.data; + +import com.google.common.base.Supplier; +import com.google.gson.JsonElement; +import com.simibubi.create.Create; +import com.simibubi.create.foundation.utility.FilesHelper; + +import java.util.List; + +public interface ILangPartial { + + String getDisplay(); + String getFileName(); + + default String getModID() { return Create.ID; } + + JsonElement provide(); + + private JsonElement fromResource() { + String fileName = getFileName(); + String filepath = "assets/" + getModID() + "/lang/default/" + fileName + ".json"; + JsonElement element = FilesHelper.loadJsonResource(filepath); + if (element == null) + throw new IllegalStateException(String.format("Could not find default lang file: %s", filepath)); + return element; + } + + default Supplier getDefault() { return this::fromResource; } +} diff --git a/src/main/java/com/simibubi/create/foundation/data/LangMerger.java b/src/main/java/com/simibubi/create/foundation/data/LangMerger.java index 9bbf8abe7..90fd5d109 100644 --- a/src/main/java/com/simibubi/create/foundation/data/LangMerger.java +++ b/src/main/java/com/simibubi/create/foundation/data/LangMerger.java @@ -41,6 +41,7 @@ public class LangMerger implements DataProvider { private DataGenerator gen; private final String modid; private final String displayName; + private final ILangPartial[] langPartials; private List mergedLangData; private Map> populatedLangData; @@ -49,12 +50,15 @@ public class LangMerger implements DataProvider { private List langIgnore; - public LangMerger(DataGenerator gen) { this(gen, Create.ID, "Create"); } + public LangMerger(DataGenerator gen) { + this(gen, Create.ID, "Create", AllLangPartials.values()); + } - public LangMerger(DataGenerator gen, String modid, String displayName) { + public LangMerger(DataGenerator gen, String modid, String displayName, T[] langPartials) { this.gen = gen; this.modid = modid; this.displayName = displayName; + this.langPartials = langPartials; this.mergedLangData = new ArrayList<>(); this.langIgnore = new ArrayList<>(); this.allLocalizedEntries = new HashMap<>(); @@ -66,7 +70,7 @@ public class LangMerger implements DataProvider { private void populateLangIgnore() { // Key prefixes added here will NOT be transferred to lang templates langIgnore.add("create.ponder.debug_"); // Ponder debug scene text - langIgnore.add("create.gui.chromatic_projector"); + langIgnore.add("create.gui.chromatic_projector"); } private boolean shouldIgnore(String key) { @@ -225,7 +229,7 @@ public class LangMerger implements DataProvider { } private void collectEntries() { - for (AllLangPartials partial : AllLangPartials.values()) + for (ILangPartial partial : langPartials) addAll(partial.getDisplay(), partial.provide() .getAsJsonObject()); }