53 lines
2.2 KiB
PowerShell
53 lines
2.2 KiB
PowerShell
param(
|
|
[string]$GridMiscActionFile = "Unity/Assets/Scripts/TH1_Logic/Action/GridMiscActionLogic.cs"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repoRoot = git rev-parse --show-toplevel 2>$null
|
|
if (-not $repoRoot) {
|
|
throw "Not inside a git repository."
|
|
}
|
|
$repoRoot = [System.IO.Path]::GetFullPath($repoRoot.Trim())
|
|
|
|
function Read-RepoFile([string]$relativePath) {
|
|
$fullPath = Join-Path $repoRoot $relativePath
|
|
if (-not (Test-Path -LiteralPath $fullPath)) {
|
|
throw "Required file not found: $fullPath"
|
|
}
|
|
return Get-Content -LiteralPath $fullPath -Raw -Encoding UTF8
|
|
}
|
|
|
|
$text = Read-RepoFile $GridMiscActionFile
|
|
|
|
if ($text -notmatch 'private static bool CanGrowForestOnGrid\(CommonActionParams actionParams\)') {
|
|
throw "GrowForest under-building guardrail failed: missing shared CanGrowForestOnGrid predicate."
|
|
}
|
|
|
|
$method = [regex]::Match($text, '(?ms)private static bool CanGrowForestOnGrid\(CommonActionParams actionParams\).*?^\s*\}')
|
|
if (-not $method.Success) {
|
|
throw "GrowForest under-building guardrail failed: cannot locate CanGrowForestOnGrid body."
|
|
}
|
|
|
|
foreach ($needle in @(
|
|
'grid.ResourceUnderBuilding != ResourceType.None',
|
|
'grid.Resource is ResourceType.None or ResourceType.Crop or ResourceType.Fruit',
|
|
'TechAtom.KaguyaFrenchNapoleonicCode'
|
|
)) {
|
|
if (-not $method.Value.Contains($needle)) {
|
|
throw "GrowForest under-building guardrail failed: CanGrowForestOnGrid missing '$needle'."
|
|
}
|
|
}
|
|
|
|
$checkCanBlock = [regex]::Match($text, '(?ms)public override bool CheckCan\(CommonActionParams actionParams\).*?public override bool CheckShow')
|
|
if (-not $checkCanBlock.Success -or -not $checkCanBlock.Value.Contains('return CanGrowForestOnGrid(actionParams);')) {
|
|
throw "GrowForest under-building guardrail failed: CheckCan must use CanGrowForestOnGrid."
|
|
}
|
|
|
|
$checkShowBlock = [regex]::Match($text, '(?ms)public override bool CheckShow\(CommonActionParams actionParams,out ShowType showType\).*?protected bool GridMiscActionPayMoney')
|
|
if (-not $checkShowBlock.Success -or -not $checkShowBlock.Value.Contains('return CanGrowForestOnGrid(actionParams);')) {
|
|
throw "GrowForest under-building guardrail failed: CheckShow must use CanGrowForestOnGrid."
|
|
}
|
|
|
|
Write-Host "GrowForest under-building resource guardrail passed."
|