Changed deprecated StringBuilder.appendln with .appendLine

This commit is contained in:
Yair Morgenstern 2021-02-22 21:13:16 +02:00
parent b7c25f30e5
commit 0ef44fc4da
9 changed files with 66 additions and 67 deletions

View File

@ -20,7 +20,7 @@ class CrashReportSenderAndroid(private val activity: Activity) : CrashReportSend
"OS version: %s\n" + "OS version: %s\n" +
"Device model: %s\n" + "Device model: %s\n" +
"Mods: %s\n" + "Mods: %s\n" +
"Game data: %s\n" "Game data: \n%s\n"
} }
override fun sendReport(report: CrashReport) { override fun sendReport(report: CrashReport) {

View File

@ -95,25 +95,25 @@ class Building : NamedStats(), IConstruction {
fun getDescription(forBuildingPickerScreen: Boolean, civInfo: CivilizationInfo?, ruleset: Ruleset): String { fun getDescription(forBuildingPickerScreen: Boolean, civInfo: CivilizationInfo?, ruleset: Ruleset): String {
val stats = getStats(civInfo) val stats = getStats(civInfo)
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
if (uniqueTo != null) stringBuilder.appendln("Unique to [$uniqueTo], replaces [$replaces]".tr()) if (uniqueTo != null) stringBuilder.appendLine("Unique to [$uniqueTo], replaces [$replaces]".tr())
if (!forBuildingPickerScreen) stringBuilder.appendln("{Cost}: $cost".tr()) if (!forBuildingPickerScreen) stringBuilder.appendLine("{Cost}: $cost".tr())
if (isWonder) stringBuilder.appendln("Wonder".tr()) if (isWonder) stringBuilder.appendLine("Wonder".tr())
if (isNationalWonder) stringBuilder.appendln("National Wonder".tr()) if (isNationalWonder) stringBuilder.appendLine("National Wonder".tr())
if (!forBuildingPickerScreen && requiredTech != null) if (!forBuildingPickerScreen && requiredTech != null)
stringBuilder.appendln("Required tech: [$requiredTech]".tr()) stringBuilder.appendLine("Required tech: [$requiredTech]".tr())
if (!forBuildingPickerScreen && requiredBuilding != null) if (!forBuildingPickerScreen && requiredBuilding != null)
stringBuilder.appendln("Requires [$requiredBuilding] to be built in the city".tr()) stringBuilder.appendLine("Requires [$requiredBuilding] to be built in the city".tr())
if (!forBuildingPickerScreen && requiredBuildingInAllCities != null) if (!forBuildingPickerScreen && requiredBuildingInAllCities != null)
stringBuilder.appendln("Requires [$requiredBuildingInAllCities] to be built in all cities".tr()) stringBuilder.appendLine("Requires [$requiredBuildingInAllCities] to be built in all cities".tr())
for ((resource, amount) in getResourceRequirements()) { for ((resource, amount) in getResourceRequirements()) {
if (amount == 1) stringBuilder.appendln("Consumes 1 [$resource]".tr()) // For now, to keep the existing translations if (amount == 1) stringBuilder.appendLine("Consumes 1 [$resource]".tr()) // For now, to keep the existing translations
else stringBuilder.appendln("Consumes [$amount] [$resource]".tr()) else stringBuilder.appendLine("Consumes [$amount] [$resource]".tr())
} }
if (providesFreeBuilding != null) if (providesFreeBuilding != null)
stringBuilder.appendln("Provides a free [$providesFreeBuilding] in the city".tr()) stringBuilder.appendLine("Provides a free [$providesFreeBuilding] in the city".tr())
if (uniques.isNotEmpty()) { if (uniques.isNotEmpty()) {
if (replacementTextForUniques != "") stringBuilder.appendln(replacementTextForUniques) if (replacementTextForUniques != "") stringBuilder.appendLine(replacementTextForUniques)
else stringBuilder.appendln(uniques.asSequence().map { it.tr() }.joinToString("\n")) else stringBuilder.appendLine(uniques.asSequence().map { it.tr() }.joinToString("\n"))
} }
if (!stats.isEmpty()) if (!stats.isEmpty())
stringBuilder.appendln(stats) stringBuilder.appendln(stats)
@ -127,28 +127,28 @@ class Building : NamedStats(), IConstruction {
if (this.greatPersonPoints != null) { if (this.greatPersonPoints != null) {
val gpp = this.greatPersonPoints!! val gpp = this.greatPersonPoints!!
if (gpp.production != 0f) stringBuilder.appendln("+" + gpp.production.toInt() + " " + "[Great Engineer] points".tr()) if (gpp.production != 0f) stringBuilder.appendLine("+" + gpp.production.toInt() + " " + "[Great Engineer] points".tr())
if (gpp.gold != 0f) stringBuilder.appendln("+" + gpp.gold.toInt() + " " + "[Great Merchant] points".tr()) if (gpp.gold != 0f) stringBuilder.appendLine("+" + gpp.gold.toInt() + " " + "[Great Merchant] points".tr())
if (gpp.science != 0f) stringBuilder.appendln("+" + gpp.science.toInt() + " " + "[Great Scientist] points".tr()) if (gpp.science != 0f) stringBuilder.appendLine("+" + gpp.science.toInt() + " " + "[Great Scientist] points".tr())
if (gpp.culture != 0f) stringBuilder.appendln("+" + gpp.culture.toInt() + " " + "[Great Artist] points".tr()) if (gpp.culture != 0f) stringBuilder.appendLine("+" + gpp.culture.toInt() + " " + "[Great Artist] points".tr())
} }
for ((specialistName, amount) in newSpecialists()) for ((specialistName, amount) in newSpecialists())
stringBuilder.appendln("+$amount " + "[$specialistName] slots".tr()) stringBuilder.appendLine("+$amount " + "[$specialistName] slots".tr())
if (resourceBonusStats != null) { if (resourceBonusStats != null) {
val resources = ruleset.tileResources.values.filter { name == it.building }.joinToString { it.name.tr() } val resources = ruleset.tileResources.values.filter { name == it.building }.joinToString { it.name.tr() }
stringBuilder.appendln("$resources {provide} $resourceBonusStats".tr()) stringBuilder.appendLine("$resources {provide} $resourceBonusStats".tr())
} }
if (requiredNearbyImprovedResources != null) if (requiredNearbyImprovedResources != null)
stringBuilder.appendln(("Requires worked [" + requiredNearbyImprovedResources!!.joinToString("/") { it.tr() } + "] near city").tr()) stringBuilder.appendLine(("Requires worked [" + requiredNearbyImprovedResources!!.joinToString("/") { it.tr() } + "] near city").tr())
if (cityStrength != 0) stringBuilder.appendln("{City strength} +".tr() + cityStrength) if (cityStrength != 0) stringBuilder.appendLine("{City strength} +".tr() + cityStrength)
if (cityHealth != 0) stringBuilder.appendln("{City health} +".tr() + cityHealth) if (cityHealth != 0) stringBuilder.appendLine("{City health} +".tr() + cityHealth)
if (xpForNewUnits != 0) stringBuilder.appendln("+$xpForNewUnits {XP for new units}".tr()) if (xpForNewUnits != 0) stringBuilder.appendLine("+$xpForNewUnits {XP for new units}".tr())
if (maintenance != 0) if (maintenance != 0)
stringBuilder.appendln("{Maintenance cost}: $maintenance {Gold}".tr()) stringBuilder.appendLine("{Maintenance cost}: $maintenance {Gold}".tr())
return stringBuilder.toString().trim() return stringBuilder.toString().trim()
} }

View File

@ -47,30 +47,30 @@ class Terrain : NamedStats() {
fun getDescription(ruleset: Ruleset): String { fun getDescription(ruleset: Ruleset): String {
val sb = StringBuilder() val sb = StringBuilder()
sb.appendln(this.clone().toString()) sb.appendLine(this.clone().toString())
if (occursOn.isNotEmpty()) if (occursOn.isNotEmpty())
sb.appendln("Occurs on [${occursOn.joinToString(", ") { it.tr() }}]".tr()) sb.appendLine("Occurs on [${occursOn.joinToString(", ") { it.tr() }}]".tr())
if (turnsInto != null) if (turnsInto != null)
sb.appendln("Placed on [$turnsInto]".tr()) sb.appendLine("Placed on [$turnsInto]".tr())
val resourcesFound = ruleset.tileResources.values.filter { it.terrainsCanBeFoundOn.contains(name) } val resourcesFound = ruleset.tileResources.values.filter { it.terrainsCanBeFoundOn.contains(name) }
if (resourcesFound.isNotEmpty()) if (resourcesFound.isNotEmpty())
sb.appendln("May contain [${resourcesFound.joinToString(", ") { it.name.tr() }}]".tr()) sb.appendLine("May contain [${resourcesFound.joinToString(", ") { it.name.tr() }}]".tr())
if(uniques.isNotEmpty()) if(uniques.isNotEmpty())
sb.appendln(uniques.joinToString { it.tr() }) sb.appendLine(uniques.joinToString { it.tr() })
if (impassable) if (impassable)
sb.appendln(Constants.impassable.tr()) sb.appendLine(Constants.impassable.tr())
else else
sb.appendln("{Movement cost}: $movementCost".tr()) sb.appendLine("{Movement cost}: $movementCost".tr())
if (defenceBonus != 0f) if (defenceBonus != 0f)
sb.appendln("{Defence bonus}: ".tr() + (defenceBonus * 100).toInt() + "%") sb.appendLine("{Defence bonus}: ".tr() + (defenceBonus * 100).toInt() + "%")
if (rough) if (rough)
sb.appendln("Rough Terrain".tr()) sb.appendLine("Rough Terrain".tr())
return sb.toString() return sb.toString()
} }

View File

@ -39,14 +39,14 @@ class TileImprovement : NamedStats() {
fun getDescription(ruleset: Ruleset, forPickerScreen: Boolean = true): String { fun getDescription(ruleset: Ruleset, forPickerScreen: Boolean = true): String {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
val statsDesc = this.clone().toString() val statsDesc = this.clone().toString()
if (statsDesc.isNotEmpty()) stringBuilder.appendln(statsDesc) if (statsDesc.isNotEmpty()) stringBuilder.appendLine(statsDesc)
if (uniqueTo!=null && !forPickerScreen) stringBuilder.appendln("Unique to [$uniqueTo]".tr()) if (uniqueTo!=null && !forPickerScreen) stringBuilder.appendLine("Unique to [$uniqueTo]".tr())
if (!terrainsCanBeBuiltOn.isEmpty()) { if (!terrainsCanBeBuiltOn.isEmpty()) {
val terrainsCanBeBuiltOnString: ArrayList<String> = arrayListOf() val terrainsCanBeBuiltOnString: ArrayList<String> = arrayListOf()
for (i in terrainsCanBeBuiltOn) { for (i in terrainsCanBeBuiltOn) {
terrainsCanBeBuiltOnString.add(i.tr()) terrainsCanBeBuiltOnString.add(i.tr())
} }
stringBuilder.appendln("Can be built on ".tr() + terrainsCanBeBuiltOnString.joinToString(", "))//language can be changed when setting changes. stringBuilder.appendLine("Can be built on ".tr() + terrainsCanBeBuiltOnString.joinToString(", "))//language can be changed when setting changes.
} }
val statsToResourceNames = HashMap<String, ArrayList<String>>() val statsToResourceNames = HashMap<String, ArrayList<String>>()
for (tr: TileResource in ruleset.tileResources.values.filter { it.improvement == name }) { for (tr: TileResource in ruleset.tileResources.values.filter { it.improvement == name }) {
@ -56,13 +56,13 @@ class TileImprovement : NamedStats() {
statsToResourceNames[statsString]!!.add(tr.name.tr()) statsToResourceNames[statsString]!!.add(tr.name.tr())
} }
statsToResourceNames.forEach { statsToResourceNames.forEach {
stringBuilder.appendln(it.key + " for ".tr() + it.value.joinToString(", ")) stringBuilder.appendLine(it.key + " for ".tr() + it.value.joinToString(", "))
} }
if (techRequired != null) stringBuilder.appendln("Required tech: [$techRequired]".tr()) if (techRequired != null) stringBuilder.appendLine("Required tech: [$techRequired]".tr())
for(unique in uniques) for(unique in uniques)
stringBuilder.appendln (unique.tr()) stringBuilder.appendLine(unique.tr())
return stringBuilder.toString() return stringBuilder.toString()
} }

View File

@ -23,26 +23,26 @@ class TileResource : NamedStats() {
fun getDescription(ruleset: Ruleset): String { fun getDescription(ruleset: Ruleset): String {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
stringBuilder.appendln(resourceType.name.tr()) stringBuilder.appendLine(resourceType.name.tr())
stringBuilder.appendln(this.clone().toString()) stringBuilder.appendLine(this.clone().toString())
val terrainsCanBeBuiltOnString: ArrayList<String> = arrayListOf() val terrainsCanBeBuiltOnString: ArrayList<String> = arrayListOf()
terrainsCanBeBuiltOnString.addAll(terrainsCanBeFoundOn.map { it.tr() }) terrainsCanBeBuiltOnString.addAll(terrainsCanBeFoundOn.map { it.tr() })
stringBuilder.appendln("Can be found on ".tr() + terrainsCanBeBuiltOnString.joinToString(", ")) stringBuilder.appendLine("Can be found on ".tr() + terrainsCanBeBuiltOnString.joinToString(", "))
stringBuilder.appendln() stringBuilder.appendln()
stringBuilder.appendln("Improved by [$improvement]".tr()) stringBuilder.appendLine("Improved by [$improvement]".tr())
stringBuilder.appendln("{Bonus stats for improvement}: ".tr() + "$improvementStats".tr()) stringBuilder.appendLine("{Bonus stats for improvement}: ".tr() + "$improvementStats".tr())
val buildingsThatConsumeThis = ruleset.buildings.values.filter { it.getResourceRequirements().containsKey(name) } val buildingsThatConsumeThis = ruleset.buildings.values.filter { it.getResourceRequirements().containsKey(name) }
if (buildingsThatConsumeThis.isNotEmpty()) if (buildingsThatConsumeThis.isNotEmpty())
stringBuilder.appendln("{Buildings that consume this resource}: ".tr() stringBuilder.appendLine("{Buildings that consume this resource}: ".tr()
+ buildingsThatConsumeThis.joinToString { it.name.tr() }) + buildingsThatConsumeThis.joinToString { it.name.tr() })
val unitsThatConsumeThis = ruleset.units.values.filter { it.getResourceRequirements().containsKey(name) } val unitsThatConsumeThis = ruleset.units.values.filter { it.getResourceRequirements().containsKey(name) }
if (unitsThatConsumeThis.isNotEmpty()) if (unitsThatConsumeThis.isNotEmpty())
stringBuilder.appendln("{Units that consume this resource}: ".tr() stringBuilder.appendLine("{Units that consume this resource}: ".tr()
+ unitsThatConsumeThis.joinToString { it.name.tr() }) + unitsThatConsumeThis.joinToString { it.name.tr() })
if (unique != null) stringBuilder.appendln(unique!!.tr()) if (unique != null) stringBuilder.appendLine(unique!!.tr())
return stringBuilder.toString() return stringBuilder.toString()
} }
} }

View File

@ -56,30 +56,30 @@ class BaseUnit : INamed, IConstruction {
fun getDescription(forPickerScreen: Boolean): String { fun getDescription(forPickerScreen: Boolean): String {
val sb = StringBuilder() val sb = StringBuilder()
for ((resource, amount) in getResourceRequirements()) { for ((resource, amount) in getResourceRequirements()) {
if (amount == 1) sb.appendln("Consumes 1 [$resource]".tr()) if (amount == 1) sb.appendLine("Consumes 1 [$resource]".tr())
else sb.appendln("Consumes [$amount]] [$resource]".tr()) else sb.appendLine("Consumes [$amount]] [$resource]".tr())
} }
if (!forPickerScreen) { if (!forPickerScreen) {
if (uniqueTo != null) sb.appendln("Unique to [$uniqueTo], replaces [$replaces]".tr()) if (uniqueTo != null) sb.appendLine("Unique to [$uniqueTo], replaces [$replaces]".tr())
else sb.appendln("{Cost}: $cost".tr()) else sb.appendLine("{Cost}: $cost".tr())
if (requiredTech != null) sb.appendln("Required tech: [$requiredTech]".tr()) if (requiredTech != null) sb.appendLine("Required tech: [$requiredTech]".tr())
if (upgradesTo != null) sb.appendln("Upgrades to [$upgradesTo]".tr()) if (upgradesTo != null) sb.appendLine("Upgrades to [$upgradesTo]".tr())
if (obsoleteTech != null) sb.appendln("Obsolete with [$obsoleteTech]".tr()) if (obsoleteTech != null) sb.appendLine("Obsolete with [$obsoleteTech]".tr())
} }
if (strength != 0) { if (strength != 0) {
sb.append("$strength${Fonts.strength}, ") sb.append("$strength${Fonts.strength}, ")
if (rangedStrength != 0) sb.append("$rangedStrength${Fonts.rangedStrength}, ") if (rangedStrength != 0) sb.append("$rangedStrength${Fonts.rangedStrength}, ")
if (rangedStrength != 0) sb.append("$range${Fonts.range}, ") if (rangedStrength != 0) sb.append("$range${Fonts.range}, ")
} }
sb.appendln("$movement${Fonts.movement}") sb.appendLine("$movement${Fonts.movement}")
if (replacementTextForUniques != "") sb.appendln(replacementTextForUniques) if (replacementTextForUniques != "") sb.appendLine(replacementTextForUniques)
else for (unique in uniques) else for (unique in uniques)
sb.appendln(Translations.translateBonusOrPenalty(unique)) sb.appendLine(Translations.translateBonusOrPenalty(unique))
if (promotions.isNotEmpty()) { if (promotions.isNotEmpty()) {
sb.append((if (promotions.size == 1) "Free promotion:" else "Free promotions:").tr()) sb.append((if (promotions.size == 1) "Free promotion:" else "Free promotions:").tr())
sb.appendln(promotions.joinToString(", ", " ") { it.tr() }) sb.appendLine(promotions.joinToString(", ", " ") { it.tr() })
} }
return sb.toString().trim() return sb.toString().trim()

View File

@ -20,7 +20,7 @@ class Promotion : INamed{
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
for (unique in uniques + effect) { for (unique in uniques + effect) {
stringBuilder.appendln(Translations.translateBonusOrPenalty(unique)) stringBuilder.appendLine(Translations.translateBonusOrPenalty(unique))
} }
if(prerequisites.isNotEmpty()) { if(prerequisites.isNotEmpty()) {
@ -28,19 +28,19 @@ class Promotion : INamed{
for (i in prerequisites.filter { promotionsForUnitType.any { promotion -> promotion.name == it } }) { for (i in prerequisites.filter { promotionsForUnitType.any { promotion -> promotion.name == it } }) {
prerequisitesString.add(i.tr()) prerequisitesString.add(i.tr())
} }
stringBuilder.appendln("{Requires}: ".tr() + prerequisitesString.joinToString(" OR ".tr())) stringBuilder.appendLine("{Requires}: ".tr() + prerequisitesString.joinToString(" OR ".tr()))
} }
if(forCivilopedia){ if(forCivilopedia){
if (unitTypes.isNotEmpty()) { if (unitTypes.isNotEmpty()) {
val unitTypesString = unitTypes.joinToString(", ") { it.tr() } val unitTypesString = unitTypes.joinToString(", ") { it.tr() }
stringBuilder.appendln("Available for [$unitTypesString]".tr()) stringBuilder.appendLine("Available for [$unitTypesString]".tr())
} }
if (ruleSet!=null) { if (ruleSet!=null) {
val freeforUnits = ruleSet.units.filter { it.value.promotions.contains(name) } val freeforUnits = ruleSet.units.filter { it.value.promotions.contains(name) }
if (freeforUnits.isNotEmpty()) { if (freeforUnits.isNotEmpty()) {
val freeforString = freeforUnits.map { it.value.name }.joinToString(", ") { it.tr() } val freeforString = freeforUnits.map { it.value.name }.joinToString(", ") { it.tr() }
stringBuilder.appendln("Free for [$freeforString]".tr()) stringBuilder.appendLine("Free for [$freeforString]".tr())
} }
} }
} }

View File

@ -89,7 +89,7 @@ object TranslationFileWriter {
// this stops lots of line breaks between removed translations in G&K // this stops lots of line breaks between removed translations in G&K
stringBuilder.appendln() stringBuilder.appendln()
} else // copy as-is } else // copy as-is
stringBuilder.appendln(line) stringBuilder.appendLine(line)
continue continue
} }
@ -110,11 +110,11 @@ object TranslationFileWriter {
if (translationEntry != null && translationEntry.containsKey(language)) { if (translationEntry != null && translationEntry.containsKey(language)) {
translationValue = translationEntry[language]!! translationValue = translationEntry[language]!!
translationsOfThisLanguage++ translationsOfThisLanguage++
} else stringBuilder.appendln(" # Requires translation!") } else stringBuilder.appendLine(" # Requires translation!")
val lineToWrite = translationKey.replace("\n", "\\n") + val lineToWrite = translationKey.replace("\n", "\\n") +
" = " + translationValue.replace("\n", "\\n") " = " + translationValue.replace("\n", "\\n")
stringBuilder.appendln(lineToWrite) stringBuilder.appendLine(lineToWrite)
} }
countOfTranslatedLines[language] = translationsOfThisLanguage countOfTranslatedLines[language] = translationsOfThisLanguage
@ -135,7 +135,7 @@ object TranslationFileWriter {
private fun writeLanguagePercentages(percentages: HashMap<String, Int>) { private fun writeLanguagePercentages(percentages: HashMap<String, Int>) {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
for (entry in percentages) { for (entry in percentages) {
stringBuilder.appendln(entry.key + " = " + entry.value) stringBuilder.appendLine(entry.key + " = " + entry.value)
} }
Gdx.files.local(TranslationFileReader.percentagesFileLocation).writeString(stringBuilder.toString(), false) Gdx.files.local(TranslationFileReader.percentagesFileLocation).writeString(stringBuilder.toString(), false)
} }

View File

@ -9,7 +9,6 @@ import com.unciv.logic.city.CityInfo
import com.unciv.logic.civilization.GreatPersonManager import com.unciv.logic.civilization.GreatPersonManager
import com.unciv.models.ruleset.Building import com.unciv.models.ruleset.Building
import com.unciv.models.stats.Stat import com.unciv.models.stats.Stat
import com.unciv.models.stats.StatMap
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import java.text.DecimalFormat import java.text.DecimalFormat