public GameObject Spawn(string level) { var pieces = new Dictionary <MapPiece, GameObject> { { MapPiece.Floor, floor }, { MapPiece.FailsafeFloor, failsafeFloor }, { MapPiece.Root, root }, { MapPiece.RootKey, rootKey }, { MapPiece.DataCube, dataCube }, { MapPiece.Routine, subroutine }, { MapPiece.DoubleRoutine, doubleSubroutine }, { MapPiece.JumpingRoutine, jumpingSubroutine } }; var map = TokenizedLevelMap.FromString(level); var iterator = new TwoDimensionalIterator(map.Width, map.Height); var obj = new GameObject(); iterator.Select(p => new TilePoint(p.Item1, p.Item2)).ForEach(t => { Instantiate(pieces[map.FloorLayer[t.X, t.Y]], new Vector3(t.X, t.Y, 0), Quaternion.identity, obj.transform); Instantiate(pieces[map.ObjectLayer[t.X, t.Y]], new Vector3(t.X, t.Y, 0), Quaternion.identity, obj.transform); }); return(obj); }
public static LevelSimulationSnapshot Create(LevelMap map) { var iterator = new TwoDimensionalIterator(map.Width, map.Height); var floors = new List <TilePoint>(); var disengagedFailsafes = new List <TilePoint>(); var oneHealthSubroutines = new List <TilePoint>(); var twoHealthSubroutines = new List <TilePoint>(); var iceSubroutines = new List <TilePoint>(); var dataCubes = new List <TilePoint>(); var root = new TilePoint(-999, -999); var rootKey = new TilePoint(-999, -999); iterator.ForEach(t => { var(x, y) = t; var point = new TilePoint(x, y); if (map.FloorLayer[x, y] == MapPiece.Floor) { floors.Add(point); } if (map.FloorLayer[x, y] == MapPiece.FailsafeFloor) { disengagedFailsafes.Add(point); } if (map.ObjectLayer[x, y] == MapPiece.Routine) { oneHealthSubroutines.Add(point); } if (map.ObjectLayer[x, y] == MapPiece.DoubleRoutine) { twoHealthSubroutines.Add(point); } if (map.ObjectLayer[x, y] == MapPiece.JumpingRoutine) { iceSubroutines.Add(point); } if (map.ObjectLayer[x, y] == MapPiece.DataCube) { dataCubes.Add(point); } if (map.ObjectLayer[x, y] == MapPiece.Root) { root = point; } if (map.ObjectLayer[x, y] == MapPiece.RootKey) { rootKey = point; } }); if (root.X == -999 || rootKey.X == -999) { throw new ArgumentException($"Map {map.Name} is missing it's Root or Root Key!"); } return(new LevelSimulationSnapshot(floors, disengagedFailsafes, oneHealthSubroutines, twoHealthSubroutines, iceSubroutines, dataCubes, root, rootKey)); }