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:
@@ -15,6 +15,7 @@ extends Range
|
||||
}
|
||||
public void addLabyModel(int z, LabyModel model)
|
||||
{
|
||||
updateBounds(z);
|
||||
layers.put(new Integer(z), model);
|
||||
}
|
||||
|
||||
|
||||
@@ -799,7 +799,19 @@ implements StatusListener
|
||||
FileInputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(infile);
|
||||
setModel(new MazePersistWorldEdit().parseInputStream("we",inputStream));
|
||||
LabyLayers newLayers = new MazePersistWorldEdit().parseInputStream("we",inputStream);
|
||||
if ( ! newLayers.isEmpty()) {
|
||||
int l = layer;
|
||||
for (int i = newLayers.getMin(); i <= newLayers.getMax(); i++) {
|
||||
LabyModel m = newLayers.getLayer(i);
|
||||
if (m != null) {
|
||||
System.out.println("add layer " + l);
|
||||
layers.addLabyModel(l, m);
|
||||
l++;
|
||||
}
|
||||
}
|
||||
setModel(layers.getLayer(layer));
|
||||
}
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace(System.err);
|
||||
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
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
|
||||
{
|
||||
} else {
|
||||
System.err.println("no ground !");
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return layers;
|
||||
} else {
|
||||
throw new IOException("Format " + pFormat + " Not yet implemented.");
|
||||
}
|
||||
@@ -149,27 +153,29 @@ public class MazePersistWorldEdit {
|
||||
int up = rawRange.getMin();
|
||||
|
||||
short [][] t = new short[width][height];
|
||||
if ( ! ground.isEmpty() ) {
|
||||
int left = ground.getMin();
|
||||
for ( int x = ground.getMin() ; x < ground.getMax() ; x ++)
|
||||
{
|
||||
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 ++) {
|
||||
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 ) {
|
||||
if (node != null) {
|
||||
move = 0;
|
||||
}
|
||||
int newx = x - left;
|
||||
int newy = y - up;
|
||||
System.out.println( " " + newx + " " + newy + " =" + move );
|
||||
System.out.println(" " + newx + " " + newy + " =" + move);
|
||||
t[newx][newy] = move;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
model = new LabyModel(width,height, t);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Range {
|
||||
return update;
|
||||
}
|
||||
|
||||
boolean updateBounds(int v)
|
||||
protected boolean updateBounds(int v)
|
||||
{
|
||||
boolean update = false;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Range {
|
||||
}
|
||||
else
|
||||
{
|
||||
return max - min;
|
||||
return max - min + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ public class CharProvider {
|
||||
|
||||
String input;
|
||||
int current;
|
||||
int last;
|
||||
|
||||
public CharProvider(String input) {
|
||||
this.input = input;
|
||||
@@ -13,9 +14,16 @@ public class CharProvider {
|
||||
public char getNextchar()
|
||||
{
|
||||
int i = current;
|
||||
if ( input.length() > current) {
|
||||
current++;
|
||||
return input.charAt(i);
|
||||
int max = input.length();
|
||||
if ( max > current) {
|
||||
char c = 0;
|
||||
last = current;
|
||||
while ( ( max > i ) && ( c = input.charAt(i) ) == ' ' )
|
||||
{
|
||||
i++;
|
||||
}
|
||||
current = i + 1;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -26,7 +34,7 @@ public class CharProvider {
|
||||
public void pushBackChar(char c)
|
||||
{
|
||||
System.out.print('*');
|
||||
current--;
|
||||
current = last;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user