prepare for hexagon display & other models
- display cell as hexagon is Display.mHexagon if set ( not default ) will need a checkbox to set this - various new models preparation...
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package org.artisanlogiciel.games.maze.persist;
|
||||
|
||||
import org.artisanlogiciel.games.maze.model.HalfSquareRasterModel;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class HalfSquareRasterModelPersistRaw {
|
||||
private HalfSquareRasterModel model;
|
||||
|
||||
private static byte HEADER[] = new byte[]{(byte) 'L', (byte) 'A', (byte) 'B', (byte) '1'};
|
||||
|
||||
public HalfSquareRasterModelPersistRaw(HalfSquareRasterModel model)
|
||||
{
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public HalfSquareRasterModelPersistRaw()
|
||||
{
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
|
||||
public void streamOut(String pFormat, OutputStream pOut) throws IOException {
|
||||
if ((pFormat == null) || (pFormat.equals("sraw"))) {
|
||||
// first raw format, not smart.
|
||||
DataOutputStream dataOut = new DataOutputStream(pOut);
|
||||
// should dump this to stream.
|
||||
dataOut.write(HEADER);
|
||||
dataOut.writeInt(model.getWidth());
|
||||
dataOut.writeInt(model.getHeight());
|
||||
dataOut.flush();
|
||||
long[][] t = model.getLines();
|
||||
for (int y = 0; y < model.getHeight(); y++) {
|
||||
for (int x = 0; x < model.getLongs(); x++) {
|
||||
dataOut.writeLong(t[y][x]);
|
||||
}
|
||||
}
|
||||
dataOut.flush();
|
||||
} else {
|
||||
throw new IOException("Format " + pFormat + " Not yet implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public HalfSquareRasterModel parseInputStream(String pFormat, InputStream pIn) throws IOException {
|
||||
if ((pFormat == null) || (pFormat.equals("sraw"))) {
|
||||
// maxdepth is unset then unmodified
|
||||
byte[] header = new byte[4];
|
||||
DataInputStream in = new DataInputStream(pIn);
|
||||
in.read(header);
|
||||
int rwidth = in.readInt();
|
||||
int rheight = in.readInt();
|
||||
if ((rwidth > 0) && (rheight > 0)) {
|
||||
int width = rwidth;
|
||||
int height = rheight;
|
||||
model= new HalfSquareRasterModel(width, height);
|
||||
// SHOULD CHECK max width and max height...
|
||||
// CLEAR == 0 and array is initialized with 0s
|
||||
long[][] t = model.getLines();
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < model.getLongs(); x++) {
|
||||
t[y][x] = in.readLong();
|
||||
}
|
||||
}
|
||||
return model;
|
||||
} else {
|
||||
throw new IOException("Invalid header for width and height");
|
||||
}
|
||||
// should be at end of stream ? Not necessary can stream multiple
|
||||
// labs ( or tiling ).
|
||||
} else {
|
||||
throw new IOException("Format " + pFormat + " Not yet implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,8 +4,13 @@ import org.artisanlogiciel.games.maze.LabyModel;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* raw model with short table inner of LabyModel
|
||||
*/
|
||||
public class MazePersistRaw
|
||||
{
|
||||
private static byte HEADER[] = new byte[]{(byte) 'L', (byte) 'A', (byte) 'B', (byte) '0'};
|
||||
|
||||
private LabyModel model;
|
||||
|
||||
public MazePersistRaw(LabyModel model)
|
||||
@@ -24,7 +29,7 @@ public class MazePersistRaw
|
||||
// first raw format, not smart.
|
||||
DataOutputStream dataOut = new DataOutputStream(pOut);
|
||||
// should dump this to stream.
|
||||
dataOut.write(new byte[]{(byte) 'L', (byte) 'A', (byte) 'B', (byte) '0'});
|
||||
dataOut.write(HEADER);
|
||||
dataOut.writeInt(model.getWidth());
|
||||
dataOut.writeInt(model.getHeight());
|
||||
dataOut.flush();
|
||||
@@ -46,6 +51,7 @@ public class MazePersistRaw
|
||||
byte[] header = new byte[4];
|
||||
DataInputStream in = new DataInputStream(pIn);
|
||||
in.read(header);
|
||||
// TODO check header == HEADER
|
||||
int rwidth = in.readInt();
|
||||
int rheight = in.readInt();
|
||||
if ((rwidth > 0) && (rheight > 0)) {
|
||||
|
||||
Reference in New Issue
Block a user