AllLangPartials also now supports more mod ids

This commit is contained in:
FortressNebula 2022-11-06 12:24:37 +00:00
parent f0311f3245
commit e053c9240f
3 changed files with 48 additions and 15 deletions

View file

@ -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<JsonElement> 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;
}
}

View file

@ -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<JsonElement> getDefault() { return this::fromResource; }
}

View file

@ -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<Object> mergedLangData;
private Map<String, List<Object>> populatedLangData;
@ -49,12 +50,15 @@ public class LangMerger implements DataProvider {
private List<String> 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 <T extends ILangPartial> 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());
}