else if(e.getSource() == save)
{
String filename = getFile("Save");
Node mapNode = new Node("map");
mapNode.addSubnode("width",""+lvlWidth);
mapNode.addSubnode("height",""+lvlHeight);
mapNode.addSubnode("name",name.getText());
for(int x = 0; x < lvlWidth; x++)
for (int y = 0; y < lvlHeight; y++)
mapNode.addSubnode( tiles[x][y].asNode() );
try
{
OutputStream os = new FileOutputStream(filename);
mapNode.tryWriteOn(os);
os.flush();
os.close();
}
catch (Exception ex) { }
JOptionPane.showMessageDialog(this, "Save complete", "Done", JOptionPane.PLAIN_MESSAGE);
}
else if(e.getSource() == load)
{
try{
String filename = getFile("Load");
Node mapNode = Node.parseFrom(new FileInputStream(filename));
name.setText(mapNode.contentOf("name"));
int w = new Integer( mapNode.contentOf("width"));
int h = new Integer( mapNode.contentOf("height"));
resizeMap(w,h,-1);
for(Node tileNode: mapNode.subnodes("tile"))
{
Tile t = Tile.fromNode(tileNode);
tiles[t.getX()][t.getY()] = t;
}