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)
|
public void addLabyModel(int z, LabyModel model)
|
||||||
{
|
{
|
||||||
|
updateBounds(z);
|
||||||
layers.put(new Integer(z), model);
|
layers.put(new Integer(z), model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -799,7 +799,19 @@ implements StatusListener
|
|||||||
FileInputStream inputStream = null;
|
FileInputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(infile);
|
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) {
|
} catch (IOException io) {
|
||||||
io.printStackTrace(System.err);
|
io.printStackTrace(System.err);
|
||||||
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.artisanlogiciel.games.maze.persist;
|
package org.artisanlogiciel.games.maze.persist;
|
||||||
|
|
||||||
import org.artisanlogiciel.games.maze.Brick;
|
import org.artisanlogiciel.games.maze.Brick;
|
||||||
|
import org.artisanlogiciel.games.maze.LabyLayers;
|
||||||
import org.artisanlogiciel.games.maze.LabyModel;
|
import org.artisanlogiciel.games.maze.LabyModel;
|
||||||
import org.artisanlogiciel.games.minetest.*;
|
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
|
// TODO using WorldEditGenerator
|
||||||
if ((pFormat == null) || (pFormat.equals("we"))) {
|
if ((pFormat == null) || (pFormat.equals("we"))) {
|
||||||
// DataInputStream in = new DataInputStream(pIn);
|
// DataInputStream in = new DataInputStream(pIn);
|
||||||
@@ -121,18 +122,21 @@ public class MazePersistWorldEdit {
|
|||||||
World world = reader.read();
|
World world = reader.read();
|
||||||
// need to convert world into a LabyModel ...
|
// need to convert world into a LabyModel ...
|
||||||
// get level z = 0
|
// get level z = 0
|
||||||
Slice ground = world.getSlice(0);
|
LabyLayers layers = new LabyLayers();
|
||||||
if ( ground != null )
|
if ( ! world.isEmpty()) {
|
||||||
{
|
for (int level = world.getMin(); level <= world.getMax(); level++) {
|
||||||
|
Slice ground = world.getSlice(level);
|
||||||
|
if (ground != null) {
|
||||||
model = getModelFromSlice(ground);
|
model = getModelFromSlice(ground);
|
||||||
model.setOnewaywall(true);
|
model.setOnewaywall(true);
|
||||||
|
layers.addLabyModel(level, model);
|
||||||
System.out.println(model);
|
System.out.println(model);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
System.err.println("no ground !");
|
System.err.println("no ground !");
|
||||||
}
|
}
|
||||||
return model;
|
}
|
||||||
|
}
|
||||||
|
return layers;
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Format " + pFormat + " Not yet implemented.");
|
throw new IOException("Format " + pFormat + " Not yet implemented.");
|
||||||
}
|
}
|
||||||
@@ -149,27 +153,29 @@ public class MazePersistWorldEdit {
|
|||||||
int up = rawRange.getMin();
|
int up = rawRange.getMin();
|
||||||
|
|
||||||
short [][] t = new short[width][height];
|
short [][] t = new short[width][height];
|
||||||
|
if ( ! ground.isEmpty() ) {
|
||||||
int left = ground.getMin();
|
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 ...
|
// work on raws ...
|
||||||
Raw raw = ground.getRaw(new Integer(x));
|
Raw raw = ground.getRaw(new Integer(x));
|
||||||
if ( raw != null )
|
if ( raw != null) {
|
||||||
{
|
if (!raw.isEmpty()) {
|
||||||
for ( int y = raw.getMin() ; y < raw.getMax(); y ++) {
|
for (int y = raw.getMin(); y <= raw.getMax(); y++) {
|
||||||
// full closed place ... ( lazzy ... )
|
// full closed place ... ( lazzy ... )
|
||||||
Node node = raw.getNode(y);
|
Node node = raw.getNode(y);
|
||||||
short move = LabyModel.EMPTY | 32;
|
short move = LabyModel.EMPTY | 32;
|
||||||
if ( node != null ) {
|
if (node != null) {
|
||||||
move = 0;
|
move = 0;
|
||||||
}
|
}
|
||||||
int newx = x - left;
|
int newx = x - left;
|
||||||
int newy = y - up;
|
int newy = y - up;
|
||||||
System.out.println( " " + newx + " " + newy + " =" + move );
|
System.out.println(" " + newx + " " + newy + " =" + move);
|
||||||
t[newx][newy] = move;
|
t[newx][newy] = move;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
model = new LabyModel(width,height, t);
|
model = new LabyModel(width,height, t);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class Range {
|
|||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean updateBounds(int v)
|
protected boolean updateBounds(int v)
|
||||||
{
|
{
|
||||||
boolean update = false;
|
boolean update = false;
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public class Range {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return max - min;
|
return max - min + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ public class CharProvider {
|
|||||||
|
|
||||||
String input;
|
String input;
|
||||||
int current;
|
int current;
|
||||||
|
int last;
|
||||||
|
|
||||||
public CharProvider(String input) {
|
public CharProvider(String input) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
@@ -13,9 +14,16 @@ public class CharProvider {
|
|||||||
public char getNextchar()
|
public char getNextchar()
|
||||||
{
|
{
|
||||||
int i = current;
|
int i = current;
|
||||||
if ( input.length() > current) {
|
int max = input.length();
|
||||||
current++;
|
if ( max > current) {
|
||||||
return input.charAt(i);
|
char c = 0;
|
||||||
|
last = current;
|
||||||
|
while ( ( max > i ) && ( c = input.charAt(i) ) == ' ' )
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
current = i + 1;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -26,7 +34,7 @@ public class CharProvider {
|
|||||||
public void pushBackChar(char c)
|
public void pushBackChar(char c)
|
||||||
{
|
{
|
||||||
System.out.print('*');
|
System.out.print('*');
|
||||||
current--;
|
current = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user