read a .we minetest schema

- use ground has maze walls
This commit is contained in:
philippe lhardy
2020-11-04 22:12:17 +01:00
parent 6402766371
commit 52a2d3f1e3
13 changed files with 430 additions and 16 deletions

View File

@@ -2,9 +2,8 @@ package org.artisanlogiciel.games.maze.persist;
import org.artisanlogiciel.games.maze.Brick;
import org.artisanlogiciel.games.maze.LabyModel;
import org.artisanlogiciel.games.minetest.Material;
import org.artisanlogiciel.games.minetest.Node;
import org.artisanlogiciel.games.minetest.WorlEditGenerator;
import org.artisanlogiciel.games.minetest.*;
import java.io.*;
import static org.artisanlogiciel.games.minetest.Material.GRASS_MATERIAL;
@@ -18,6 +17,10 @@ public class MazePersistWorldEdit {
this.model = model;
}
public MazePersistWorldEdit() {
//
}
void addNode(Node node)
{
if (node != null )
@@ -110,13 +113,71 @@ public class MazePersistWorldEdit {
// TODO using WorldEditGenerator
if ((pFormat == null) || (pFormat.equals("we"))) {
// DataInputStream in = new DataInputStream(pIn);
throw new IOException("Format " + pFormat + " Not yet implemented.");
// should be at end of stream ? Not necessary can stream multiple
// labs ( or tiling ).
WorldEditReader reader = new WorldEditReader(pIn);
// skip header "5.return " hacky way ...
byte[] b = new byte[9];
pIn.read(b);
// System.out.println(new String(b));
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);
System.out.println(model);
}
else
{
System.err.println("no ground !");
}
return model;
} else {
throw new IOException("Format " + pFormat + " Not yet implemented.");
}
}
private LabyModel getModelFromSlice(Slice ground) {
// TODO
if ( ! ground.isEmpty() )
{
int width = ground.getRangeSize();
Range rawRange = ground.getRawRange();
int height = rawRange.getRangeSize();
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;
}
int newx = x - left;
int newy = y - up;
System.out.println( " " + newx + " " + newy + " =" + move );
t[newx][newy] = move;
}
}
}
model = new LabyModel(width,height, t);
return model;
}
else
{
System.out.println("empty ground");
}
return null;
}
}