Fixed save bug
This commit is contained in:
parent
6215e8a7ab
commit
6362287240
@ -281,11 +281,11 @@ public class DQ extends JFrame implements ActionListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (e.getActionCommand().equals("Save Level")) {
|
if (e.getActionCommand().equals("Save Level")) {
|
||||||
FileDialog fd = new FileDialog(this, "Save Level", FileDialog.SAVE);
|
FileDialog fd = new FileDialog(this, "Save Level", FileDialog.SAVE);
|
||||||
fd.setDirectory(System.getProperty("user.home") + "/.DroidQuest/" + "ROlevels");
|
fd.setDirectory(System.getProperty("user.home") + "/.DroidQuest/" + "Saves");
|
||||||
fd.show();
|
fd.show();
|
||||||
System.out.println("Dialog returned with "
|
System.out.println("Dialog returned with "
|
||||||
+ fd.getDirectory()
|
+ fd.getDirectory()
|
||||||
+ fd.getFile());
|
+ fd.getFile());
|
||||||
if (fd.getFile() != null) {
|
if (fd.getFile() != null) {
|
||||||
myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
|
myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
|
|
||||||
public class RoomDisplay extends JPanel {
|
public class RoomDisplay extends JPanel {
|
||||||
public final DQ dq;
|
public final DQ dq;
|
||||||
Level level;
|
public Level level;
|
||||||
public Timer timer;
|
public Timer timer;
|
||||||
private int timerspeed = 128;
|
private int timerspeed = 128;
|
||||||
public boolean useSounds = true;
|
public boolean useSounds = true;
|
||||||
@ -36,6 +36,8 @@ public class RoomDisplay extends JPanel {
|
|||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RoomDisplay rd;
|
||||||
|
|
||||||
public RoomDisplay(final DQ dq) {
|
public RoomDisplay(final DQ dq) {
|
||||||
this.dq = dq;
|
this.dq = dq;
|
||||||
setSize(new Dimension(560, 384));
|
setSize(new Dimension(560, 384));
|
||||||
@ -131,7 +133,7 @@ public class RoomDisplay extends JPanel {
|
|||||||
}
|
}
|
||||||
catch (FileNotFoundException ie) {
|
catch (FileNotFoundException ie) {
|
||||||
// filename does not exist
|
// filename does not exist
|
||||||
RoomDisplay rd = level.roomdisplay;
|
rd = level.roomdisplay;
|
||||||
String classname = "com.droidquest.levels." + filename.substring(0, filename.length() - 4);
|
String classname = "com.droidquest.levels." + filename.substring(0, filename.length() - 4);
|
||||||
Constructor constructor = null;
|
Constructor constructor = null;
|
||||||
try {
|
try {
|
||||||
@ -443,16 +445,45 @@ public class RoomDisplay extends JPanel {
|
|||||||
|
|
||||||
public void SaveLevel(String filename) {
|
public void SaveLevel(String filename) {
|
||||||
System.out.println("Saving level " + filename);
|
System.out.println("Saving level " + filename);
|
||||||
|
String[] filenames = filename.split("/");
|
||||||
|
if (filenames.length > 1) {
|
||||||
|
filename = filenames[filenames.length - 1];
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
FileOutputStream out = new FileOutputStream(System.getProperty("user.home") + "/.DroidQuest/" + "ROlevels/" + filename);
|
FileOutputStream out = new FileOutputStream(System.getProperty("user.home") + "/.DroidQuest/Saves/" + filename);
|
||||||
ObjectOutputStream s = new ObjectOutputStream(out);
|
ObjectOutputStream s = new ObjectOutputStream(out);
|
||||||
level.writeObject(s);
|
level.writeObject(s);
|
||||||
s.flush();
|
s.flush();
|
||||||
s.close();
|
s.close();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e) {
|
catch (FileNotFoundException e) {
|
||||||
System.out.println("File Not Found");
|
System.out.println("File Not Found" + filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.out.println("IO Exception");
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveLevelAuto(String filename) {
|
||||||
|
System.out.println("Saving level " + filename);
|
||||||
|
String[] filenames = filename.split("/");
|
||||||
|
if (filenames.length > 1) {
|
||||||
|
filename = filenames[filenames.length - 1];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file = new File(System.getProperty("user.home") + "/.DroidQuest/" + filename);
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
|
ObjectOutputStream s = new ObjectOutputStream(out);
|
||||||
|
level.writeObject(s);
|
||||||
|
s.flush();
|
||||||
|
s.close();
|
||||||
|
out.close();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.out.println("IO Exception");
|
System.out.println("IO Exception");
|
||||||
@ -468,16 +499,23 @@ public class RoomDisplay extends JPanel {
|
|||||||
Room.level = level;
|
Room.level = level;
|
||||||
Material.level = level;
|
Material.level = level;
|
||||||
|
|
||||||
|
String[] split = filename.split("/");
|
||||||
|
if (split.length == 1) {
|
||||||
|
filename = System.getProperty("user.home") + "/.DroidQuest/Saves/" + filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Loading level " + filename);
|
||||||
|
|
||||||
// Add flags for loading Object inventories or running Init()
|
// Add flags for loading Object inventories or running Init()
|
||||||
try {
|
try {
|
||||||
FileInputStream in = new FileInputStream(System.getProperty("user.home") + "/.DroidQuest/" + "ROlevels/" + filename);
|
FileInputStream in = new FileInputStream(filename);
|
||||||
ObjectInputStream s = new ObjectInputStream(in);
|
ObjectInputStream s = new ObjectInputStream(in);
|
||||||
level.readObject(s);
|
level.readObject(s);
|
||||||
s.close();
|
s.close();
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e) {
|
catch (FileNotFoundException e) {
|
||||||
System.out.println("File Not Found");
|
System.out.println("File Not Found" + filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
@ -267,11 +267,11 @@ public class MainMenu extends Level {
|
|||||||
player = gameCursor;
|
player = gameCursor;
|
||||||
currentViewer = player;
|
currentViewer = player;
|
||||||
|
|
||||||
File f = new File(System.getProperty("user.home") + "/.DroidQuest/ROlevels/");
|
File file = new File(System.getProperty("user.home") + "/.DroidQuest/Saves/");
|
||||||
if (!f.exists()) {
|
if (!file.exists()) {
|
||||||
f.mkdirs();
|
file.mkdirs();
|
||||||
}
|
}
|
||||||
String[] files = f.list();
|
String[] files = file.list();
|
||||||
int pageIndex = 5;
|
int pageIndex = 5;
|
||||||
for (int a = 0; a < files.length; a++) {
|
for (int a = 0; a < files.length; a++) {
|
||||||
if (a > 4 && a % 5 == 0) {
|
if (a > 4 && a % 5 == 0) {
|
||||||
@ -301,7 +301,7 @@ public class MainMenu extends Level {
|
|||||||
LinkRoomsUpDown(pageIndex, newPageIndex);
|
LinkRoomsUpDown(pageIndex, newPageIndex);
|
||||||
pageIndex = newPageIndex;
|
pageIndex = newPageIndex;
|
||||||
}
|
}
|
||||||
materials.addElement(new Portal(files[a], false, false));
|
materials.addElement(new Portal(System.getProperty("user.home") + "/.DroidQuest/Saves/" + files[a], false, false));
|
||||||
int matIndex = materials.size() - 1;
|
int matIndex = materials.size() - 1;
|
||||||
int y = 1 + (a % 5) * 2;
|
int y = 1 + (a % 5) * 2;
|
||||||
Room room = rooms.elementAt(pageIndex);
|
Room room = rooms.elementAt(pageIndex);
|
||||||
|
Loading…
Reference in New Issue
Block a user