converted world type to enum

master
flying sheep 2013-04-05 23:32:13 +02:00
parent aa0fa3abb6
commit 6ecbd88f36
3 changed files with 32 additions and 12 deletions

View File

@ -25,10 +25,10 @@ public class Project extends JPanel {
public String seedText;
public Project(long seed, FinderWindow window) {
this(seed, window, "default");
this(seed, window, SaveLoader.Type.DEFAULT);
}
public Project(long seed, FinderWindow window, String type) {
public Project(long seed, FinderWindow window, SaveLoader.Type type) {
SaveLoader.genType = type;
saveLoaded = false;
//Enter seed data:
@ -42,7 +42,7 @@ public class Project extends JPanel {
minfo.repaint();
}
public Project(String seed, FinderWindow window, String type) {
public Project(String seed, FinderWindow window, SaveLoader.Type type) {
this(stringToLong(seed), window, type);
this.seedText = "Seed: \"" + seed + "\" (" + this.seed + ")";

View File

@ -10,7 +10,28 @@ import java.util.List;
import javax.swing.filechooser.FileFilter;
public class SaveLoader {
public static String genType = "default";
public static Type genType = Type.DEFAULT;
public enum Type {
DEFAULT("default"), FLAT("flat"), LARGE_BIOMES("largeBiomes");
private final String s;
Type(String s) {
this.s = s;
}
@Override
public String toString() {
return s;
}
public static Type fromMixedCase(String name) {
for (Type t : values())
if (t.s.equals(name))
return t;
throw new IllegalArgumentException("Value " + name + " not implemented");
}
}
public static FileFilter getFilter() {
return (new FileFilter() {
@ -98,7 +119,7 @@ public class SaveLoader {
TagCompound t = Tag.readFrom(new FileInputStream(f));
TagCompound pTag = (TagCompound) t.findTagByName("Player");
seed = (Long) t.findTagByName("RandomSeed").getValue();
genType = (String) t.findTagByName("generatorName").getValue();
genType = Type.fromMixedCase((String) t.findTagByName("generatorName").getValue());
System.out.println("Gen Type: " + genType);
multi = pTag == null;
if (!multi) {

View File

@ -89,10 +89,9 @@ public class AmidstMenu extends JMenuBar {
@Override
public void actionPerformed(ActionEvent arg0) {
//Create the JOptionPane.
String s = JOptionPane.showInputDialog(null, "Enter seed...", "New Project", JOptionPane.QUESTION_MESSAGE);
String s = JOptionPane.showInputDialog(null, "Enter seed", "New Project", JOptionPane.QUESTION_MESSAGE);
if (s != null) {
String[] possibilities = { "default", "flat", "largeBiomes" };
String worldType = choose("New Project", "Enter world type...\n", possibilities);
SaveLoader.Type worldType = choose("New Project", "Enter world type…\n", SaveLoader.Type.values());
//If a string was returned, say so.
if (worldType != null)
@ -190,8 +189,8 @@ public class AmidstMenu extends JMenuBar {
}
});
}});
//new JMenuItem("Spawn");
//new JMenuItem("Chunk");
//add(new JMenuItem("Spawn"));
//add(new JMenuItem("Chunk"));
}
}
@ -210,7 +209,7 @@ public class AmidstMenu extends JMenuBar {
add(new DisplayingCheckbox("Nether fortresses",
ResourceLoader.getImage("nether_fortress.png"),
KeyEvent.VK_3,
Options.instance.showNetherFortresses));
Options.instance.showNetherFortresses));
add(new DisplayingCheckbox("Icons",
null,
KeyEvent.VK_4,
@ -239,7 +238,7 @@ public class AmidstMenu extends JMenuBar {
fc.addChoosableFileFilter(new PNGFileFilter());
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(window);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String s = fc.getSelectedFile().toString();
if (!s.toLowerCase().endsWith(".png"))