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

@@ -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);