minetest worledit .we format export
- harcoded generation of lua content of .we export - export something, but not yet correct ( walls are points ... )
This commit is contained in:
80
java/org/artisanlogiciel/games/maze/DrawingGenerator.java
Normal file
80
java/org/artisanlogiciel/games/maze/DrawingGenerator.java
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package org.artisanlogiciel.games.maze;
|
||||||
|
|
||||||
|
import org.artisanlogiciel.graphics.Drawing;
|
||||||
|
import org.artisanlogiciel.graphics.DrawingLine;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingGenerator {
|
||||||
|
|
||||||
|
LabyModel model;
|
||||||
|
|
||||||
|
public DrawingGenerator(LabyModel model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addWallInDrawing(int pX, int pY, Drawing d) {
|
||||||
|
short walls = model.getWalls(pX, pY);
|
||||||
|
short wdrawn = 0;
|
||||||
|
// todo
|
||||||
|
int w = 2;
|
||||||
|
int h = 2;
|
||||||
|
int ox = 0;
|
||||||
|
int oy = 0;
|
||||||
|
|
||||||
|
int x = ox + (int) (pX * w);
|
||||||
|
int y = oy + (int) (pY * h);
|
||||||
|
DrawingLine dl = new DrawingLine();
|
||||||
|
// order matters since all points are linked
|
||||||
|
if ((pY == 0) && LabyModel.isFlagSet(walls, Brick.UP)) {
|
||||||
|
dl.addPoint(new Point(x, y));
|
||||||
|
dl.addPoint(new Point(x + (int) w, y));
|
||||||
|
wdrawn |= Brick.UP;
|
||||||
|
}
|
||||||
|
if (LabyModel.isFlagSet(walls, Brick.RIGHT)) {
|
||||||
|
if (!LabyModel.isFlagSet(wdrawn, Brick.UP)) {
|
||||||
|
dl.addPoint(new Point(x + (int) w, y));
|
||||||
|
}
|
||||||
|
dl.addPoint(new Point(x + (int) w, y + (int) h));
|
||||||
|
wdrawn |= Brick.RIGHT;
|
||||||
|
}
|
||||||
|
if (LabyModel.isFlagSet(walls, Brick.DOWN)) {
|
||||||
|
if (!LabyModel.isFlagSet(wdrawn, Brick.RIGHT)) {
|
||||||
|
if (wdrawn != 0) {
|
||||||
|
d.addLine(dl);
|
||||||
|
dl = new DrawingLine();
|
||||||
|
}
|
||||||
|
dl.addPoint(new Point(x + (int) w, y + (int) h));
|
||||||
|
}
|
||||||
|
dl.addPoint(new Point(x, y + (int) h));
|
||||||
|
wdrawn |= Brick.DOWN;
|
||||||
|
}
|
||||||
|
if ((pX == 0) && LabyModel.isFlagSet(walls, Brick.LEFT)) {
|
||||||
|
if (!LabyModel.isFlagSet(wdrawn, Brick.DOWN)) {
|
||||||
|
if (wdrawn != 0) {
|
||||||
|
d.addLine(dl);
|
||||||
|
dl = new DrawingLine();
|
||||||
|
}
|
||||||
|
dl.addPoint(new Point(x, y + (int) h));
|
||||||
|
}
|
||||||
|
dl.addPoint(new Point(x, y));
|
||||||
|
wdrawn |= Brick.LEFT;
|
||||||
|
}
|
||||||
|
if (wdrawn != 0) {
|
||||||
|
d.addLine(dl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawing createDrawing() {
|
||||||
|
Drawing d = new Drawing();
|
||||||
|
{
|
||||||
|
// draw all walls within clip bounds horiz first then lines
|
||||||
|
for (int y = 0; y < model.getHeight(); y++) {
|
||||||
|
for (int x = 0; x < model.getWidth(); x++) {
|
||||||
|
addWallInDrawing(x, y, d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,36 +1,33 @@
|
|||||||
package org.artisanlogiciel.games.maze.gui;
|
package org.artisanlogiciel.games.maze.gui;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import org.artisanlogiciel.games.maze.DrawingGenerator;
|
||||||
import java.awt.image.BufferedImage;
|
import org.artisanlogiciel.games.maze.LabyModel;
|
||||||
import java.awt.Container;
|
import org.artisanlogiciel.games.maze.MazeParams;
|
||||||
import java.awt.FlowLayout;
|
import org.artisanlogiciel.games.maze.MazeParamsFixed;
|
||||||
import java.awt.Graphics;
|
import org.artisanlogiciel.games.maze.persist.MazePeristWorldEdit;
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.event.ChangeEvent;
|
|
||||||
import javax.swing.event.ChangeListener;
|
|
||||||
|
|
||||||
import org.artisanlogiciel.games.maze.*;
|
|
||||||
import org.artisanlogiciel.games.maze.persist.MazePersistRaw;
|
import org.artisanlogiciel.games.maze.persist.MazePersistRaw;
|
||||||
import org.artisanlogiciel.games.maze.solve.SolvingModel;
|
import org.artisanlogiciel.games.maze.solve.SolvingModel;
|
||||||
import org.artisanlogiciel.games.stl.Maze3dParams;
|
import org.artisanlogiciel.games.stl.Maze3dParams;
|
||||||
import org.artisanlogiciel.games.stl.Wall3dStream;
|
import org.artisanlogiciel.games.stl.Wall3dStream;
|
||||||
|
import org.artisanlogiciel.graphics.Drawing;
|
||||||
|
import org.artisanlogiciel.graphics.SvgWriter;
|
||||||
import org.artisanlogiciel.osm.OsmReader;
|
import org.artisanlogiciel.osm.OsmReader;
|
||||||
import org.artisanlogiciel.osm.convert.OsmToDrawing;
|
import org.artisanlogiciel.osm.convert.OsmToDrawing;
|
||||||
import org.artisanlogiciel.util.UTF8Control;
|
import org.artisanlogiciel.util.UTF8Control;
|
||||||
|
|
||||||
import org.artisanlogiciel.graphics.Drawing;
|
import javax.imageio.ImageIO;
|
||||||
import org.artisanlogiciel.graphics.DrawingLine;
|
import javax.swing.*;
|
||||||
import org.artisanlogiciel.graphics.SvgWriter;
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display is Main JFrame for this tool
|
* Display is Main JFrame for this tool
|
||||||
@@ -176,72 +173,7 @@ implements StatusListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addWallInDrawing(int pX, int pY, Drawing d) {
|
|
||||||
short walls = model.getWalls(pX, pY);
|
|
||||||
short wdrawn = 0;
|
|
||||||
// todo
|
|
||||||
int w = 2;
|
|
||||||
int h = 2;
|
|
||||||
int ox = 0;
|
|
||||||
int oy = 0;
|
|
||||||
|
|
||||||
int x = ox + (int) (pX * w);
|
|
||||||
int y = oy + (int) (pY * h);
|
|
||||||
DrawingLine dl = new DrawingLine();
|
|
||||||
// order matters since all points are linked
|
|
||||||
if ((pY == 0) && LabyModel.isFlagSet(walls, Brick.UP)) {
|
|
||||||
dl.addPoint(new Point(x, y));
|
|
||||||
dl.addPoint(new Point(x + (int) w, y));
|
|
||||||
wdrawn |= Brick.UP;
|
|
||||||
}
|
|
||||||
if (LabyModel.isFlagSet(walls, Brick.RIGHT)) {
|
|
||||||
if (!LabyModel.isFlagSet(wdrawn, Brick.UP)) {
|
|
||||||
dl.addPoint(new Point(x + (int) w, y));
|
|
||||||
}
|
|
||||||
dl.addPoint(new Point(x + (int) w, y + (int) h));
|
|
||||||
wdrawn |= Brick.RIGHT;
|
|
||||||
}
|
|
||||||
if (LabyModel.isFlagSet(walls, Brick.DOWN)) {
|
|
||||||
if (!LabyModel.isFlagSet(wdrawn, Brick.RIGHT)) {
|
|
||||||
if (wdrawn != 0) {
|
|
||||||
d.addLine(dl);
|
|
||||||
dl = new DrawingLine();
|
|
||||||
}
|
|
||||||
dl.addPoint(new Point(x + (int) w, y + (int) h));
|
|
||||||
}
|
|
||||||
dl.addPoint(new Point(x, y + (int) h));
|
|
||||||
wdrawn |= Brick.DOWN;
|
|
||||||
}
|
|
||||||
if ((pX == 0) && LabyModel.isFlagSet(walls, Brick.LEFT)) {
|
|
||||||
if (!LabyModel.isFlagSet(wdrawn, Brick.DOWN)) {
|
|
||||||
if (wdrawn != 0) {
|
|
||||||
d.addLine(dl);
|
|
||||||
dl = new DrawingLine();
|
|
||||||
}
|
|
||||||
dl.addPoint(new Point(x, y + (int) h));
|
|
||||||
}
|
|
||||||
dl.addPoint(new Point(x, y));
|
|
||||||
wdrawn |= Brick.LEFT;
|
|
||||||
}
|
|
||||||
if (wdrawn != 0) {
|
|
||||||
d.addLine(dl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Drawing createDrawing() {
|
|
||||||
Drawing d = new Drawing();
|
|
||||||
{
|
|
||||||
short walls;
|
|
||||||
|
|
||||||
// draw all walls within clip bounds horiz first then lines
|
|
||||||
for (int y = 0; y < model.getHeight(); y++) {
|
|
||||||
for (int x = 0; x < model.getWidth(); x++) {
|
|
||||||
addWallInDrawing(x, y, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
// to allow to log / write somewher into screen...
|
// to allow to log / write somewher into screen...
|
||||||
void writeSentence(String pSentence) {
|
void writeSentence(String pSentence) {
|
||||||
@@ -253,6 +185,10 @@ implements StatusListener
|
|||||||
System.err.println(pError);
|
System.err.println(pError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Drawing createDrawing() {
|
||||||
|
return new DrawingGenerator(model).createDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
void saveImc() {
|
void saveImc() {
|
||||||
Drawing d = createDrawing();
|
Drawing d = createDrawing();
|
||||||
|
|
||||||
@@ -442,67 +378,69 @@ implements StatusListener
|
|||||||
|
|
||||||
private JMenu createSavingMenu() {
|
private JMenu createSavingMenu() {
|
||||||
final JTextField saveName = new JTextField("newlaby");
|
final JTextField saveName = new JTextField("newlaby");
|
||||||
final JButton savePngButton = new JButton(labels.getString("save") + " png");
|
|
||||||
Action savePngAction = new AbstractAction() {
|
final JButton savePngButton = newSaveButton( "png",
|
||||||
public void actionPerformed(ActionEvent evt) {
|
new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
//
|
||||||
addStatus("save png");
|
addStatus("save png");
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
savePng();
|
savePng();
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
savePngButton.addActionListener(savePngAction);
|
|
||||||
final JButton saveSvgButton = new JButton(labels.getString("save") + " svg");
|
final JButton saveSvgButton = newSaveButton("svg",
|
||||||
Action saveSvgAction = new AbstractAction() {
|
new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
writeSentence("save svg");
|
writeSentence("save svg");
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
saveSvg();
|
saveSvg();
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
saveSvgButton.addActionListener(saveSvgAction);
|
|
||||||
final JButton saveButton = new JButton(labels.getString("save") + " raw");
|
final JButton saveButton = newSaveButton("raw",
|
||||||
Action saveAction = new AbstractAction() {
|
new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
|
||||||
addStatus("save");
|
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
MazeParamsFixed p = (MazeParamsFixed) params;
|
MazeParamsFixed p = (MazeParamsFixed) params;
|
||||||
save(p, model);
|
save(p, model);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
saveButton.addActionListener(saveAction);
|
|
||||||
final JButton saveImcButton = new JButton(labels.getString("save") + " imc");
|
|
||||||
Action saveImcAction = new AbstractAction() {
|
Action saveImcAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
|
||||||
addStatus("save imc");
|
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
saveImc();
|
saveImc();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
saveImcButton.addActionListener(saveImcAction);
|
final JButton saveImcButton = newSaveButton("imc", saveImcAction);
|
||||||
final JButton saveStlButton = new JButton(labels.getString("save") + " stl");
|
|
||||||
Action saveStlAction = new AbstractAction() {
|
Action saveStlAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
//
|
||||||
addStatus("save stl");
|
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
MazeParamsFixed p = (MazeParamsFixed) params;
|
MazeParamsFixed p = (MazeParamsFixed) params;
|
||||||
saveStl(p, model,stlsettings.createParams());
|
saveStl(p, model,stlsettings.createParams());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
saveStlButton.addActionListener(saveStlAction);
|
final JButton saveStlButton = newSaveButton("stl", saveStlAction);
|
||||||
final JButton saveTextButton = new JButton(labels.getString("save") + " txt");
|
|
||||||
Action saveTextAction = new AbstractAction() {
|
Action saveTextAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
//
|
//
|
||||||
addStatus("save txt");
|
|
||||||
setMazeName(saveName.getText());
|
setMazeName(saveName.getText());
|
||||||
saveText();
|
saveText();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
saveTextButton.addActionListener(saveTextAction);
|
final JButton saveTextButton = newSaveButton("txt", saveTextAction);
|
||||||
|
|
||||||
|
final JButton saveWorleEditButton = newSaveButton( "we",
|
||||||
|
new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
setMazeName(saveName.getText());
|
||||||
|
saveWorldEdit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
stlsettings = new Maze3dSettings(new Maze3dParams());
|
stlsettings = new Maze3dSettings(new Maze3dParams());
|
||||||
|
|
||||||
@@ -515,11 +453,18 @@ implements StatusListener
|
|||||||
saveMenu.add(saveStlButton);
|
saveMenu.add(saveStlButton);
|
||||||
saveMenu.add(saveImcButton);
|
saveMenu.add(saveImcButton);
|
||||||
saveMenu.add(saveTextButton);
|
saveMenu.add(saveTextButton);
|
||||||
|
saveMenu.add(saveWorleEditButton);
|
||||||
|
|
||||||
return saveMenu;
|
return saveMenu;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JButton newSaveButton(String format, Action action) {
|
||||||
|
final JButton saveTextButton = new JButton(labels.getString("save") + " " + format);
|
||||||
|
saveTextButton.addActionListener(action);
|
||||||
|
return saveTextButton;
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel createResolveQuitBar() {
|
private JPanel createResolveQuitBar() {
|
||||||
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
||||||
|
|
||||||
@@ -829,10 +774,28 @@ implements StatusListener
|
|||||||
Display display = new Display(model, W, H, params);
|
Display display = new Display(model, W, H, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveWorldEdit() {
|
||||||
|
File outfile = getFileForExtension("we");
|
||||||
|
if (!outfile.exists()) {
|
||||||
|
addStatus("Saving we to " + outfile + " ...");
|
||||||
|
try {
|
||||||
|
FileOutputStream out = new FileOutputStream(outfile);
|
||||||
|
new MazePeristWorldEdit(model).streamOut("we", out);
|
||||||
|
out.close();
|
||||||
|
addStatus("... Done.");
|
||||||
|
} catch (IOException io) {
|
||||||
|
io.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addStatus("we file " + outfile + " already exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void saveStl(MazeParamsFixed params, LabyModel model, Maze3dParams wallparams) {
|
public void saveStl(MazeParamsFixed params, LabyModel model, Maze3dParams wallparams) {
|
||||||
File outfile = getFileForExtension("stl");
|
File outfile = getFileForExtension("stl");
|
||||||
if (!outfile.exists()) {
|
if (!outfile.exists()) {
|
||||||
addStatus("Saving to " + outfile + " ...");
|
addStatus("Saving stl to " + outfile + " ...");
|
||||||
try {
|
try {
|
||||||
FileOutputStream out = new FileOutputStream(outfile);
|
FileOutputStream out = new FileOutputStream(outfile);
|
||||||
new Wall3dStream(params.getName(), model, out, wallparams).stream();
|
new Wall3dStream(params.getName(), model, out, wallparams).stream();
|
||||||
@@ -842,7 +805,7 @@ implements StatusListener
|
|||||||
io.printStackTrace(System.err);
|
io.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addStatus("" + outfile + " already exists");
|
addStatus("stl file " + outfile + " already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package org.artisanlogiciel.games.maze.persist;
|
||||||
|
|
||||||
|
import org.artisanlogiciel.games.maze.Brick;
|
||||||
|
import org.artisanlogiciel.games.maze.LabyModel;
|
||||||
|
import org.artisanlogiciel.games.minetest.Node;
|
||||||
|
import org.artisanlogiciel.games.minetest.WorlEditGenerator;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class MazePeristWorldEdit {
|
||||||
|
|
||||||
|
private LabyModel model;
|
||||||
|
private WorlEditGenerator generator;
|
||||||
|
private static final String GRASS_MATERIAL = "default:dirt_with_grass";
|
||||||
|
|
||||||
|
public MazePeristWorldEdit(LabyModel model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addNode(Node node)
|
||||||
|
{
|
||||||
|
if (node != null )
|
||||||
|
{
|
||||||
|
generator.writeNode(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addWalls(int pX, int pY) {
|
||||||
|
short walls = model.getWalls(pX, pY);
|
||||||
|
short wdrawn = 0;
|
||||||
|
// todo
|
||||||
|
int w = 2;
|
||||||
|
int h = 2;
|
||||||
|
int ox = 0;
|
||||||
|
int oy = 0;
|
||||||
|
int z = 0;
|
||||||
|
|
||||||
|
String material = GRASS_MATERIAL;
|
||||||
|
|
||||||
|
int x = ox + (int) (pX * w);
|
||||||
|
int y = oy + (int) (pY * h);
|
||||||
|
|
||||||
|
// copied from drawing, where order did matter, might not be the case here...
|
||||||
|
if ((pY == 0) && LabyModel.isFlagSet(walls, Brick.UP)) {
|
||||||
|
addNode(new Node(x,y,z,material));
|
||||||
|
addNode(new Node(x + (int) w,y,z,material));
|
||||||
|
wdrawn |= Brick.UP;
|
||||||
|
}
|
||||||
|
if (LabyModel.isFlagSet(walls, Brick.RIGHT)) {
|
||||||
|
if (!LabyModel.isFlagSet(wdrawn, Brick.UP)) {
|
||||||
|
addNode(new Node(x + (int) w, y, 0, material));
|
||||||
|
}
|
||||||
|
addNode(new Node(x + (int) w, y + (int) h, z, material));
|
||||||
|
wdrawn |= Brick.RIGHT;
|
||||||
|
}
|
||||||
|
if (LabyModel.isFlagSet(walls, Brick.DOWN)) {
|
||||||
|
if (!LabyModel.isFlagSet(wdrawn, Brick.RIGHT)) {
|
||||||
|
addNode(new Node(x + (int) w, y + (int) h, z, material));
|
||||||
|
}
|
||||||
|
addNode(new Node(x, y + (int) h, z, material));
|
||||||
|
wdrawn |= Brick.DOWN;
|
||||||
|
}
|
||||||
|
if ((pX == 0) && LabyModel.isFlagSet(walls, Brick.LEFT)) {
|
||||||
|
if (!LabyModel.isFlagSet(wdrawn, Brick.DOWN)) {
|
||||||
|
addNode(new Node(x, y + (int) h, z, material));
|
||||||
|
}
|
||||||
|
addNode(new Node(x, y, z, material));
|
||||||
|
wdrawn |= Brick.LEFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void streamOut(String pFormat, OutputStream pOut) throws IOException {
|
||||||
|
// WIP using WorldEditGenerator
|
||||||
|
if ((pFormat == null) || (pFormat.equals("we"))) {
|
||||||
|
|
||||||
|
Node refNode = new Node(0,0,0,"default:dirt_with_grass");
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
generator = new WorlEditGenerator(builder,refNode);
|
||||||
|
generator.writeStart();
|
||||||
|
// first raw format, not smart.
|
||||||
|
DataOutputStream dataOut = new DataOutputStream(pOut);
|
||||||
|
dataOut.flush();
|
||||||
|
for (int y = 0; y < model.getHeight(); y++) {
|
||||||
|
for (int x = 0; x < model.getWidth(); x++) {
|
||||||
|
addWalls(x,y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
generator.writeEnd();
|
||||||
|
dataOut.write(builder.toString().getBytes());
|
||||||
|
dataOut.flush();
|
||||||
|
} else {
|
||||||
|
throw new IOException("Format " + pFormat + " Not yet implemented.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public LabyModel parseInputStream(String pFormat, InputStream pIn) throws IOException {
|
||||||
|
// 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 ).
|
||||||
|
} else {
|
||||||
|
throw new IOException("Format " + pFormat + " Not yet implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,31 @@
|
|||||||
package org.artisanlogiciel.games.minetest;
|
package org.artisanlogiciel.games.minetest;
|
||||||
|
|
||||||
public class Node {
|
public class Node {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
String material;
|
||||||
|
|
||||||
|
public Node(int x, int y, int z, String material) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.material = material;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getZ() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaterial() {
|
||||||
|
return material;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package org.artisanlogiciel.games.minetest;
|
||||||
|
|
||||||
|
public class WorlEditGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
Node refNode;
|
||||||
|
StringBuilder luaNode;
|
||||||
|
boolean start = true;
|
||||||
|
|
||||||
|
public WorlEditGenerator(StringBuilder luaNode, Node refNode) {
|
||||||
|
this.luaNode = luaNode;
|
||||||
|
start = true;
|
||||||
|
this.refNode = refNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addIntMember(String name, int value)
|
||||||
|
{
|
||||||
|
addSeparator();
|
||||||
|
addMember(name);
|
||||||
|
luaNode.append(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStringMember( String name, String value)
|
||||||
|
{
|
||||||
|
addSeparator();
|
||||||
|
addMember(name);
|
||||||
|
luaNode.append('"').append(value).append('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMember(String name) {
|
||||||
|
luaNode.append("[\"").append(name).append("\"]=");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSeparator() {
|
||||||
|
if ( ! start)
|
||||||
|
{
|
||||||
|
luaNode.append(",");
|
||||||
|
}
|
||||||
|
start = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeStart()
|
||||||
|
{
|
||||||
|
luaNode.append("5.return {");
|
||||||
|
}
|
||||||
|
public void writeNode(Node node)
|
||||||
|
{
|
||||||
|
addSeparator();
|
||||||
|
luaNode.append("{");
|
||||||
|
start=true;
|
||||||
|
addIntMember("x", node.getX() - refNode.getX());
|
||||||
|
addIntMember("y", node.getY() - refNode.getY());
|
||||||
|
addIntMember("z", node.getZ() - refNode.getZ());
|
||||||
|
addStringMember("name",node.getMaterial());
|
||||||
|
luaNode.append("}");
|
||||||
|
start=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeEnd()
|
||||||
|
{
|
||||||
|
luaNode.append("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user