Hasta ahora el script puede realizar lo siguiente:
-Modificar todos los archivos JSON que contengan la palabra Window dentro de las carpetas game, menu y shared.
-Modificar el campo "RenderColor" solo para la ventana principal en los archivos JSON que sean sobre las ventanas.
-Que las modificaciones se apliquen cuando compilas en debug, release o publish.
Los ajustes a realizar son los siguientes:
-Que busque en cualquier ubicacion dentro de gui/layouts/
-que cambie los otros archivos con otro color
-que genere un log de cada archivo modificado
Código
Intersect.Client.csproj
<!– Colores para los patrones de RenderColor (definir una sola vez) –>
<PropertyGroup>
<WindowColor>255,0,0,0</WindowColor>
<InputBoxColor>255,0,0,0</InputBoxColor>
</PropertyGroup>
<Target Name=»UpdateRenderColor» AfterTargets=»Build»>
<PropertyGroup>
<ResourcesOutputPath>$(OutputPath)/resources</ResourcesOutputPath>
<ProjectRoot>$([System.IO.Path]::GetFullPath(‘$(MSBuildProjectDirectory)\..’))</ProjectRoot>
<LogPath>$(ProjectRoot)\RenderColor-Log.md</LogPath>
</PropertyGroup>
<Exec Command=»powershell -ExecutionPolicy Bypass -File "$(ProjectDir)Update-RenderColor.ps1" -ResourcesDir "$(ResourcesOutputPath)" -Pattern "*Window*.json" -Color $(WindowColor) -LogPath "$(LogPath)"» />
<Exec Command=»powershell -ExecutionPolicy Bypass -File "$(ProjectDir)Update-RenderColor.ps1" -ResourcesDir "$(ResourcesOutputPath)" -Pattern "*InputBox*.json" -Color $(InputBoxColor) -LogPath "$(LogPath)"» />
</Target>
<Target Name=»UpdateRenderColorAfterPublish» AfterTargets=»Publish»>
<PropertyGroup> <ResourcesOutputPath>$(PublishDir)/resources</ResourcesOutputPath>
<ProjectRoot>$([System.IO.Path]::GetFullPath(‘$(MSBuildProjectDirectory)\..’))</ProjectRoot>
<LogPath>$(ProjectRoot)\RenderColor-Log.md</LogPath>
</PropertyGroup>
<Exec Command=»powershell -ExecutionPolicy Bypass -File "$(ProjectDir)Update-RenderColor.ps1" -ResourcesDir "$(ResourcesOutputPath)" -Pattern "*Window*.json" -Color $(WindowColor) -LogPath "$(LogPath)"» />
<Exec Command=»powershell -ExecutionPolicy Bypass -File "$(ProjectDir)Update-RenderColor.ps1" -ResourcesDir "$(ResourcesOutputPath)" -Pattern "*InputBox*.json" -Color $(InputBoxColor) -LogPath "$(LogPath)"» />
</Target>
</Project>
Update-RenderColor.ps1
param(
[Parameter(Mandatory=$true)]
[string]$ResourcesDir,
[string]$LogPath,
[string]$Pattern = ‘*Window*.json’
)
# Color nuevo (A,R,G,B)
$newColor = «200,0,0,0»
# Determinar ruta del log si no se proporciona
if (-not $LogPath) {
# Asumir que la raíz del proyecto está un nivel arriba del script (Intersect.Client -> Intersect-Engine)
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot «..»)
$LogPath = Join-Path $repoRoot «RenderColor-Log.md»
}
# Crear carpeta del log si no existe
$logDir = Split-Path $LogPath -Parent
if (-not (Test-Path $logDir)) {
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
}
# Convertir ResourcesDir a ruta absoluta
$absoluteResourcesDir = (Resolve-Path $ResourcesDir).Path
# Iniciar log con cabecera de ejecución
$timestamp = Get-Date -Format «yyyy-MM-dd HH:mm:ss»
Add-Content -Path $LogPath -Value «## $timestamp»
Add-Content -Path $LogPath -Value «- **Recursos:** «$absoluteResourcesDir«»
Add-Content -Path $LogPath -Value «- **Patrón:** «$Pattern«»
Add-Content -Path $LogPath -Value «- **Búsqueda:** Todas las subcarpetas dentro de «gui/layouts«»
Add-Content -Path $LogPath -Value «- **Nuevo color:** «$newColor«»
Add-Content -Path $LogPath -Value «»
# Contadores
$modified = 0
$noColor = 0
$errors = 0
# Ruta base donde buscar (gui/layouts)
$searchPath = Join-Path $absoluteResourcesDir «gui/layouts»
if (-not (Test-Path $searchPath)) {
Add-Content -Path $LogPath -Value «- ❌ Carpeta «gui/layouts« no encontrada en «$absoluteResourcesDir«»
Write-Host «Error: Carpeta gui/layouts no encontrada.» -ForegroundColor Red
exit 1
}
# Buscar archivos JSON que coincidan con el patrón recursivamente
$files = Get-ChildItem -Path $searchPath -Filter $Pattern -Recurse -File
foreach ($file in $files) {
# Calcular ruta relativa a la carpeta de recursos
# Normalizar rutas a absolutas sin barra final
try {
$baseDir = [System.IO.Path]::GetFullPath($absoluteResourcesDir).TrimEnd(‘\’)
$filePath = [System.IO.Path]::GetFullPath($file.FullName)
if ($filePath.StartsWith($baseDir + ‘\’)) {
$relativePath = $filePath.Substring($baseDir.Length + 1)
} else {
$relativePath = $filePath
}
# Reemplazar barras invertidas por barras normales para mejor legibilidad en Markdown
$relativePath = $relativePath.Replace(‘\’, ‘/’)
} catch {
# Fallback en caso de error
$relativePath = $file.FullName
}
try {
# Leer y parsear JSON
$content = Get-Content $file.FullName -Raw -ErrorAction Stop
$json = $content | ConvertFrom-Json -ErrorAction Stop
if (Get-Member -InputObject $json -Name «RenderColor») {
$oldColor = $json.RenderColor
$json.RenderColor = $newColor
# Convertir de nuevo a JSON y guardar
$json | ConvertTo-Json -Depth 20 | Set-Content $file.FullName -Encoding UTF8 -NoNewline -ErrorAction Stop
Add-Content -Path $LogPath -Value «- ✅ «$relativePath« → «$newColor« (era «$oldColor«)»
$modified++
} else {
Add-Content -Path $LogPath -Value «- ⚠️ «$relativePath« → No tiene RenderColor en raíz»
$noColor++
}
} catch {
Add-Content -Path $LogPath -Value «- ❌ «$relativePath« → Error: $($_.Exception.Message)»
$errors++
}
}
# Resumen
Add-Content -Path $LogPath -Value «»
Add-Content -Path $LogPath -Value «### Resumen»
Add-Content -Path $LogPath -Value «- Archivos encontrados: $($files.Count)»
Add-Content -Path $LogPath -Value «- Archivos modificados: $modified»
Add-Content -Path $LogPath -Value «- Archivos sin RenderColor en raíz: $noColor»
Add-Content -Path $LogPath -Value «- Errores: $errors»
Add-Content -Path $LogPath -Value «»
Add-Content -Path $LogPath -Value «—«
Add-Content -Path $LogPath -Value «»
# Mensajes en consola
Write-Host «Proceso completado.» -ForegroundColor Green
Write-Host » Archivos encontrados: $($files.Count)» -ForegroundColor Green
Write-Host » Modificados: $modified» -ForegroundColor Green
Write-Host » Sin RenderColor en raíz: $noColor» -ForegroundColor Yellow
Write-Host » Errores: $errors» -ForegroundColor Red
Write-Host » Log: $LogPath» -ForegroundColor Cyan





Deja una respuesta