Created stat parameter parsing and translation!

Genericified "[stats] from [terrain] tile" building unique
This commit is contained in:
Yair Morgenstern 2020-07-24 17:47:55 +03:00
parent 56052884f1
commit 066dd615b4
30 changed files with 118 additions and 50 deletions

View file

@ -178,7 +178,7 @@
"hurryCostModifier": 25,
"maintenance": 1,
"resourceBonusStats": {"food": 1},
"uniques": ["Can only be built in coastal cities","+1 food from Ocean and Coast tiles"],
"uniques": ["Can only be built in coastal cities", "[+1 Food] from [Ocean] tiles", "[+1 Food] from [Coast] tiles"]
"requiredTech": "Optics"
},
{

View file

@ -971,7 +971,8 @@ Provides a sum of gold each time you spend a Great Person = Proporciona um monta
+2 Gold for each source of Marble and Stone = +2 de Ouro por cada recurso de Mármore e Pedra
Mausoleum of Halicarnassus = Mausoléu de Halicarnasso
+1 food from Ocean and Coast tiles = +1 de comida de regiões costeiras e oceânicas
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Farol
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Os navios que descem no mar, negociam em grandes águas; estes vêem as obras do Senhor, e suas maravilhas nas profundezas.' - A Bíblia, Salmos 107:23-24

View file

@ -1018,7 +1018,8 @@ Provides a sum of gold each time you spend a Great Person = Poskytne zlato při
+2 Gold for each source of Marble and Stone = +2 zlata za každý Mramor a Kámen
Mausoleum of Halicarnassus = Mauzoleum v Halikarnassu
+1 food from Ocean and Coast tiles = +1 jídlo z oceánu a pobřežních polí
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Maják
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Ti, kteří se vydávají na lodích na moře, kdo konají dílo na nesmírných vodách, spatřili Hospodinovy skutky, jeho divy na hlubině.' - Bible, Žalm 107: 23-24

View file

@ -1546,7 +1546,8 @@ Provides a sum of gold each time you spend a Great Person =
# Requires translation!
Mausoleum of Halicarnassus =
+1 food from Ocean and Coast tiles = +1 voedsel van Oceaan en Kust tegels
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Vuurtoren
# Requires translation!

View file

@ -1773,7 +1773,7 @@ Provides a sum of gold each time you spend a Great Person =
Mausoleum of Halicarnassus =
# Requires translation!
+1 food from Ocean and Coast tiles =
[stats] from [terrain] tiles =
# Requires translation!
Lighthouse =

View file

@ -1002,7 +1002,8 @@ Provides a sum of gold each time you spend a Great Person = Donne de l'Or à cha
+2 Gold for each source of Marble and Stone = +2 Or pour chaque ressource de Marbre et de Pierre
Mausoleum of Halicarnassus = Mausolée d'Halicarnasse
+1 food from Ocean and Coast tiles = +1 nourriture des cases océans et côtes
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Phare
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Ceux qui étaient descendus sur la mer dans des navires, et qui travaillaient sur les grandes eaux, Ceux-là virent les oeuvres de l'Eternel et ses merveilles au milieu de l'abîme.…' - La Bible, Psaumes 107:23-24

View file

@ -969,7 +969,8 @@ Provides a sum of gold each time you spend a Great Person = Gibt Dir jedes mal b
+2 Gold for each source of Marble and Stone = +2 Gold für jede Quelle von Marmor und Stein
Mausoleum of Halicarnassus = Mausoleum von Halikarnassos
+1 food from Ocean and Coast tiles = +1 Nahrung von Ozean- und Küstenfeldern
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Leuchtturm
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Die mit Schiffen auf dem Meere fuhren und trieben ihren Handel auf großen Wassern, die des HERRN Werke erfahren haben und seine Wunder im Meer.' - Die Bibel, Psalm 107,23-25

View file

@ -965,7 +965,8 @@ Provides a sum of gold each time you spend a Great Person = Menyediakan sejumlah
+2 Gold for each source of Marble and Stone = +2 Emas untuk setiap sumber Marmer dan Batu
Mausoleum of Halicarnassus = Makam Halikarnassus
+1 food from Ocean and Coast tiles = +1 makanan dari Samudera dan Pesisir
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Mercusuar
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Ada orang-orang yang mengarungi laut dengan kapal-kapal, yang melakukan perdagangan di lautan luas; mereka melihat pekerjaan-pekerjaan Tuhan, dan perbuatan-perbuatan-Nya yang ajaib di tempat yang dalam.' - Alkitab, Mazmur 107:23-24

View file

@ -965,7 +965,8 @@ Provides a sum of gold each time you spend a Great Person = Concede una tantum d
+2 Gold for each source of Marble and Stone = +2 Oro per ogni fonte di Marmo e Pietra
Mausoleum of Halicarnassus = Mausoleo di Alicarnasso
+1 food from Ocean and Coast tiles = +1 Cibo da caselle Oceano e costiere
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Faro
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Ecco quelli che scendon nel mare su navi, che trafficano sulle grandi acque; essi veggono le opere dell'Eterno e le sue meraviglie nell'abisso.' - Salmi 107:23-24

View file

@ -965,7 +965,8 @@ Provides a sum of gold each time you spend a Great Person = 偉人を消費す
+2 Gold for each source of Marble and Stone = 大理石または石材1つにつきゴールド+2
Mausoleum of Halicarnassus = マウソロス霊廟
+1 food from Ocean and Coast tiles = 海岸、海のタイルに食料+1
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = 灯台
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 「彼らは船に乗り海に出て、大海原で事業をなす者となった。彼らは深き海で主の御業を見た。驚くべき主の美業を。」 - 旧約聖書詩編 107:23-24

View file

@ -963,7 +963,8 @@ Provides a sum of gold each time you spend a Great Person = 위인 소모시 일
+2 Gold for each source of Marble and Stone = 대리석, 돌에서 금 +2
Mausoleum of Halicarnassus = 마우솔로스의 영묘
+1 food from Ocean and Coast tiles = 연안, 대양에서 식량 +1
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = 등대
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = '배들을 바다에 띄우며 큰 물에서 일을 하는 자는 여호와께서 행하신 일들과 그의 기이한 일들을 깊은 바다에서 보나니.' - 성경, 시편 107:23-24

View file

@ -1041,7 +1041,7 @@ Provides a sum of gold each time you spend a Great Person =
Mausoleum of Halicarnassus =
# Requires translation!
+1 food from Ocean and Coast tiles =
[stats] from [terrain] tiles =
# Requires translation!
Lighthouse =

View file

@ -1719,7 +1719,7 @@ Provides a sum of gold each time you spend a Great Person =
Mausoleum of Halicarnassus =
# Requires translation!
+1 food from Ocean and Coast tiles =
[stats] from [terrain] tiles =
Lighthouse = Rumah Api
# Requires translation!

View file

@ -1003,7 +1003,7 @@ Provides a sum of gold each time you spend a Great Person =
Mausoleum of Halicarnassus =
# Requires translation!
+1 food from Ocean and Coast tiles =
[stats] from [terrain] tiles =
# Requires translation!
Lighthouse =

View file

@ -1004,7 +1004,7 @@ Provides a sum of gold each time you spend a Great Person =
Mausoleum of Halicarnassus =
# Requires translation!
+1 food from Ocean and Coast tiles =
[stats] from [terrain] tiles =
# Requires translation!
Lighthouse =

View file

@ -998,7 +998,8 @@ Provides a sum of gold each time you spend a Great Person = Otrzymujesz sumę z
+2 Gold for each source of Marble and Stone = +2 do Złota za każde źródło Marmuru i Kamienia
Mausoleum of Halicarnassus = Mauzoleum z Halikarnasu
+1 food from Ocean and Coast tiles = +1 do żywności z pól wybrzeża i oceanicznych
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Latarnia morska
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Ci, którzy na statkach ruszyli na morze, aby uprawiać handel na ogromnych wodach, ci widzieli dzieła Pana i jego cuda wśród głębiny.' Biblia, Księga Psalmów 107,23-24

View file

@ -1053,7 +1053,8 @@ Provides a sum of gold each time you spend a Great Person =
# Requires translation!
Mausoleum of Halicarnassus =
+1 food from Ocean and Coast tiles = +1 de comida de regiões costeiras e oceânicas
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Farol
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Os navios que descem no mar, negociam em grandes águas; estes vêem as obras do Senhor, e suas maravilhas nas profundezas.' - A Bíblia, Salmos 107:23-24

View file

@ -1058,7 +1058,8 @@ Provides a sum of gold each time you spend a Great Person = Oferă o sumă de au
# Requires translation!
Mausoleum of Halicarnassus =
+1 food from Ocean and Coast tiles = +1 hrană din celule ocean și de țărm
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Far
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Cei ce se coborâseră pe mare în corăbii și făceau negoț pe apele cele mari, aceia au văzut lucrările Domnului și minunile Lui în mijlocul adâncului.' - Biblia, Psalmul 107:23-24

View file

@ -965,7 +965,8 @@ Provides a sum of gold each time you spend a Great Person = Дает золот
+2 Gold for each source of Marble and Stone = Каждая обрабатываемая городом клетка с Мрамором или Камнем дает +2 Золота
Mausoleum of Halicarnassus = Галикарнасский мавзолей
+1 food from Ocean and Coast tiles = +1 Еда от клеток океана и берега
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Маяк
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Отправляющиеся на кораблях в море, производящие дела на больших водах, видят дела Господа и чудеса Его в пучине...' - Псалтирь, Псалом 106: 23-24

View file

@ -969,7 +969,8 @@ Provides a sum of gold each time you spend a Great Person = 每次消耗掉一
+2 Gold for each source of Marble and Stone = 所在城市开发的每处大理石或花岗石资源额外产出2金钱
Mausoleum of Halicarnassus = 摩索拉斯陵墓
+1 food from Ocean and Coast tiles = 每个海滨地块和海洋地块+1食物
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = 灯塔
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = “在大海上坐船,在大水里经理事务的;他们看到耶和华的作为,并他在深水中的奇事。”——圣经·诗篇 107:23-24

View file

@ -971,7 +971,8 @@ Provides a sum of gold each time you spend a Great Person = Proporciona una suma
+2 Gold for each source of Marble and Stone = +2 de oro por cada fuente de Mármol y Piedra
Mausoleum of Halicarnassus = Mausoleo de Halicarnaso
+1 food from Ocean and Coast tiles = +1 de comida en casillas costeras o de Océano
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Faro
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Los que surcan el mar en las naves para hacer su negocio en la inmensidad de las aguas también ven la obra de Yavé y sus maravillas en el piélago.' - La Biblia, Salmos 107: 23-24

View file

@ -990,7 +990,8 @@ Provides a sum of gold each time you spend a Great Person = 每次消耗掉一
+2 Gold for each source of Marble and Stone = 所在城市開發的每處大理石或花崗石資源額外產出2金錢
Mausoleum of Halicarnassus = 摩索拉斯陵墓
+1 food from Ocean and Coast tiles = 每個海濱地區和海洋地區+1食物
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = 燈塔
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = “在大海上坐船,在大水裡處理事物的;他們看到耶和華的作為,並他在深水中的奇事。”——聖經·詩篇 107:23-24

View file

@ -1021,7 +1021,8 @@ Provides a sum of gold each time you spend a Great Person =
+2 Gold for each source of Marble and Stone = Her Mermer ve Taş kaynağı için +2 Altın
Mausoleum of Halicarnassus = Halikarnas Mozolesi
+1 food from Ocean and Coast tiles = Okyanus ve Sahil çinilerinden +1 yiyecek
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Deniz feneri
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = 'Gemilerde denize inen, büyük sularda iş yapan onlar; bunlar Rabbin ve harikalarını derinlerde görür. ' - İncil, Mezmurlar 107: 23-24

View file

@ -969,7 +969,8 @@ Provides a sum of gold each time you spend a Great Person = Забезпечує
+2 Gold for each source of Marble and Stone = +2 золота за кожен Мармур та Камінь
Mausoleum of Halicarnassus = Галікарнаський мавзолей
+1 food from Ocean and Coast tiles = +1 їжа з кожної океанської і прибережної клітинки
# Requires translation!
[stats] from [terrain] tiles =
Lighthouse = Маяк
'They that go down to the sea in ships, that do business in great waters; these see the works of the Lord, and his wonders in the deep.' - The Bible, Psalms 107:23-24 = «Ті, хто по морю пливе кораблями, хто чинить зайняття своє на великій воді; вони бачили чини Господні та чуда Його в глибині!» — Біблія, Псалом 107:23-34.

View file

@ -2,7 +2,7 @@ Brazilian_Portuguese = 72
Persian_(Pinglish-UN) = 26
Traditional_Chinese = 63
Italian = 99
Polish = 96
Polish = 95
Russian = 99
Lithuanian = 26
Romanian = 46

View file

@ -10,6 +10,8 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.tile.*
import com.unciv.models.stats.Stats
import com.unciv.models.translations.equalsPlaceholderText
import com.unciv.models.translations.getPlaceholderParameters
import com.unciv.models.translations.tr
import kotlin.math.abs
@ -170,9 +172,14 @@ open class TileInfo {
fun getTileStats(city: CityInfo?, observingCiv: CivilizationInfo): Stats {
var stats = getBaseTerrain().clone()
if ((baseTerrain == Constants.ocean || baseTerrain == Constants.coast) && city != null
&& city.containsBuildingUnique("+1 food from Ocean and Coast tiles"))
stats.food += 1
if(city!=null) for(unique in city.getBuildingUniques()) {
if (unique.equalsPlaceholderText("[] from [] tiles")) {
val placeholderParams = unique.getPlaceholderParameters()
val tileType = placeholderParams[1]
if (baseTerrain == tileType || terrainFeature == tileType)
stats.add(Stats.parse(placeholderParams[0]))
}
}
if (terrainFeature != null) {
val terrainFeatureBase = getTerrainFeature()

View file

@ -102,6 +102,25 @@ open class Stats() {
&& science == otherStats.science
&& faith == otherStats.faith
}
companion object {
private val allStatNames = Stat.values().joinToString("|") { it.name }
private val statRegexPattern = "([+-])(\\d+) ($allStatNames)"
private val statRegex = Regex(statRegexPattern)
private val entireStringRegexPattern = Regex("$statRegexPattern(, $statRegexPattern)*")
fun isStats(string:String): Boolean = entireStringRegexPattern.matches(string)
fun parse(string:String):Stats{
val toReturn = Stats()
val statsWithBonuses = string.split(", ")
for(statWithBonuses in statsWithBonuses){
val match = statRegex.matchEntire(statWithBonuses)!!
val statName = match.groupValues[3]
val statAmount = match.groupValues[2].toFloat() * (if(match.groupValues[1]=="-") -1 else 1)
toReturn.add(Stat.valueOf(statName), statAmount)
}
return toReturn
}
}
}
class StatMap:LinkedHashMap<String,Stats>(){

View file

@ -14,6 +14,7 @@ import com.unciv.models.ruleset.tile.TileImprovement
import com.unciv.models.ruleset.tile.TileResource
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.Promotion
import com.unciv.models.stats.Stats
import com.unciv.ui.worldscreen.unit.UnitActions
import java.lang.reflect.Field
@ -202,9 +203,10 @@ object TranslationFileWriter {
parameter.toIntOrNull() != null -> "amount"
RulesetCache.getBaseRuleset().terrains.containsKey(parameter) -> "terrain"
RulesetCache.getBaseRuleset().units.containsKey(parameter) -> "unit"
Stats.isStats(parameter) -> "stats"
else -> "param"
}
stringToTranslate = string.replace(parameters[0], parameterName)
stringToTranslate = stringToTranslate.replace(parameter, parameterName)
}
}

View file

@ -2,6 +2,7 @@ package com.unciv.models.translations
import com.badlogic.gdx.Gdx
import com.unciv.UncivGame
import com.unciv.models.stats.Stats
import java.util.*
import kotlin.collections.HashMap
@ -269,6 +270,8 @@ fun String.tr(): String {
return curlyBraceRegex.replace(this) { it.groups[1]!!.value.tr() }
}
if (Stats.isStats(this)) return Stats.parse(this).toString()
return UncivGame.Current.translations.getText(this, UncivGame.Current.settings.language, activeMods)
}

View file

@ -4,9 +4,13 @@ package com.unciv.testing
import com.badlogic.gdx.Gdx
import com.unciv.UncivGame
import com.unciv.UncivGameParameters
import com.unciv.models.metadata.GameSettings
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@ -60,4 +64,19 @@ class BasicTests {
}
Assert.assertTrue(allObsoletingUnitsHaveUpgrades)
}
@Test
fun statParserWorks(){
Assert.assertTrue(Stats.isStats("+1 Production"))
Assert.assertTrue(Stats.isStats("+1 Gold, +2 Production"))
Assert.assertFalse(Stats.isStats("+1 Gold from tree"))
val statsThatShouldBe = Stats().add(Stat.Gold,1f).add(Stat.Production, 2f)
Assert.assertTrue(Stats.parse("+1 Gold, +2 Production").equals(statsThatShouldBe))
UncivGame.Current = UncivGame("")
UncivGame.Current.settings = GameSettings().apply { language = "Italian" }
val x = "+1 Gold, +2 Production".tr()
print(x)
}
}