LifePlay-Revival/Tools/NewMod.ps1

68 lines
3.1 KiB
PowerShell
Raw Normal View History

<#
.SYNOPSIS
Cree le squelette d'un mod d'assets (lot H3c, Docs/Modding/FullGuides/Creating_Asset_Mods.md).
.DESCRIPTION
Cree ModSources\<Nom>\ :
<Nom>.uplugin plugin de contenu (assets cuits a part du jeu)
Content\ assets du mod (a remplir dans l'editeur : Tools/EditMod.ps1)
Module\<Nom>.lpmod module LifePlay (MODULE_UNIQUEID = <Nom>, active depuis le gestionnaire de mods)
Module\CREDITS.txt credits et licences des assets
et, avec -Hairs, Tools\mods\<Nom>.json (configuration de Tools/HairPipeline.ps1, liste de coiffures vide).
Refuse un nom deja pris (sources, module du jeu ou plugin).
.EXAMPLE
.\Tools\NewMod.ps1 -Name MyHairPack -Title "My Hair Pack" -Author "Me" -Hairs
#>
param(
[Parameter(Mandatory)] [ValidatePattern('^[A-Za-z][A-Za-z0-9_]{2,40}$')] [string] $Name,
[Parameter(Mandatory)] [string] $Title,
[Parameter(Mandatory)] [string] $Author,
[string] $Description = '',
[string] $Link = '',
[switch] $Hairs
)
$ErrorActionPreference = 'Stop'
$Root = Split-Path $PSScriptRoot -Parent
$src = Join-Path $Root "ModSources\$Name"
foreach ($taken in $src, (Join-Path $Root "Mods\$Name"), (Join-Path $Root "Content\Modules\$Name"), (Join-Path $Root "Plugins\$Name")) {
if (Test-Path $taken) { throw "Nom deja pris : $taken" }
}
$utf8 = New-Object Text.UTF8Encoding $false
New-Item -ItemType Directory -Force (Join-Path $src 'Content'), (Join-Path $src 'Module') | Out-Null
$plugin = [ordered]@{
FileVersion = 3; Version = 1; VersionName = '1.0'
FriendlyName = $Title
Description = $(if ($Description) { $Description } else { "LifePlay mod: $Title" })
Category = 'LifePlay Mods'; CreatedBy = $Author
CanContainContent = $true; IsBetaVersion = $false; Installed = $false
}
[IO.File]::WriteAllText((Join-Path $src "$Name.uplugin"), ($plugin | ConvertTo-Json) + "`r`n", $utf8)
$lpmod = @(
"MODULE_UNIQUEID: $Name",
"MODULE_NAME: $Title",
"MODULE_AUTHOR: $Author",
"MODULE_LINK: $Link",
"MODULE_DESCRIPTION: $(if ($Description) { $Description } else { $Title })",
'MODULE_REQUIREMENTS: vin_Base')
[IO.File]::WriteAllText((Join-Path $src "Module\$Name.lpmod"), ($lpmod -join "`r`n") + "`r`n", $utf8)
[IO.File]::WriteAllText((Join-Path $src 'Module\CREDITS.txt'), "Credits and licenses of the assets in $Title (one line per asset: title, author, license, source URL, changes).`r`n", $utf8)
if ($Hairs) {
$cfgPath = Join-Path $Root "Tools\mods\$Name.json"
if (Test-Path $cfgPath) { throw "$cfgPath existe deja" }
$cfg = [ordered]@{
mod = $Name; module = $Name; folder = "/$Name/Hairs"
backup = "D:/Game/LifePlay_Backup_5.5/mods/$Name"
hairs = @()
}
New-Item -ItemType Directory -Force (Split-Path $cfgPath -Parent) | Out-Null
[IO.File]::WriteAllText($cfgPath, ($cfg | ConvertTo-Json -Depth 4) + "`r`n", $utf8)
Write-Host "Configuration des coiffures : $cfgPath (ajouter les entrees de 'hairs', voir Tools/mods/LPHairSample.json)"
}
Write-Host "Mod cree : $src"
Write-Host "Suite : .\Tools\EditMod.ps1 -Name $Name (assets dans l'editeur), puis .\Tools\BuildMod.ps1 -Name $Name"