fix: round-trip match objectives through ScenarioSerializer
This commit is contained in:
@@ -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'] ?? [],
|
||||
|
||||
Reference in New Issue
Block a user