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:
@@ -1,36 +1,33 @@
|
||||
package org.artisanlogiciel.games.maze.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.Container;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Graphics;
|
||||
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.DrawingGenerator;
|
||||
import org.artisanlogiciel.games.maze.LabyModel;
|
||||
import org.artisanlogiciel.games.maze.MazeParams;
|
||||
import org.artisanlogiciel.games.maze.MazeParamsFixed;
|
||||
import org.artisanlogiciel.games.maze.persist.MazePeristWorldEdit;
|
||||
import org.artisanlogiciel.games.maze.persist.MazePersistRaw;
|
||||
import org.artisanlogiciel.games.maze.solve.SolvingModel;
|
||||
import org.artisanlogiciel.games.stl.Maze3dParams;
|
||||
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.convert.OsmToDrawing;
|
||||
import org.artisanlogiciel.util.UTF8Control;
|
||||
|
||||
import org.artisanlogiciel.graphics.Drawing;
|
||||
import org.artisanlogiciel.graphics.DrawingLine;
|
||||
import org.artisanlogiciel.graphics.SvgWriter;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
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
|
||||
@@ -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...
|
||||
void writeSentence(String pSentence) {
|
||||
@@ -253,6 +185,10 @@ implements StatusListener
|
||||
System.err.println(pError);
|
||||
}
|
||||
|
||||
public Drawing createDrawing() {
|
||||
return new DrawingGenerator(model).createDrawing();
|
||||
}
|
||||
|
||||
void saveImc() {
|
||||
Drawing d = createDrawing();
|
||||
|
||||
@@ -442,67 +378,69 @@ implements StatusListener
|
||||
|
||||
private JMenu createSavingMenu() {
|
||||
final JTextField saveName = new JTextField("newlaby");
|
||||
final JButton savePngButton = new JButton(labels.getString("save") + " png");
|
||||
Action savePngAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
|
||||
final JButton savePngButton = newSaveButton( "png",
|
||||
new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
addStatus("save png");
|
||||
setMazeName(saveName.getText());
|
||||
savePng();
|
||||
}
|
||||
};
|
||||
savePngButton.addActionListener(savePngAction);
|
||||
final JButton saveSvgButton = new JButton(labels.getString("save") + " svg");
|
||||
Action saveSvgAction = new AbstractAction() {
|
||||
addStatus("save png");
|
||||
setMazeName(saveName.getText());
|
||||
savePng();
|
||||
}
|
||||
});
|
||||
|
||||
final JButton saveSvgButton = newSaveButton("svg",
|
||||
new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
writeSentence("save svg");
|
||||
setMazeName(saveName.getText());
|
||||
saveSvg();
|
||||
}
|
||||
};
|
||||
saveSvgButton.addActionListener(saveSvgAction);
|
||||
final JButton saveButton = new JButton(labels.getString("save") + " raw");
|
||||
Action saveAction = new AbstractAction() {
|
||||
});
|
||||
|
||||
final JButton saveButton = newSaveButton("raw",
|
||||
new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
addStatus("save");
|
||||
setMazeName(saveName.getText());
|
||||
MazeParamsFixed p = (MazeParamsFixed) params;
|
||||
save(p, model);
|
||||
}
|
||||
};
|
||||
saveButton.addActionListener(saveAction);
|
||||
final JButton saveImcButton = new JButton(labels.getString("save") + " imc");
|
||||
});
|
||||
|
||||
Action saveImcAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
addStatus("save imc");
|
||||
setMazeName(saveName.getText());
|
||||
saveImc();
|
||||
}
|
||||
};
|
||||
saveImcButton.addActionListener(saveImcAction);
|
||||
final JButton saveStlButton = new JButton(labels.getString("save") + " stl");
|
||||
final JButton saveImcButton = newSaveButton("imc", saveImcAction);
|
||||
|
||||
Action saveStlAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
addStatus("save stl");
|
||||
setMazeName(saveName.getText());
|
||||
MazeParamsFixed p = (MazeParamsFixed) params;
|
||||
saveStl(p, model,stlsettings.createParams());
|
||||
}
|
||||
};
|
||||
saveStlButton.addActionListener(saveStlAction);
|
||||
final JButton saveTextButton = new JButton(labels.getString("save") + " txt");
|
||||
final JButton saveStlButton = newSaveButton("stl", saveStlAction);
|
||||
|
||||
Action saveTextAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
//
|
||||
addStatus("save txt");
|
||||
setMazeName(saveName.getText());
|
||||
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());
|
||||
|
||||
@@ -515,11 +453,18 @@ implements StatusListener
|
||||
saveMenu.add(saveStlButton);
|
||||
saveMenu.add(saveImcButton);
|
||||
saveMenu.add(saveTextButton);
|
||||
saveMenu.add(saveWorleEditButton);
|
||||
|
||||
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() {
|
||||
JPanel resolveQuitBar = new JPanel(new FlowLayout());
|
||||
|
||||
@@ -829,10 +774,28 @@ implements StatusListener
|
||||
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) {
|
||||
File outfile = getFileForExtension("stl");
|
||||
if (!outfile.exists()) {
|
||||
addStatus("Saving to " + outfile + " ...");
|
||||
addStatus("Saving stl to " + outfile + " ...");
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(outfile);
|
||||
new Wall3dStream(params.getName(), model, out, wallparams).stream();
|
||||
@@ -842,7 +805,7 @@ implements StatusListener
|
||||
io.printStackTrace(System.err);
|
||||
}
|
||||
} else {
|
||||
addStatus("" + outfile + " already exists");
|
||||
addStatus("stl file " + outfile + " already exists");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user