Skip to content

Commit

Permalink
Migrate pre-0.7.0.7 routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed Dec 29, 2023
1 parent a80ab43 commit d99f4a0
Showing 1 changed file with 87 additions and 4 deletions.
91 changes: 87 additions & 4 deletions src/RoadCaptain.Adapters/RouteStoreToDisk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,95 @@ internal PlannedRoute DeserializeAndUpgrade(string serialized)
{
plannedRoute.LoopMode = LoopMode.Infinite;
}
}

if (routeVersion < new Version(0, 7, 0, 7))
{
// With version 0.7.0.9 we've added new segments to Watopia
// and split a few which we need to correct for.

void SplitSequence(List<SegmentSequence> newSequence, string segmentId, SegmentSequence sequence, int index)
{
if (sequence.Direction == SegmentDirection.AtoB)
{
newSequence.Add(
new SegmentSequence(
$"{segmentId}-before",
sequence.Type,
sequence.Direction,
index+1));
newSequence[^1].TurnToNextSegment = TurnDirection.GoStraight;
newSequence[^1].NextSegmentId = $"{segmentId}-after";

newSequence.Add(
new SegmentSequence(
$"{segmentId}-after",
sequence.Type,
sequence.Direction,
index+2));
newSequence[^1].TurnToNextSegment = sequence.TurnToNextSegment;
newSequence[^1].NextSegmentId = sequence.NextSegmentId;
}
else
{
newSequence.Add(
new SegmentSequence(
$"{segmentId}-after",
sequence.Type,
sequence.Direction,
index+1));
newSequence[^1].TurnToNextSegment = TurnDirection.GoStraight;
newSequence[^1].NextSegmentId = $"{segmentId}-before";

newSequence.Add(
new SegmentSequence(
$"{segmentId}-before",
sequence.Type,
sequence.Direction,
index+2));
newSequence[^1].TurnToNextSegment = sequence.TurnToNextSegment;
newSequence[^1].NextSegmentId = sequence.NextSegmentId;
}
}

var newSequence = new List<SegmentSequence>();
var index = 0;
var tainted = false;

foreach (var sequence in plannedRoute.RouteSegmentSequence)
{
if (sequence.SegmentId == "watopia-bambino-fondo-003-after-after-before")
{
// 1: watopia-bambino-fondo-003-after-after-before is split
SplitSequence(newSequence, "watopia-bambino-fondo-003-after-after-before", sequence, index);
index += 2;
tainted = true;
}
else if (sequence.SegmentId == "watopia-tempus-fugit-001")
{
// 2: watopia-tempus-fugit-001 is split
SplitSequence(newSequence, "watopia-tempus-fugit-001", sequence, index);
index += 2;
tainted = true;
}
else if (sequence.SegmentId == "watopia-bambino-fondo-004-after-before")
{
// 3: watopia-bambino-fondo-004-after-before is split
SplitSequence(newSequence, "watopia-bambino-fondo-004-after-before", sequence, index);
index += 2;
tainted = true;
}
else
{
sequence.Index = index++;
newSequence.Add(sequence);
}
}

if (routeVersion < new Version(0, 7, 0, 7))
if (tainted)
{
// With version 0.7.0.9 we've added new segments to Watopia
// and split a few which we need to correct for.

plannedRoute.RouteSegmentSequence.Clear();
plannedRoute.RouteSegmentSequence.AddRange(newSequence);
}
}
}
Expand Down

0 comments on commit d99f4a0

Please sign in to comment.