Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Move MapNeighbours to Galaxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander0542 committed Oct 28, 2021
1 parent 872b8c2 commit 139cf1e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/Avans.FlatGalaxy.Models/Galaxy.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Avans.FlatGalaxy.Models.CelestialBodies;
using Avans.FlatGalaxy.Models.CelestialBodies.States;

Expand Down Expand Up @@ -42,6 +43,17 @@ public void Remove(CelestialBody celestialBody)
_celestialBodies.Remove(celestialBody);
}

public void MapNeighbours(IDictionary<Planet, string[]> planetNeighbours)
{
foreach (var (planet, neighbours) in planetNeighbours)
{
foreach (var neighbour in neighbours)
{
planet.Neighbours.Add(CelestialBodies.OfType<Planet>().First(b => b.Name == neighbour));
}
}
}

public void OnCompleted()
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,5 @@ protected ConfigurationParserBase(ICelestialBodyFactory celestialBodyFactory)
public abstract Galaxy Parse(string content);

public abstract bool CanParse(string content);

protected static void MapNeighbours(Galaxy galaxy, Dictionary<Planet, string[]> planetNeighbours)
{
foreach (var (planet, neighbours) in planetNeighbours)
{
foreach (var neighbour in neighbours)
{
planet.Neighbours.Add(galaxy.CelestialBodies.OfType<Planet>().First(b => b.Name == neighbour));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override Galaxy Parse(string content)
}
}

MapNeighbours(galaxy, planetNeighbours);
galaxy.MapNeighbours(planetNeighbours);
return galaxy;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override Galaxy Parse(string content)
if (body is Planet planet) planetNeighbours.Add(planet, neighbours.ToArray());
}

MapNeighbours(galaxy, planetNeighbours);
galaxy.MapNeighbours(planetNeighbours);
return galaxy;
}
}
Expand Down

0 comments on commit 139cf1e

Please sign in to comment.