load .we with layers

- and fix some bug : max is within range ( perhaps not as many as those added ...)
- quick hack in CharProvider to skip spaces ... ( bad it applies to strings too ...)
This commit is contained in:
philippe lhardy
2020-11-05 21:31:28 +01:00
parent bf918333bf
commit 6c9800047c
5 changed files with 63 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
package org.artisanlogiciel.games.maze.persist;
import org.artisanlogiciel.games.maze.Brick;
import org.artisanlogiciel.games.maze.LabyLayers;
import org.artisanlogiciel.games.maze.LabyModel;
import org.artisanlogiciel.games.minetest.*;
@@ -109,7 +110,7 @@ public class MazePersistWorldEdit {
}
public LabyModel parseInputStream(String pFormat, InputStream pIn) throws IOException {
public LabyLayers parseInputStream(String pFormat, InputStream pIn) throws IOException {
// TODO using WorldEditGenerator
if ((pFormat == null) || (pFormat.equals("we"))) {
// DataInputStream in = new DataInputStream(pIn);
@@ -121,18 +122,21 @@ public class MazePersistWorldEdit {
World world = reader.read();
// need to convert world into a LabyModel ...
// get level z = 0
Slice ground = world.getSlice(0);
if ( ground != null )
{
model = getModelFromSlice(ground);
model.setOnewaywall(true);
System.out.println(model);
LabyLayers layers = new LabyLayers();
if ( ! world.isEmpty()) {
for (int level = world.getMin(); level <= world.getMax(); level++) {
Slice ground = world.getSlice(level);
if (ground != null) {
model = getModelFromSlice(ground);
model.setOnewaywall(true);
layers.addLabyModel(level, model);
System.out.println(model);
} else {
System.err.println("no ground !");
}
}
}
else
{
System.err.println("no ground !");
}
return model;
return layers;
} else {
throw new IOException("Format " + pFormat + " Not yet implemented.");
}
@@ -149,24 +153,26 @@ public class MazePersistWorldEdit {
int up = rawRange.getMin();
short [][] t = new short[width][height];
int left = ground.getMin();
for ( int x = ground.getMin() ; x < ground.getMax() ; x ++)
{
// work on raws ...
Raw raw = ground.getRaw(new Integer(x));
if ( raw != null )
{
for ( int y = raw.getMin() ; y < raw.getMax(); y ++) {
// full closed place ... ( lazzy ... )
Node node = raw.getNode(y);
short move = LabyModel.EMPTY | 32;
if ( node != null ) {
move = 0;
if ( ! ground.isEmpty() ) {
int left = ground.getMin();
for (int x = ground.getMin(); x <= ground.getMax(); x++) {
// work on raws ...
Raw raw = ground.getRaw(new Integer(x));
if ( raw != null) {
if (!raw.isEmpty()) {
for (int y = raw.getMin(); y <= raw.getMax(); y++) {
// full closed place ... ( lazzy ... )
Node node = raw.getNode(y);
short move = LabyModel.EMPTY | 32;
if (node != null) {
move = 0;
}
int newx = x - left;
int newy = y - up;
System.out.println(" " + newx + " " + newy + " =" + move);
t[newx][newy] = move;
}
}
int newx = x - left;
int newy = y - up;
System.out.println( " " + newx + " " + newy + " =" + move );
t[newx][newy] = move;
}
}
}