Add campaign chapter metadata

This commit is contained in:
2026-06-18 04:00:38 +09:00
parent b8378d9144
commit f0d941c273
8 changed files with 275 additions and 12 deletions

View File

@@ -120,6 +120,94 @@ foreach ($officerIdValue in (Get-Prop $campaign "initial_joined_officers" @()))
}
}
$campaignScenarioIds = @()
$campaignScenarioIdSet = New-Object System.Collections.Generic.HashSet[string]
foreach ($scenario in @($campaign.scenarios)) {
if ($scenario -is [System.Array] -or $null -eq $scenario) {
Fail "Campaign has a malformed scenario entry."
}
$scenarioId = [string](Get-Prop $scenario "id" "")
$scenarioTitle = [string](Get-Prop $scenario "title" "")
$scenarioPath = [string](Get-Prop $scenario "path" "")
if ([string]::IsNullOrWhiteSpace($scenarioId)) {
Fail "Campaign has a scenario with an empty id."
}
if (-not ($scenarioId -match '^[a-z0-9_]+$')) {
Fail "Campaign scenario has unstable id: $scenarioId"
}
if ([string]::IsNullOrWhiteSpace($scenarioTitle)) {
Fail "Campaign scenario $scenarioId has an empty title."
}
if ([string]::IsNullOrWhiteSpace($scenarioPath)) {
Fail "Campaign scenario $scenarioId has an empty path."
}
if (-not $campaignScenarioIdSet.Add($scenarioId)) {
Fail "Campaign has duplicate scenario id: $scenarioId"
}
$campaignScenarioIds += $scenarioId
}
if ($campaignScenarioIds.Count -le 0) {
Fail "Campaign has no scenarios."
}
if (-not $campaignScenarioIdSet.Contains([string]$campaign.start_scenario)) {
Fail "Campaign start_scenario references unknown scenario: $($campaign.start_scenario)"
}
if (Has-Prop $campaign "chapters") {
$chaptersValue = Get-Prop $campaign "chapters" $null
if ($chaptersValue -isnot [System.Array]) {
Fail "Campaign chapters must be an array."
}
if (@($chaptersValue).Count -le 0) {
Fail "Campaign chapters must not be empty."
}
$chapterIds = New-Object System.Collections.Generic.HashSet[string]
$coveredScenarioIds = New-Object System.Collections.Generic.HashSet[string]
foreach ($chapter in @($chaptersValue)) {
if ($chapter -is [System.Array] -or $null -eq $chapter) {
Fail "Campaign has a malformed chapter entry."
}
$chapterId = [string](Get-Prop $chapter "id" "")
$chapterTitle = [string](Get-Prop $chapter "title" "")
$startScenario = [string](Get-Prop $chapter "start_scenario" "")
$endScenario = [string](Get-Prop $chapter "end_scenario" "")
if ([string]::IsNullOrWhiteSpace($chapterId)) {
Fail "Campaign chapter has an empty id."
}
if (-not ($chapterId -match '^[a-z0-9_]+$')) {
Fail "Campaign chapter has unstable id: $chapterId"
}
if (-not $chapterIds.Add($chapterId)) {
Fail "Campaign has duplicate chapter id: $chapterId"
}
if ([string]::IsNullOrWhiteSpace($chapterTitle)) {
Fail "Campaign chapter $chapterId has an empty title."
}
if (-not $campaignScenarioIdSet.Contains($startScenario)) {
Fail "Campaign chapter $chapterId references unknown start_scenario: $startScenario"
}
if (-not $campaignScenarioIdSet.Contains($endScenario)) {
Fail "Campaign chapter $chapterId references unknown end_scenario: $endScenario"
}
$startIndex = [Array]::IndexOf($campaignScenarioIds, $startScenario)
$endIndex = [Array]::IndexOf($campaignScenarioIds, $endScenario)
if ($startIndex -lt 0 -or $endIndex -lt 0 -or $endIndex -lt $startIndex) {
Fail "Campaign chapter $chapterId has an invalid scenario range."
}
for ($index = $startIndex; $index -le $endIndex; $index++) {
$coveredScenarioId = [string]$campaignScenarioIds[$index]
if (-not $coveredScenarioIds.Add($coveredScenarioId)) {
Fail "Campaign chapter $chapterId overlaps scenario: $coveredScenarioId"
}
}
}
foreach ($scenarioId in $campaignScenarioIds) {
if (-not $coveredScenarioIds.Contains($scenarioId)) {
Fail "Campaign chapters do not cover scenario: $scenarioId"
}
}
}
function Check-Condition($Condition, [string]$ScenarioId, $EventIds, [int]$Width = -1, [int]$Height = -1, $Rows = $null, $KnownUnitIds = $null) {
if ($Condition -is [System.Array]) {
foreach ($entry in $Condition) {