implemented capability to save CharacterSheet objects to storage

This commit is contained in:
Joshua-Ashton01
2022-11-08 18:09:54 -07:00
parent a1589f627d
commit cf0ea4ea88
3 changed files with 45 additions and 13 deletions
+31 -12
View File
@@ -1,7 +1,7 @@
package FileManagement;
import javax.swing.text.Document;
import java.io.File;
import java.io.*;
import Character.*;
public class FileManager {
@@ -14,12 +14,39 @@ public class FileManager {
}
public CharacterSheet readCharacter() {
// TODO: Need to implement. Reads file and returns a re-created CharacterSheet object.
public CharacterSheet readCharacter(int index) {
File character = savedCharacters[index];
return new CharacterSheet();
}
public void saveCharacter (CharacterSheet completedCharacter) {
try {
FileOutputStream fileOut =
new FileOutputStream("/bin/" + completedCharacter.getName().hashCode() + ".dnd");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(completedCharacter);
out.close();
fileOut.close();
} catch (IOException i) {
i.printStackTrace();
}
}
// TODO: Need to implement.
public void deleteCharacter(int index) {
}
// TODO: Need to implement. Should create an array of Files corresponding to user-created characters.
@@ -27,14 +54,6 @@ public class FileManager {
}
public void saveCharacter (Character completedCharacter) {
}
}