fix: round-trip match objectives through ScenarioSerializer

This commit is contained in:
Keith Solomon
2026-07-25 22:21:25 -05:00
parent a6d93dd1d3
commit a0dcff2c2a
2 changed files with 55 additions and 1 deletions
+18 -1
View File
@@ -130,6 +130,14 @@ final class ScenarioSerializer
$units[] = self::unitToArray($unit);
}
$objectives = [];
foreach ($match->objectives as $id => $objective) {
$objectives[(string) $id] = [
'id' => $objective->id,
'position' => self::positionToArray($objective->position),
];
}
return [
'battlefield' => [
'width' => $match->battlefield->width,
@@ -141,6 +149,7 @@ final class ScenarioSerializer
'round' => $match->round,
'winnerTeamId' => $match->winnerTeamId,
'actionLog' => $match->actionLog,
'objectives' => $objectives,
'victoryCondition' => $match->victoryCondition->value,
'holdRoundsRequired' => $match->holdRoundsRequired,
'objectiveControl' => $match->objectiveControl,
@@ -166,6 +175,14 @@ final class ScenarioSerializer
$units[] = self::unitFromArray($row);
}
$objectives = [];
foreach (($data['objectives'] ?? []) as $id => $row) {
$objectives[(string) $id] = new ObjectiveMarker(
(string) $row['id'],
self::positionFromArray($row['position']),
);
}
return new MatchState(
battlefield: $battlefield,
units: $units,
@@ -173,7 +190,7 @@ final class ScenarioSerializer
round: (int) $data['round'],
winnerTeamId: $data['winnerTeamId'] ?? null,
actionLog: array_map(static fn (mixed $entry): string => (string) $entry, $data['actionLog'] ?? []),
objectives: [],
objectives: $objectives,
victoryCondition: VictoryCondition::from((string) $data['victoryCondition']),
holdRoundsRequired: (int) $data['holdRoundsRequired'],
objectiveControl: $data['objectiveControl'] ?? [],