diff options
| author | ilotterytea <iltsu@alright.party> | 2024-10-25 12:16:44 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-10-25 12:16:44 +0500 |
| commit | 354e2876e93bf45ca6b748e9eb23093fe9bffaa6 (patch) | |
| tree | 8637b646a6176b4808695d714443839c2624a961 /core/src/kz/ilotterytea/maxon/localization | |
| parent | f416c899aa619b21fad2f96f5f5a4475024557db (diff) | |
feat: LocalizationManager + removed unused lines and classes
Diffstat (limited to 'core/src/kz/ilotterytea/maxon/localization')
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/localization/LineId.java | 75 | ||||
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/localization/LocalizationManager.java | 70 |
2 files changed, 145 insertions, 0 deletions
diff --git a/core/src/kz/ilotterytea/maxon/localization/LineId.java b/core/src/kz/ilotterytea/maxon/localization/LineId.java new file mode 100644 index 0000000..3fe2203 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/localization/LineId.java @@ -0,0 +1,75 @@ +package kz.ilotterytea.maxon.localization; + +import org.slf4j.LoggerFactory; + +import java.util.Locale; + +public enum LineId { + UpdaterInfo, + + MenuContinue, + MenuReset, + + GiftboxOpen, + + MinigameSlotsSpinbutton, + MinigameSlotsExitbutton, + MinigameSlotsBet, + MinigameSlotsNothing, + MinigameSlotsPrize, + + PetBrorName, + PetBrorDesc, + PetSandwichName, + PetSandwichDesc, + PetManlooshkaName, + PetManlooshkaDesc, + PetThirstyName, + PetThirstyDesc, + PetFuriosName, + PetFuriosDesc, + PetTvcatName, + PetTvcatDesc, + PetProgcatName, + PetProgcatDesc, + PetScreamcatName, + PetScreamcatDesc, + PetHellcatName, + PetHellcatDesc, + PetLurkerName, + PetLurkerDesc, + PetPianoName, + PetPianoDesc, + PetBeeName, + PetBeeDesc, + PetBusyName, + PetBusyDesc, + PetAeaeName, + PetAeaeDesc, + PetSuccatName, + PetSuccatDesc, + ; + + public static LineId fromJson(String value) { + StringBuilder result = new StringBuilder(); + String[] chunks = value.split("\\."); + + for (String chunk : chunks) { + chunk = chunk.replace("_", ""); + + String firstLetter = chunk.substring(0, 1).toUpperCase(Locale.ROOT); + String otherPart = chunk.substring(1); + + result.append(firstLetter).append(otherPart); + } + + value = result.toString(); + + try { + return LineId.valueOf(value); + } catch (Exception e) { + LoggerFactory.getLogger(LineId.class.getName()).error("The key '{}' not registered in LineId enum", value); + return null; + } + } +} diff --git a/core/src/kz/ilotterytea/maxon/localization/LocalizationManager.java b/core/src/kz/ilotterytea/maxon/localization/LocalizationManager.java new file mode 100644 index 0000000..afa2841 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/localization/LocalizationManager.java @@ -0,0 +1,70 @@ +package kz.ilotterytea.maxon.localization; + +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.JsonReader; +import com.badlogic.gdx.utils.JsonValue; +import com.badlogic.gdx.utils.StringBuilder; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class LocalizationManager { + private final Map<LineId, String> lines = new HashMap<>(); + private final FileHandle handle; + + public LocalizationManager(FileHandle localizationFile) { + this.handle = localizationFile; + + JsonValue json = new JsonReader().parse(handle); + for (JsonValue val : json.iterator()) { + LineId key = LineId.fromJson(val.name); + if (key == null) continue; + String value; + + try { + value = json.getString(val.name); + } catch (Exception e) { + value = val.name; + } + + lines.put(key, value); + } + } + + public String getLine(LineId id) { + return lines.get(id); + } + + public String getFormattedLine(LineId id, CharSequence... params) { + String line = this.getLine(id); + + if (line == null) return null; + + Scanner scanner = new Scanner(line); + StringBuilder result = new StringBuilder(); + int index = 0; + + while (scanner.hasNext()) { + String next = scanner.next(); + + if (next.contains("%s")) { + next = next.replace("%s", params[index]); + + if (index + 1 < params.length) index++; + } + + result.append(next).append(' '); + } + + return result.substring(0, result.length - 1); + } + + public FileHandle getHandle() { + return handle; + } + + public Map<LineId, String> getLines() { + return lines; + } +} |
