fix: round-trip match objectives through ScenarioSerializer
This commit is contained in:
@@ -135,4 +135,41 @@ final class ScenarioSerializerTest extends TestCase
|
||||
// missing 'name', 'battlefield', 'units', etc.
|
||||
]);
|
||||
}
|
||||
|
||||
public function testMatchRoundTripsItsObjectives(): void
|
||||
{
|
||||
$battlefield = new Battlefield(10, 8);
|
||||
$units = [
|
||||
new UnitState('a1', 'alpha', new Position(0, 0), 10, 10, 3, 3, 2, 2, false),
|
||||
new UnitState('a2', 'alpha', new Position(1, 0), 10, 10, 3, 3, 2, 2, false),
|
||||
new UnitState('a3', 'alpha', new Position(2, 0), 10, 10, 3, 3, 2, 2, false),
|
||||
new UnitState('b1', 'bravo', new Position(9, 7), 10, 10, 3, 3, 2, 2, false),
|
||||
new UnitState('b2', 'bravo', new Position(8, 7), 10, 10, 3, 3, 2, 2, false),
|
||||
new UnitState('b3', 'bravo', new Position(7, 7), 10, 10, 3, 3, 2, 2, false),
|
||||
];
|
||||
$objective = new ObjectiveMarker('objective-1', new Position(5, 4));
|
||||
$original = new MatchState(
|
||||
battlefield: $battlefield,
|
||||
units: $units,
|
||||
activeTeamId: 'alpha',
|
||||
objectives: ['objective-1' => $objective],
|
||||
victoryCondition: VictoryCondition::HoldObjective,
|
||||
holdRoundsRequired: 3,
|
||||
);
|
||||
|
||||
$array = ScenarioSerializer::matchToArray($original);
|
||||
self::assertArrayHasKey('objectives', $array);
|
||||
self::assertSame(
|
||||
['id' => 'objective-1', 'position' => ['x' => 5, 'y' => 4]],
|
||||
$array['objectives']['objective-1'] ?? null,
|
||||
);
|
||||
|
||||
$rebuilt = ScenarioSerializer::matchFromArray($array);
|
||||
self::assertArrayHasKey('objective-1', $rebuilt->objectives);
|
||||
self::assertSame('objective-1', $rebuilt->objectives['objective-1']->id);
|
||||
self::assertSame(5, $rebuilt->objectives['objective-1']->position->x);
|
||||
self::assertSame(4, $rebuilt->objectives['objective-1']->position->y);
|
||||
self::assertSame(VictoryCondition::HoldObjective, $rebuilt->victoryCondition);
|
||||
self::assertSame(3, $rebuilt->holdRoundsRequired);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user