Example #1
0
        public Chunk(JsonObject json)
        {
            json.TryGetValue("position", out var position);
            ((JsonObject)position).TryGetValue("x", out var x_x);
            ((JsonObject)position).TryGetValue("y", out var y_y);
            var x_ = (int)x_x;
            var y_ = (int)y_y;

            WorldPos = new Vector2(x_, y_);
            ChunkId  = new ChunkIdentifier(x_, y_);
            if (json.TryGetValue("data", out var data))
            {
                var arr = (JsonArray)data;
                foreach (var val in arr)
                {
                    ((JsonObject)val).TryGetValue("type", out var otype);
                    if (otype == "tile")
                    {
                        ((JsonObject)val).TryGetValue("tiletype", out var ttype);
                        var tile = (EnumTiles)(int)ttype;
                        ((JsonObject)val).TryGetValue("position", out var pos);
                        ((JsonObject)pos).TryGetValue("x", out var xx);
                        ((JsonObject)pos).TryGetValue("y", out var yy);
                        var x = (int)xx;
                        var y = (int)yy;
                        Tiles[(x / 256) / 8, (y / 256) / 8] = new Tile(tile, this, new Vector2(x, y));
                    }
                }
            }
        }
Example #2
0
 public static Chunk LoadChunk(ChunkIdentifier chunkid)
 {
     Chunks.TryGetValue(chunkid, out var chunk);
     if (!Chunks.ContainsKey(chunkid))
     {
         chunk = new Chunk(chunkid.Pos * 256 * 8);
         Chunks.Add(chunkid, chunk);
         ChunksLoaded.Add(chunk);
     }
     return(chunk);
 }
Example #3
0
 public Chunk(Vector2 position)
 {
     WorldPos  = position;
     var(x, y) = position;
     ChunkId   = new ChunkIdentifier((int)x, (int)y);
     for (var i = 255; i > Tiles.GetUpperBound(0); i--)
     {
         for (var j = 255; j > Tiles.GetUpperBound(1); j--)
         {
             Tiles[i, j] = null;
         }
     }
 }
Example #4
0
        public static Chunk LoadChunk(ChunkIdentifier chunkid, Chunk chunk)
        {
            if (!Chunks.ContainsKey(chunkid))
            {
                Chunks.Add(chunkid, chunk);
            }
            if (!ChunksLoaded.Contains(chunk))
            {
                ChunksLoaded.Add(chunk);
            }

            return(chunk);
        }
Example #5
0
 public static Chunk GetFromId(ChunkIdentifier id)
 {
     ChunkedWorld.Chunks.TryGetValue(id, out var chunk);
     return(chunk);
 }