read a .we minetest schema
- use ground has maze walls
This commit is contained in:
@@ -35,6 +35,8 @@ public class LabyModel implements WallsProvider {
|
||||
public final static short RIGHT = Brick.RIGHT << FLAGLENGTH | DIRECTION | HORIZONTAL | POSITIVE;
|
||||
public final static short UP = Brick.UP << FLAGLENGTH | DIRECTION | VERTICAL | NEGATIVE;
|
||||
|
||||
public final static short EMPTY = LEFT | DOWN | RIGHT | UP ;
|
||||
|
||||
// flag when a wall should be open to access this for entry
|
||||
public final static short ENTRY = Brick.ENTRY << FLAGLENGTH;
|
||||
// flag when a wall should be open to access this for exit
|
||||
@@ -100,7 +102,7 @@ public class LabyModel implements WallsProvider {
|
||||
/**
|
||||
* construct LabyModel from an InputStream, yet only "raw" is supported
|
||||
**/
|
||||
public LabyModel(int width, int heigh, short [][] t) {
|
||||
public LabyModel(int width, int height, short [][] t) {
|
||||
random = null;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
@@ -368,11 +368,25 @@ implements StatusListener
|
||||
|
||||
}
|
||||
};
|
||||
JButton loadOsmButton = new JButton(labels.getString("load" ) + " Osm");
|
||||
loadOsmButton.addActionListener(loadOsmAction);
|
||||
loadMenu.add(newLoadButton("osm", loadOsmAction));
|
||||
|
||||
loadMenu.add(loadOsmButton);
|
||||
loadMenu.add(newLoadButton("we",
|
||||
new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
addStatus("load WoldEdit");
|
||||
|
||||
String filename = loadName.getText();
|
||||
|
||||
if ((filename.length() > 0)) {
|
||||
setMazeName(filename);
|
||||
loadWorldEdit(false);
|
||||
refresh();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
));
|
||||
return loadMenu;
|
||||
}
|
||||
|
||||
@@ -459,12 +473,20 @@ implements StatusListener
|
||||
|
||||
}
|
||||
|
||||
private JButton newSaveButton(String format, Action action) {
|
||||
final JButton saveTextButton = new JButton(labels.getString("save") + " " + format);
|
||||
private JButton newActionButton(String actionName, String format, Action action) {
|
||||
final JButton saveTextButton = new JButton(labels.getString(actionName) + " " + format);
|
||||
saveTextButton.addActionListener(action);
|
||||
return saveTextButton;
|
||||
}
|
||||
|
||||
private JButton newSaveButton(String format, Action action) {
|
||||
return newActionButton("save",format,action);
|
||||
}
|
||||
|
||||
private JButton newLoadButton(String format, Action action) {
|
||||
return newActionButton("load",format,action);
|
||||
}
|
||||
|
||||
private JPanel createResolveQuitBar() {
|
||||
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
||||
|
||||
@@ -759,6 +781,29 @@ implements StatusListener
|
||||
}
|
||||
}
|
||||
|
||||
private void loadWorldEdit(boolean add) {
|
||||
if ( maze != null ) {
|
||||
File infile = new File(params.getSaveDir(), params.getName() + ".we");
|
||||
FileInputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(infile);
|
||||
model = new MazePersistWorldEdit().parseInputStream("we",inputStream);
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace(System.err);
|
||||
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
// cleanup
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Exception any) {
|
||||
// don't care really
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JButton addDirection(final JPanel panel, final String direction, String key, Action goAction) {
|
||||
String actionName = "go" + direction;
|
||||
JButton button = new JButton(direction);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user