Add event id validation

This commit is contained in:
2026-06-18 12:20:04 +09:00
parent 47754b5d45
commit c3a09d6577
2 changed files with 31 additions and 7 deletions

View File

@@ -1408,6 +1408,35 @@ function Check-Post-Battle-Choices($Choices, [string]$ScenarioId) {
}
}
function Check-Event-Ids($Events, [string]$ScenarioId) {
$eventIds = New-Object System.Collections.Generic.HashSet[string]
if ($null -eq $Events) {
return ,$eventIds
}
if (-not ($Events -is [System.Array])) {
Fail "Scenario $ScenarioId events must be an array."
}
foreach ($event in @($Events)) {
if ($event -is [string] -or $event -is [System.Array]) {
Fail "Scenario $ScenarioId has malformed event."
}
if (-not (Has-Prop $event "id")) {
Fail "Scenario $ScenarioId event has empty id."
}
$eventId = [string](Get-Prop $event "id" "")
if ([string]::IsNullOrWhiteSpace($eventId)) {
Fail "Scenario $ScenarioId event has empty id."
}
if (-not ($eventId -match "^[a-z0-9_]+$")) {
Fail "Scenario $ScenarioId event has unstable id: $eventId"
}
if (-not $eventIds.Add($eventId)) {
Fail "Scenario $ScenarioId has duplicate event id: $eventId"
}
}
return ,$eventIds
}
function Check-Required-Flags($RequiredFlags, [string]$ScenarioId, [string]$Context) {
if ($null -eq $RequiredFlags) {
return
@@ -1602,12 +1631,7 @@ foreach ($scenario in $campaign.scenarios) {
}
}
$eventIds = New-Object System.Collections.Generic.HashSet[string]
foreach ($event in (Get-Prop $scenarioData "events" @())) {
if (Has-Prop $event "id") {
$eventIds.Add([string]$event.id) | Out-Null
}
}
$eventIds = Check-Event-Ids (Get-Prop $scenarioData "events" $null) $scenarioId
$knownUnitIds = Collect-Scenario-Unit-Ids $scenarioData
if (Has-Prop $scenarioData "conditions") {