mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
Lang: get-from-config tags
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
"TOOLTIP_item@basegame:37": "“I am sworn to keep your burdens.”", /* skyrim/lydia reference */
|
"TOOLTIP_item@basegame:37": "“I am sworn to keep your burdens.”", /* skyrim/lydia reference */
|
||||||
"TOOLTIP_item@basegame:38": "“I am sworn to keep your burdens.”", /* skyrim/lydia reference */
|
"TOOLTIP_item@basegame:38": "“I am sworn to keep your burdens.”", /* skyrim/lydia reference */
|
||||||
"TOOLTIP_item@basegame:39": "“I am sworn to keep your burdens.”", /* skyrim/lydia reference */
|
"TOOLTIP_item@basegame:39": "“I am sworn to keep your burdens.”", /* skyrim/lydia reference */
|
||||||
"TOOLTIP_item@basegame:9": "An electricians’ best friend",
|
"TOOLTIP_item@basegame:9": "Push {MOUSE:config_mousesecondary} to change the colour",
|
||||||
"TOOLTIP_item@basegame:10": "“Who needs a Book and Quill when you’ve got this?”", /* a jab on the Minecraft item Book and Quill */
|
"TOOLTIP_item@basegame:10": "“Who needs a Book and Quill when you’ve got this?”", /* a jab on the Minecraft item Book and Quill */
|
||||||
"TOOLTIP_item@basegame:11": "Tells what day it is",
|
"TOOLTIP_item@basegame:11": "Tells what day it is",
|
||||||
"TOOLTIP_item@basegame:12": "Breaks down walls",
|
"TOOLTIP_item@basegame:12": "Breaks down walls",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"TOOLTIP_item@basegame:37": "“짐을 맡아두기로 한 몸이니까요.”", /* skyrim/lydia reference */
|
"TOOLTIP_item@basegame:37": "“짐을 맡아두기로 한 몸이니까요.”", /* skyrim/lydia reference */
|
||||||
"TOOLTIP_item@basegame:38": "“짐을 맡아두기로 한 몸이니까요.”", /* skyrim/lydia reference */
|
"TOOLTIP_item@basegame:38": "“짐을 맡아두기로 한 몸이니까요.”", /* skyrim/lydia reference */
|
||||||
"TOOLTIP_item@basegame:39": "“짐을 맡아두기로 한 몸이니까요.”", /* skyrim/lydia reference */
|
"TOOLTIP_item@basegame:39": "“짐을 맡아두기로 한 몸이니까요.”", /* skyrim/lydia reference */
|
||||||
"TOOLTIP_item@basegame:9": "전기공의 친한 친구",
|
"TOOLTIP_item@basegame:9": "{MOUSE:config_mousesecondary} 버튼을 눌러 색깔 변경",
|
||||||
"TOOLTIP_item@basegame:10": "“이게 있는데 책과 깃펜이 왜 필요하죠?”", /* a jab on the Minecraft item Book and Quill */
|
"TOOLTIP_item@basegame:10": "“이게 있는데 책과 깃펜이 왜 필요하죠?”", /* a jab on the Minecraft item Book and Quill */
|
||||||
"TOOLTIP_item@basegame:11": "오늘이 무슨 날인지 알려줍니다",
|
"TOOLTIP_item@basegame:11": "오늘이 무슨 날인지 알려줍니다",
|
||||||
"TOOLTIP_item@basegame:12": "벽을 부숩니다",
|
"TOOLTIP_item@basegame:12": "벽을 부숩니다",
|
||||||
|
|||||||
@@ -1726,7 +1726,7 @@ public class App implements ApplicationListener {
|
|||||||
return DefaultConfig.INSTANCE.getHashMap();
|
return DefaultConfig.INSTANCE.getHashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object getConfigMaster(String key1) {
|
public static Object getConfigMaster(String key1) {
|
||||||
String key = key1.toLowerCase();
|
String key = key1.toLowerCase();
|
||||||
|
|
||||||
Object config;
|
Object config;
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ package net.torvald.terrarum.langpack
|
|||||||
|
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
|
import net.torvald.terrarum.tail
|
||||||
import net.torvald.terrarum.utils.JsonFetcher
|
import net.torvald.terrarum.utils.JsonFetcher
|
||||||
|
import net.torvald.unicode.getKeycapPC
|
||||||
|
import net.torvald.unicode.getMouseButton
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
class LangObject(val key: String, val fromLang: Boolean) {
|
class LangObject(val key: String, val fromLang: Boolean) {
|
||||||
fun get() = if (fromLang) Lang[key] else key
|
fun get() = if (fromLang) Lang[key] else key
|
||||||
@@ -137,21 +141,33 @@ object Lang {
|
|||||||
operator fun get(key: String, capitalise: Boolean = false): String {
|
operator fun get(key: String, capitalise: Boolean = false): String {
|
||||||
fun getstr(s: String) = getByLocale(s, App.GAME_LOCALE, capitalise) ?: getByLocale(s, FALLBACK_LANG_CODE, capitalise) ?: "$$s"
|
fun getstr(s: String) = getByLocale(s, App.GAME_LOCALE, capitalise) ?: getByLocale(s, FALLBACK_LANG_CODE, capitalise) ?: "$$s"
|
||||||
|
|
||||||
|
decodeCache[App.GAME_LOCALE]?.get("$key+$capitalise").let {
|
||||||
|
if (it != null) {
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val args = key.split(bindOp).filter { it.isNotBlank() }.map { it.trim() }
|
||||||
|
if (args.isEmpty()) return ""
|
||||||
|
|
||||||
val args = key.split(bindOp).filter { it.isNotBlank() }.map { it.trim() }
|
val sb = StringBuilder()
|
||||||
if (args.isEmpty()) return ""
|
val formatter = Formatter(sb)
|
||||||
|
|
||||||
val sb = StringBuilder()
|
sb.append(getstr(args[0]))
|
||||||
val formatter = Formatter(sb)
|
args.subList(1, args.size).forEach {
|
||||||
|
val oldstr = sb.toString()
|
||||||
|
sb.clear()
|
||||||
|
formatter.format(getstr(it), oldstr)
|
||||||
|
}
|
||||||
|
|
||||||
sb.append(getstr(args[0]))
|
if (decodeCache[App.GAME_LOCALE] == null) {
|
||||||
args.subList(1, args.size).forEach {
|
decodeCache[App.GAME_LOCALE] = HashMap()
|
||||||
val oldstr = sb.toString()
|
}
|
||||||
sb.clear()
|
decodeCache[App.GAME_LOCALE]!!["$key+$capitalise"] = sb.toString()
|
||||||
formatter.format(getstr(it), oldstr)
|
|
||||||
|
return sb.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAndUseTemplate(key: String, capitalise: Boolean = false, vararg arguments: Any?): String {
|
fun getAndUseTemplate(key: String, capitalise: Boolean = false, vararg arguments: Any?): String {
|
||||||
@@ -174,6 +190,7 @@ object Lang {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val capCache = HashMap<String/*Locale*/, HashMap<String/*Key*/, String/*Text*/>>()
|
private val capCache = HashMap<String/*Locale*/, HashMap<String/*Key*/, String/*Text*/>>()
|
||||||
|
private val decodeCache = HashMap<String/*Locale*/, HashMap<String/*Key*/, String/*Text*/>>()
|
||||||
|
|
||||||
private fun CAP(key: String, locale: String): String? {
|
private fun CAP(key: String, locale: String): String? {
|
||||||
val ret = langpack["${key}_$locale"] ?: return null
|
val ret = langpack["${key}_$locale"] ?: return null
|
||||||
@@ -191,20 +208,49 @@ object Lang {
|
|||||||
private fun NOCAP(key: String, locale: String): String? {
|
private fun NOCAP(key: String, locale: String): String? {
|
||||||
return langpack["${key}_$locale"] ?: return null
|
return langpack["${key}_$locale"] ?: return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val tagRegex = Regex("""\{[A-Z]+:[0-9A-Za-z_\- ]+\}""")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does NOT parse the operators
|
* Does NOT parse the bind operators, but DO parse the precomposed tags
|
||||||
*/
|
*/
|
||||||
fun getByLocale(key: String, locale: String, capitalise: Boolean = false): String? {
|
fun getByLocale(key: String, locale: String, capitalise: Boolean = false): String? {
|
||||||
val s = if (capitalise) CAP(key, locale) else NOCAP(key, locale)
|
val s = if (capitalise) CAP(key, locale) else NOCAP(key, locale)
|
||||||
|
|
||||||
if (s == null) return null
|
if (s == null) return null
|
||||||
|
|
||||||
return if (locale.startsWith("bg"))
|
val fetchedS = if (locale.startsWith("bg"))
|
||||||
"${App.fontGame.charsetOverrideBulgarian}$s${App.fontGame.charsetOverrideDefault}"
|
"${App.fontGame.charsetOverrideBulgarian}$s${App.fontGame.charsetOverrideDefault}"
|
||||||
else if (locale.startsWith("sr"))
|
else if (locale.startsWith("sr"))
|
||||||
"${App.fontGame.charsetOverrideSerbian}$s${App.fontGame.charsetOverrideDefault}"
|
"${App.fontGame.charsetOverrideSerbian}$s${App.fontGame.charsetOverrideDefault}"
|
||||||
else
|
else
|
||||||
s
|
s
|
||||||
|
|
||||||
|
// apply {DOMAIN:argument} form of template
|
||||||
|
var ret = "$fetchedS" // make copy of the str
|
||||||
|
tagRegex.findAll(fetchedS).forEach {
|
||||||
|
val matched0 = it.groupValues[0]
|
||||||
|
val matched = matched0.substring(1 until matched0.lastIndex) // strip off the brackets
|
||||||
|
val mode = matched.substringBefore(':')
|
||||||
|
val key = matched.substringAfter(':')
|
||||||
|
|
||||||
|
val resolved = when (mode) {
|
||||||
|
"MOUSE" -> { // cognates to gdx.Input.Button
|
||||||
|
getMouseButton(App.getConfigInt(key)).toString()
|
||||||
|
}
|
||||||
|
"KEYCAP" -> { // cognates to gdx.Input.Keys
|
||||||
|
getKeycapPC(App.getConfigInt(key)).toString()
|
||||||
|
}
|
||||||
|
"CONFIG" -> {
|
||||||
|
App.getConfigMaster(key).toString()
|
||||||
|
}
|
||||||
|
else -> matched0
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ret.replace(matched0, resolved)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.getEndTag() = this.split("_").last()
|
private fun String.getEndTag() = this.split("_").last()
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class UIItemInventoryElemSimple(
|
|||||||
val itemIDstr = "\n$grey(${item?.originalID}${if (item?.isCurrentlyDynamic == true) "/${item?.dynamicID}" else ""})"
|
val itemIDstr = "\n$grey(${item?.originalID}${if (item?.isCurrentlyDynamic == true) "/${item?.dynamicID}" else ""})"
|
||||||
val nameStr0 = if (item?.nameSecondary?.isNotBlank() == true) "${item?.name}\n$grey${item?.nameSecondary}" else "${item?.name}"
|
val nameStr0 = if (item?.nameSecondary?.isNotBlank() == true) "${item?.name}\n$grey${item?.nameSecondary}" else "${item?.name}"
|
||||||
val nameStr = if (Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT)) nameStr0 + itemIDstr else nameStr0
|
val nameStr = if (Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT)) nameStr0 + itemIDstr else nameStr0
|
||||||
val descStr = Lang.getOrNull("TOOLTIP_${item?.originalID}")?.replace("\n","\n$grey")
|
val descStr = Lang.getAndUseTemplate("TOOLTIP_${item?.originalID}")?.replace("\n","\n$grey")
|
||||||
|
|
||||||
val finalStr = if (descStr != null) "$nameStr\n$grey$descStr" else nameStr
|
val finalStr = if (descStr != null) "$nameStr\n$grey$descStr" else nameStr
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user