Add event id validation
This commit is contained in:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user