package com.blarg.gdx.tilemap3d.serialization;

import com.blarg.gdx.tilemap3d.Tile;
import com.blarg.gdx.tilemap3d.TileChunk;

import java.nio.ByteBuffer;

public class TileChunkSerializer {
	public static final int TILE_SIZE_BYTES = 10;  // TODO: is there some kind of java sizeof() type thing?

	public static void serialize(TileChunk chunk, ByteBuffer buffer) {
		Tile[] tiles = chunk.getData();
		for (int i = 0; i < tiles.length; ++i)
			serialize(tiles[i], buffer);
	}

	public static void deserialize(ByteBuffer buffer, TileChunk out) {
		Tile[] tiles = out.getData();
		for (int i = 0; i < tiles.length; ++i)
			deserialize(buffer, tiles[i]);
	}

	public static void serialize(Tile tile, ByteBuffer buffer) {
		buffer.putShort(tile.tile);
		buffer.putShort(tile.flags);
		buffer.put(tile.tileLight);
		buffer.put(tile.skyLight);
		buffer.putInt(tile.color);
	}

	public static void deserialize(ByteBuffer buffer, Tile out) {
		out.tile = buffer.getShort();
		out.flags = buffer.getShort();
		out.tileLight = buffer.get();
		out.skyLight = buffer.get();
		out.color = buffer.getInt();
	}
}

@@ -229,17 +229,17 @@
 YTES = 1
-0
+7
 ;  // TO
@@ -847,203 +847,721 @@
 .put
-Int(tile.color);%0A%09%7D%0A%0A%09public static void deserialize(ByteBuffer buffer, Tile out) %7B%0A%09%09out.tile = buffer.getShort();%0A%09%09out.flags = buffer.getShort();%0A%09%09out.tileLight = buffer.get();%0A%09%09out.skyLight
+(tile.rotation);%0A%09%09buffer.put(tile.parentTileOffsetX);%0A%09%09buffer.put(tile.parentTileOffsetY);%0A%09%09buffer.put(tile.parentTileOffsetZ);%0A%09%09buffer.put(tile.parentTileWidth);%0A%09%09buffer.put(tile.parentTileHeight);%0A%09%09buffer.put(tile.parentTileDepth);%0A%09%09buffer.putInt(tile.color);%0A%09%7D%0A%0A%09public static void deserialize(ByteBuffer buffer, Tile out) %7B%0A%09%09out.tile = buffer.getShort();%0A%09%09out.flags = buffer.getShort();%0A%09%09out.tileLight = buffer.get();%0A%09%09out.skyLight = buffer.get();%0A%09%09out.rotation = buffer.get();%0A%09%09out.parentTileOffsetX = buffer.get();%0A%09%09out.parentTileOffsetY = buffer.get();%0A%09%09out.parentTileOffsetZ = buffer.get();%0A%09%09out.parentTileWidth = buffer.get();%0A%09%09out.parentTileHeight = buffer.get();%0A%09%09out.parentTileDepth
  = b

add new Tile fields to serialization methods