mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-18 16:02:19 +01:00
AllLangPartials also now supports more mod ids
This commit is contained in:
parent
f0311f3245
commit
e053c9240f
3 changed files with 48 additions and 15 deletions
|
@ -9,7 +9,9 @@ import com.simibubi.create.foundation.ponder.PonderLocalization;
|
||||||
import com.simibubi.create.foundation.utility.FilesHelper;
|
import com.simibubi.create.foundation.utility.FilesHelper;
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
import com.simibubi.create.foundation.utility.Lang;
|
||||||
|
|
||||||
public enum AllLangPartials {
|
import java.util.List;
|
||||||
|
|
||||||
|
public enum AllLangPartials implements ILangPartial {
|
||||||
|
|
||||||
ADVANCEMENTS("Advancements", AllAdvancements::provideLangEntries),
|
ADVANCEMENTS("Advancements", AllAdvancements::provideLangEntries),
|
||||||
INTERFACE("UI & Messages"),
|
INTERFACE("UI & Messages"),
|
||||||
|
@ -24,7 +26,7 @@ public enum AllLangPartials {
|
||||||
|
|
||||||
private AllLangPartials(String display) {
|
private AllLangPartials(String display) {
|
||||||
this.display = display;
|
this.display = display;
|
||||||
this.provider = this::fromResource;
|
this.provider = getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AllLangPartials(String display, Supplier<JsonElement> customProvider) {
|
private AllLangPartials(String display, Supplier<JsonElement> customProvider) {
|
||||||
|
@ -32,21 +34,19 @@ public enum AllLangPartials {
|
||||||
this.provider = customProvider;
|
this.provider = customProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDisplay() {
|
public String getDisplay() {
|
||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFileName() {
|
||||||
|
return Lang.asId(name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public JsonElement provide() {
|
public JsonElement provide() {
|
||||||
return provider.get();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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; }
|
||||||
|
}
|
|
@ -41,6 +41,7 @@ public class LangMerger implements DataProvider {
|
||||||
private DataGenerator gen;
|
private DataGenerator gen;
|
||||||
private final String modid;
|
private final String modid;
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
|
private final ILangPartial[] langPartials;
|
||||||
|
|
||||||
private List<Object> mergedLangData;
|
private List<Object> mergedLangData;
|
||||||
private Map<String, List<Object>> populatedLangData;
|
private Map<String, List<Object>> populatedLangData;
|
||||||
|
@ -49,12 +50,15 @@ public class LangMerger implements DataProvider {
|
||||||
|
|
||||||
private List<String> langIgnore;
|
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.gen = gen;
|
||||||
this.modid = modid;
|
this.modid = modid;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
|
this.langPartials = langPartials;
|
||||||
this.mergedLangData = new ArrayList<>();
|
this.mergedLangData = new ArrayList<>();
|
||||||
this.langIgnore = new ArrayList<>();
|
this.langIgnore = new ArrayList<>();
|
||||||
this.allLocalizedEntries = new HashMap<>();
|
this.allLocalizedEntries = new HashMap<>();
|
||||||
|
@ -225,7 +229,7 @@ public class LangMerger implements DataProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectEntries() {
|
private void collectEntries() {
|
||||||
for (AllLangPartials partial : AllLangPartials.values())
|
for (ILangPartial partial : langPartials)
|
||||||
addAll(partial.getDisplay(), partial.provide()
|
addAll(partial.getDisplay(), partial.provide()
|
||||||
.getAsJsonObject());
|
.getAsJsonObject());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue