36 lines
1.2 KiB
Java
36 lines
1.2 KiB
Java
package ch.fritteli.maze.generator.serialization.v1;
|
|
|
|
import ch.fritteli.maze.generator.model.Maze;
|
|
import ch.fritteli.maze.generator.model.Tile;
|
|
import ch.fritteli.maze.generator.serialization.AbstractMazeOutputStream;
|
|
import lombok.NonNull;
|
|
|
|
public class MazeOutputStreamV1 extends AbstractMazeOutputStream {
|
|
|
|
@Override
|
|
public void writeHeader() {
|
|
this.writeByte(SerializerDeserializerV1.MAGIC_BYTE_1);
|
|
this.writeByte(SerializerDeserializerV1.MAGIC_BYTE_2);
|
|
this.writeByte(SerializerDeserializerV1.VERSION_BYTE);
|
|
}
|
|
|
|
@Override
|
|
public void writeMazeData(@NonNull final Maze maze) {
|
|
final long randomSeed = maze.getRandomSeed();
|
|
final int width = maze.getWidth();
|
|
final int height = maze.getHeight();
|
|
this.writeLong(randomSeed);
|
|
this.writeInt(width);
|
|
this.writeInt(height);
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
for (int x = 0; x < width; x++) {
|
|
// We .get() it, because we want to crash hard if it is not available.
|
|
final Tile tile = maze.getTileAt(x, y).get();
|
|
final byte bitmask = SerializerDeserializerV1.getBitmaskForTile(tile);
|
|
this.writeByte(bitmask);
|
|
}
|
|
}
|
|
}
|
|
}
|