add TilePrefab saving
This commit is contained in:
parent
41c7dce4f4
commit
a64683f74b
|
@ -34,4 +34,25 @@ public class TilePrefabLoader {
|
||||||
|
|
||||||
return prefab;
|
return prefab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void save(TilePrefab prefab, String outputFilename) {
|
||||||
|
if (prefab == null)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
JsonTilePrefab jsonPrefab = new JsonTilePrefab();
|
||||||
|
jsonPrefab.width = prefab.getWidth();
|
||||||
|
jsonPrefab.height = prefab.getHeight();
|
||||||
|
jsonPrefab.depth = prefab.getDepth();
|
||||||
|
|
||||||
|
byte[] dataBytes = new byte[prefab.getData().length * TileDataSerializer.TILE_SIZE_BYTES];
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(dataBytes);
|
||||||
|
|
||||||
|
TileDataSerializer.serialize(prefab, buffer);
|
||||||
|
jsonPrefab.data = new String(Base64Coder.encode(dataBytes));
|
||||||
|
|
||||||
|
Json json = new Json();
|
||||||
|
String output = json.prettyPrint(jsonPrefab);
|
||||||
|
FileHandle outputFile = Gdx.files.local(outputFilename);
|
||||||
|
outputFile.writeString(output, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue