save, load, delete features implemented. starting testing.
This commit is contained in:
@@ -5,18 +5,11 @@ public class DndCharacterBuilder {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
FileManager data = new FileManager();
|
||||||
|
|
||||||
PanelHolder guiPanels = new PanelHolder();
|
PanelHolder guiPanels = new PanelHolder();
|
||||||
UImanager gui = new UImanager(guiPanels, isReturningUser());
|
UImanager gui = new UImanager(guiPanels, data.isReturninguser());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isReturningUser() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,16 +10,40 @@ public class FileManager {
|
|||||||
|
|
||||||
public FileManager() {
|
public FileManager() {
|
||||||
|
|
||||||
|
findSavedCharacters();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReturninguser() {
|
||||||
|
|
||||||
|
return savedCharacters.length > 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need to implement. Reads file and returns a re-created CharacterSheet object.
|
|
||||||
public CharacterSheet readCharacter(int index) {
|
public CharacterSheet readCharacter(int index) {
|
||||||
|
|
||||||
File character = savedCharacters[index];
|
CharacterSheet sheet = null;
|
||||||
|
|
||||||
return new CharacterSheet();
|
try {
|
||||||
|
|
||||||
|
FileInputStream fileIn = new FileInputStream("/tmp/" + savedCharacters[index].getPath() + ".dnd");
|
||||||
|
ObjectInputStream in = new ObjectInputStream(fileIn);
|
||||||
|
sheet = (CharacterSheet) in.readObject();
|
||||||
|
in.close();
|
||||||
|
fileIn.close();
|
||||||
|
|
||||||
|
} catch (IOException i) {
|
||||||
|
|
||||||
|
i.printStackTrace();
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException c) {
|
||||||
|
|
||||||
|
System.out.println("Employee class not found");
|
||||||
|
c.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return sheet;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,17 +66,28 @@ public class FileManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need to implement.
|
|
||||||
public void deleteCharacter(int index) {
|
public void deleteCharacter(int index) {
|
||||||
|
|
||||||
|
File[] tmp = new File[savedCharacters.length - 1];
|
||||||
|
|
||||||
|
for (int i = 0; i < savedCharacters.length; i++) {
|
||||||
|
|
||||||
|
if(i != index) {
|
||||||
|
|
||||||
|
tmp[i] = savedCharacters[i];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
savedCharacters = tmp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need to implement. Should create an array of Files corresponding to user-created characters.
|
// TODO: Need to implement. Should create an array of Files corresponding to user-created characters.
|
||||||
private void findSavedCharacters() {
|
private void findSavedCharacters() {
|
||||||
|
|
||||||
|
savedCharacters = new File("/bin/").listFiles();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user