Skip to content

Commit

Permalink
map editor loader
Browse files Browse the repository at this point in the history
  • Loading branch information
hameelas committed Feb 28, 2013
1 parent 70dad80 commit baf9ca4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/javachallenge/graphics/MapEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

import javax.swing.ImageIcon;

import javachallenge.common.BlockType;
import javachallenge.common.Point;
import javachallenge.graphics.components.FileChooser;
Expand Down Expand Up @@ -68,7 +71,7 @@ public void addSideBar() {
addBottomBar();
add (sidebar = new Panel (ColorMaker.shadedPanelBack));
sidebar.setLayout(new FlowLayout());
sidebar.add(new FileChooser.FileChooserButton("save", false, "Choose target", "data/maps/", "map", "Map files") {
sidebar.add(new FileChooser.FileChooserButton("save", false, "Choose target", "data/maps/", "txt", "Map files") {
{ setForeground(ColorMaker.fieldBackground); }
@Override
public void onAccept(String filename) {
Expand All @@ -81,6 +84,43 @@ public void onAccept(String filename) {
e.printStackTrace();
}
}
@Override
public void onEnter() {
setForeground(ColorMaker.white);
}
@Override
public void onExit() {
setForeground(ColorMaker.fieldBackground);
}
});
sidebar.add(new FileChooser.FileChooserButton("load", true, "Choose path", "data/maps/", "txt", "Map files") {
{ setForeground(ColorMaker.fieldBackground); }
@Override
public void onAccept(String filename) {
try {
Map map = Map.load(filename);
for (int i = 0; i < map.getWid(); i++)
for (int j = 0; j < map.getHei(); j++) {
System.err.println(map.getBlockType(new Point(i, j)));
getMapPanel().getMap().setBlockType(new Point(i, j), map.getBlockType(new Point(i, j)));

mapPanel.setBlock(i, j, map.getBlockType(new Point(i, j)).ordinal());
}
System.err.println("Map loaded Successfully");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onEnter() {
setForeground(ColorMaker.white);
}
@Override
public void onExit() {
setForeground(ColorMaker.fieldBackground);
}
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/javachallenge/graphics/components/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public Sprite getBrush() {
public Map getMap() {
return map;
}

public Sprite[][] getBlocks() {
return blocks;
}

public void setMap(Map map) {
this.map = map;
Expand Down

0 comments on commit baf9ca4

Please sign in to comment.