public void TestFromBytes() { Tile tile = new Tile(); tile.FromBytes(new byte[] { 1, 2, 3, 4 }, 0); Assert.AreEqual((2 << 8) | 1, tile.TileSetId); Assert.AreEqual((4 << 8) | 3, tile.TileId); tile.FromBytes(new byte[] { 1, 2, 3, 4, 5 }, 1); Assert.AreEqual((3 << 8) | 2, tile.TileSetId); Assert.AreEqual((5 << 8) | 4, tile.TileId); }
public override void LoadJson(JToken json) { this.Clear(); JToken token; if ((token = json["Name"] as JValue) != null) { this.Name = token.Value<string>(); } if ((token = json["Width"] as JValue) != null) { this.Width = token.Value<int>(); } if ((token = json["Height"] as JValue) != null) { this.Height = token.Value<int>(); } if ((token = json["Tiles"] as JArray) != null) { for (int i = 0; i < LayerCount; i++) { JValue token2 = token[i] as JValue; byte[] bytes = Convert.FromBase64String(token2.Value<string>()); int length = this.Width * this.Height; List<Tile> layer = this.Layers[i]; for (int j = 0; j < length; j++) { Tile tile = new Tile(); tile.FromBytes(bytes, j * 4); layer[j] = tile; } } } }