$l10n_ anpassungen + build automatisierung

This commit is contained in:
2026-07-04 00:44:06 +02:00
parent 40f7189755
commit 252c956cc1
9 changed files with 198 additions and 22 deletions
+120
View File
@@ -9,6 +9,124 @@ $projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$projectZip = Join-Path $projectRoot "$modName.zip"
$tempZip = Join-Path ([System.IO.Path]::GetTempPath()) "$modName-build.zip"
function Format-ProductionAmount {
param(
[double]$Amount,
[string]$CultureName
)
$culture = [System.Globalization.CultureInfo]::GetCultureInfo($CultureName)
$roundedAmount = [Math]::Round($Amount)
if ([Math]::Abs($Amount - $roundedAmount) -lt 0.0001) {
return ([int64]$roundedAmount).ToString("N0", $culture)
}
return $Amount.ToString("N1", $culture)
}
function Set-L10nText {
param(
[xml]$ModDesc,
[string]$Name,
[string]$EnglishText,
[string]$GermanText
)
$textNode = $ModDesc.SelectSingleNode("/modDesc/l10n/text[@name='$Name']")
if ($null -eq $textNode) {
throw "l10n Eintrag fehlt: $Name"
}
$englishNode = $textNode.SelectSingleNode("en")
$germanNode = $textNode.SelectSingleNode("de")
if ($null -eq $englishNode -or $null -eq $germanNode) {
throw "l10n Eintrag ist unvollstaendig: $Name"
}
$englishNode.InnerText = $EnglishText
$germanNode.InnerText = $GermanText
}
function Update-ProductionDescriptions {
param(
[string]$ProjectRoot
)
$modDescPath = Join-Path $ProjectRoot "modDesc.xml"
$products = @{
"PAYDIRT" = @{ En = "paydirt"; De = "Paydirt" }
"STONE" = @{ En = "stone"; De = "Stein" }
"DIRT" = @{ En = "dirt"; De = "Erde" }
"MININGCOAL" = @{ En = "mining coal"; De = "Bergbau-Kohle" }
"IRONORE" = @{ En = "iron ore"; De = "Eisenerz" }
"SILVERORE" = @{ En = "silver ore"; De = "Silbererz" }
}
$productionItems = @(
@{ XmlPath = "placeables\mine\mine.xml"; L10nName = "storeItem_paydirtMine_function" },
@{ XmlPath = "placeables\stoneQuarry\stoneQuarry.xml"; L10nName = "storeItem_stoneQuarry_function" },
@{ XmlPath = "placeables\dirt\dirt.xml"; L10nName = "storeItem_dirtPit_function" },
@{ XmlPath = "placeables\coalmine\coalmine.xml"; L10nName = "storeItem_coalMine_function" },
@{ XmlPath = "placeables\ironore\iron.xml"; L10nName = "storeItem_ironMine_function" },
@{ XmlPath = "placeables\silverore\silver.xml"; L10nName = "storeItem_silverMine_function" }
)
$modDesc = New-Object System.Xml.XmlDocument
$modDesc.PreserveWhitespace = $true
$modDesc.Load($modDescPath)
foreach ($item in $productionItems) {
$placeablePath = Join-Path $ProjectRoot $item.XmlPath
$placeable = New-Object System.Xml.XmlDocument
$placeable.PreserveWhitespace = $true
$placeable.Load($placeablePath)
$productionNode = $placeable.SelectSingleNode("/placeable/produktion")
if ($null -eq $productionNode) {
throw "produktion Eintrag fehlt: $($item.XmlPath)"
}
$fillType = $productionNode.GetAttribute("fillType")
$amountText = $productionNode.GetAttribute("amountPerHour")
if ([string]::IsNullOrWhiteSpace($fillType) -or [string]::IsNullOrWhiteSpace($amountText)) {
throw "produktion Eintrag ist unvollstaendig: $($item.XmlPath)"
}
$amountPerHour = [double]::Parse($amountText, [System.Globalization.CultureInfo]::InvariantCulture)
if ($products.ContainsKey($fillType)) {
$product = $products[$fillType]
} else {
$product = @{ En = $fillType.ToLowerInvariant(); De = $fillType }
}
$amountEn = Format-ProductionAmount -Amount $amountPerHour -CultureName "en-US"
$amountDe = Format-ProductionAmount -Amount $amountPerHour -CultureName "de-DE"
Set-L10nText -ModDesc $modDesc -Name $item.L10nName `
-EnglishText "Produces $amountEn l $($product.En) per in-game hour." `
-GermanText "Produziert $amountDe l $($product.De) pro Ingame-Stunde."
}
$settings = New-Object System.Xml.XmlWriterSettings
$settings.Encoding = New-Object System.Text.UTF8Encoding($false)
$settings.Indent = $false
$settings.NewLineChars = "`r`n"
$writer = [System.Xml.XmlWriter]::Create($modDescPath, $settings)
try {
$modDesc.Save($writer)
}
finally {
$writer.Close()
}
}
if ([string]::IsNullOrWhiteSpace($ModsPath)) {
$candidates = @(
(Join-Path $env:USERPROFILE "OneDrive\Dokumente\My Games\FarmingSimulator2025\mods"),
@@ -31,6 +149,8 @@ if (-not (Test-Path -LiteralPath $ModsPath)) {
New-Item -ItemType Directory -Force -Path $ModsPath | Out-Null
}
Update-ProductionDescriptions -ProjectRoot $projectRoot
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem