private static void WriteJson(string output, BoundingBox3D rootBounds, List <TileInfo> tiles, string geometricErrors, string filename) { List <double> errors = ToDoubles(geometricErrors); var tilesetJSON = TilesetGenerator.GetTileSetJson(rootBounds, tiles, errors); var jsonFile = $"{output}{Path.DirectorySeparatorChar}{filename}"; File.WriteAllText(jsonFile, tilesetJSON); }
private static void WriteJson(string output, BoundingBox3D rootBounds, List <TileInfo> tiles, string geometricErrors) { var errors = geometricErrors.Split(',').Select(Double.Parse).ToList(); var tilesetJSON = TilesetGenerator.GetTileSetJson(rootBounds, tiles, errors); var jsonFile = $"{output}{Path.DirectorySeparatorChar}tileset.json"; using (StreamWriter outputFile = new StreamWriter(jsonFile)) { outputFile.WriteLine(tilesetJSON); Console.WriteLine("tileset.json exported"); } }
/// <summary> /// Initializes a new galaxy. This adds placeholder tiles and initializes data structures. /// </summary> /// <param name="maxRad">The maximum 'radius' of the galaxy.</param> /// <param name="playerCount">The number of players to initialize the galaxy for</param> public void init(int maxRad, int playerCount = 6) { players = playerCount; int width = 2 * maxRad + 1; tiles = new SystemTile[width][]; for (int i = 0; i <= 2 * maxRad; i++) { SystemTile[] row = new SystemTile[width]; for (int j = 0; j <= 2 * maxRad; j++) { row[j] = TilesetGenerator.GetBlankTile(); } tiles[i] = row; } MaxRadius = maxRad; }
public void GetTilesetTests() { // arrange var bounds = new BoundingBox3D(510231.3587475557, 6875083.881813413, 0, 525809.8658122736, 6887810.502260326, 0); var bbTile = new BoundingBox3D(510231.34375, 6881084, 0, 511231.34375, 6882084, 0); var tile = new TileInfo() { Bounds = bbTile }; // act var result = TilesetGenerator.GetTileSet(bounds, new List <TileInfo> { tile }, new List <double> { 500, 0 }, "REPLACE"); // assert (todo add more checks) Assert.IsNotNull(result); Assert.IsTrue(result.asset.version == "1.0"); }
/// <summary> /// Generates a 'standard' galaxy, X rings around Mecatol w/ home systems on outside edge. /// </summary> /// <param name="rad">'radius' of the galaxy to be generated. For this shape, also equals the number of rings around Mecatol</param> /// <param name="players">Number of players in current game</param> /// <param name="shuffle">The 'Shuffle' object used for randomization. Passing one in makes it less likely that seeding weirdness produces identical galaxies</param> public void GenerateStandard(int rad, int players = 6, Shuffle shuffle = null) { // TODO: Set HSLocations for player counts other than 6 // TODO: Maybe pull this out as a helper function? HSLocations = new List <Tuple <int, int> >(); if (players == 6) { HSLocations.Add(new Tuple <int, int>(0, rad)); HSLocations.Add(new Tuple <int, int>(0, 2 * rad)); HSLocations.Add(new Tuple <int, int>(rad, 0)); HSLocations.Add(new Tuple <int, int>(rad, 2 * rad)); HSLocations.Add(new Tuple <int, int>(2 * rad, 0)); HSLocations.Add(new Tuple <int, int>(2 * rad, rad)); } // Set player# of HS tiles (used for staking claims & making sure not to put an actual tile in that spot) for (int i = 1; i <= players; i++) { Tuple <int, int> tuple = HSLocations[i - 1]; tiles[tuple.Item1][tuple.Item2].playerNum = i; } int placeableTileCount = 3 * rad * (rad + 1) - players; // TODO: Consider making tileset configurable. For now, just keep adding a full set of game tiles until the required amount is reached. // May require multiple game copies, and/or the expansion. List <SystemTile> tileset = new List <SystemTile>(); while (tileset.Count < placeableTileCount) { tileset.AddRange(TilesetGenerator.GetAllTiles()); } shuffle = shuffle ?? new Shuffle(); shuffle.ShuffleList <SystemTile>(tileset); tileset = tileset.GetRange(0, placeableTileCount); int width = 2 * rad + 1; int index = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (x + y >= rad && x + y <= 3 * rad && !(x == rad && y == rad)) { if (tiles[x][y].playerNum == 0) { // for tiles within shape of galaxy that are not Home Systems, assign a tile. tiles[x][y] = tileset[index]; index++; } } else if (x == rad && y == rad) { // "He who controls the Mecatol controls the universe" tiles[x][y] = TilesetGenerator.GetMecatol(); } else { // tiles outside of the galaxy are assigned player number -1 tiles[x][y].playerNum = -1; } } } // make sure that all tiles adjacent to tile 'A' are within 'A's adjacent list for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (tiles[x][y].playerNum >= 0) { if (x < 2 * rad && tiles[x + 1][y].playerNum >= 0) { tiles[x][y].adjacent.Add(tiles[x + 1][y]); tiles[x + 1][y].adjacent.Add(tiles[x][y]); } if (y < 2 * rad && tiles[x][y + 1].playerNum >= 0) { tiles[x][y].adjacent.Add(tiles[x][y + 1]); tiles[x][y + 1].adjacent.Add(tiles[x][y]); } if (x < 2 * rad && y > 0 && tiles[x + 1][y - 1].playerNum >= 0) { tiles[x][y].adjacent.Add(tiles[x + 1][y - 1]); tiles[x + 1][y - 1].adjacent.Add(tiles[x][y]); } } } } connectWormholes(); }
static void Main(string[] args) { Parser.Default.ParseArguments <Options>(args).WithParsed(o => { string tileFolder = "tiles"; string geom_column = "geom"; SqlMapper.AddTypeHandler(new GeometryTypeHandler()); SqlMapper.AddTypeHandler(new JArrayTypeHandler()); Console.WriteLine($"Exporting i3dm's from {o.Table}..."); Console.WriteLine($"Tile extent: {o.ExtentTile}"); Console.WriteLine($"Set extent: {o.SuperExtentTile}"); var tilefolder = $"{o.Output}{Path.DirectorySeparatorChar}{tileFolder}"; if (!Directory.Exists(tilefolder)) { Directory.CreateDirectory(tilefolder); } var conn = new NpgsqlConnection(o.ConnectionString); var rootBounds = InstancesRepository.GetBoundingBox3DForTable(conn, o.Table, geom_column, o.Query); var r_super = rootBounds.GetRange(o.SuperExtentTile); var supertiles = r_super.xrange * r_super.yrange; var potentialtiles = (int)Math.Ceiling(supertiles * Math.Pow(o.SuperExtentTile / o.ExtentTile, 2)); var newBounds = new BoundingBox3D(rootBounds.XMin, rootBounds.YMin, rootBounds.ZMin, rootBounds.XMin + r_super.xrange * o.SuperExtentTile, rootBounds.YMin + r_super.yrange * o.SuperExtentTile, rootBounds.ZMax); Console.WriteLine($"Potential tiles: {potentialtiles} in {supertiles} sets."); var options = new ProgressBarOptions { ProgressCharacter = '-', ProgressBarOnBottom = true }; var pbar = new ProgressBar(potentialtiles, "Exporting i3dm tiles...", options); var supertilesets = new List <SuperTileSetJson>(); for (var x_super = 0; x_super < r_super.xrange; x_super++) { for (var y_super = 0; y_super < r_super.yrange; y_super++) { var supertilebounds = rootBounds.GetBounds(o.SuperExtentTile, x_super, y_super); var(xrange, yrange) = supertilebounds.GetRange(o.ExtentTile); var tiles = new List <TileInfo>(); for (var x = 0; x < xrange; x++) { for (var y = 0; y < yrange; y++) { CreateTile(o, tileFolder, conn, supertilebounds, tiles, x, y, $"{x_super}_{y_super}"); pbar.Tick(); } } var supertileSet = new SuperTileSetJson(x_super, y_super); supertileSet.FileName = supertiles > 1? $"tileset_{x_super}_{y_super}.json" : "tileset.json"; supertileSet.Bounds = supertilebounds; supertilesets.Add(supertileSet); WriteJson(o.Output, supertilebounds, tiles, o.GeometricErrors, supertileSet.FileName); } } if (supertiles > 1) { var supertileset = TilesetGenerator.GetSuperTileSet(newBounds, supertilesets, ToDoubles(o.GeometricErrors)); var json = JsonConvert.SerializeObject(supertileset, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); File.WriteAllText($"{o.Output}{ Path.DirectorySeparatorChar}tileset.json", json); } pbar.WriteLine("Export finished!"); pbar.Dispose(); }); }