blob: 44b3cddd0bced1c7cf14054d31d56f07ac5b38e6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.fourisland.fourpuzzle;
import com.fourisland.fourpuzzle.database.GameCharacters;
import com.fourisland.fourpuzzle.database.Database;
import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author hatkirby
*/
public class SaveFile implements Serializable {
/**
* Creates a new SaveFile
*/
public SaveFile()
{
switches = new HashMap<String, Boolean>();
party = Database.createParty();
variables = new HashMap<String, Integer>();
currentMap = new String();
hero = new HeroEvent();
}
/**
* Loads a SaveFile
*
* @param file The ID of the SaveFile to load
* @throws IOException if the SaveFile specified does not exist
*/
public SaveFile(int file) throws IOException
{
InputStream is = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openInputFile("Save" + file + ".sav");
ObjectInputStream ois = new ObjectInputStream(is);
SaveFile temp = null;
try {
temp = (SaveFile) ois.readObject();
} catch (ClassNotFoundException ex) {
Logger.getLogger(SaveFile.class.getName()).log(Level.SEVERE, null, ex);
}
switches = temp.getSwitches();
variables = temp.getVariables();
party = temp.getParty();
currentMap = temp.getCurrentMap();
ois.close();
is.close();
}
public void saveGame(int file) throws IOException
{
OutputStream os = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openOutputFile("Save" + file + ".sav");
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(this);
oos.close();
os.close();
}
private HashMap<String, Boolean> switches;
public HashMap<String, Boolean> getSwitches() {
return switches;
}
private GameCharacters party;
public GameCharacters getParty() {
return party;
}
private HashMap<String, Integer> variables;
public HashMap<String, Integer> getVariables() {
return variables;
}
private String currentMap;
public String getCurrentMap()
{
return currentMap;
}
public void setCurrentMap(String currentMap)
{
this.currentMap = currentMap;
}
private HeroEvent hero;
public HeroEvent getHero()
{
return hero;
}
public void setHero(HeroEvent hero)
{
this.hero = hero;
}
}
|