|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.colossus.server.GameSaving
public class GameSaving
Field Summary | |
---|---|
private java.util.List<java.lang.String> |
autoGeneratedFiles
List of filenames that has been created by AutoSave. |
private GameServerSide |
game
|
private static java.util.logging.Logger |
LOGGER
|
private Options |
options
|
private org.jdom.Element |
phaseStartSnapshot
snapshot of game data (caretaker, players, legions, ...) at the last "commit point", initially those are taken only at start of a phase. |
Constructor Summary | |
---|---|
GameSaving(GameServerSide game,
Options options)
|
Method Summary | |
---|---|
private void |
addBasicData(org.jdom.Element root)
Adds the basic data: variant info, turn number, current player, current phase, and caretaker. |
private void |
addBattleData(org.jdom.Element root)
|
private void |
addPlayerData(org.jdom.Element root)
Adds the data for all players and their legions to an XML document |
private void |
addSnapshotData(org.jdom.Element saveGameRoot,
org.jdom.Element commitDataRoot)
|
private java.lang.String |
automaticFilenameHandling(java.lang.String filename,
boolean autoSave,
int keep)
Produce one "automatically generated file name" for saving games, including directory handling: 1) Creates the save game directory if it does not exist yet, including error handling. |
void |
commitPointReached()
When a commit point is reached (typically, one phase is "Done" and a new phase begins), 1) take new snapshot of overall game state, player, legion, caretaker data 2) flush the so far redoLog data to the history, 3) clear the redoLog data. |
private org.jdom.Element |
createSavegameContent()
Create the whole content that will be written to the save game file. |
private org.jdom.Element |
dumpLegion(LegionServerSide legion,
boolean inBattle)
Dump the given legion to an XML element |
private void |
ensureSavesDirectory()
Ensure that saves/ directory in Colossus-home exists, or create it. |
private java.lang.String |
makeAutosaveFileName()
Generate the filename for autosaving (or just "Save" where one does specify file name either) according to the pattern: DIRECTORY/snap TIMESTAMP TURN-PLAYER-PHASE |
private java.lang.String |
notnull(java.lang.String in)
Helper method, returns "null" if given string is null; used by dumpLegion. |
private void |
saveGame(java.lang.String filename,
boolean autoSave)
High-level method to save a file. |
(package private) void |
saveGameWithErrorHandling(java.lang.String filename,
boolean autoSave)
Call saveGame in a try-catch block. |
private void |
takeSnapshotAtBeginOfPhase()
Take a new snapshot of the data (basic game data, players with legions, and history) at the begin of a phase. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.util.logging.Logger LOGGER
private final GameServerSide game
private final Options options
private org.jdom.Element phaseStartSnapshot
private final java.util.List<java.lang.String> autoGeneratedFiles
Constructor Detail |
---|
public GameSaving(GameServerSide game, Options options)
Method Detail |
---|
private void takeSnapshotAtBeginOfPhase()
public void commitPointReached()
private void addSnapshotData(org.jdom.Element saveGameRoot, org.jdom.Element commitDataRoot)
private org.jdom.Element createSavegameContent()
private void addBasicData(org.jdom.Element root)
root
- The document root to which to add all the dataprivate java.lang.String notnull(java.lang.String in)
in
- the string to "null"ify if needed
private org.jdom.Element dumpLegion(LegionServerSide legion, boolean inBattle)
legion
- For which legion to dump the datainBattle
- Whether this legion is currently involved into an
ongoing battle (i.e. battle data needs to be dumped too)
private void addPlayerData(org.jdom.Element root)
root
- The document root to which to add the dataprivate void addBattleData(org.jdom.Element root)
private java.lang.String makeAutosaveFileName()
private void ensureSavesDirectory() throws java.io.IOException
java.io.IOException
- if the saves directory does not exist and creation
failsprivate java.lang.String automaticFilenameHandling(java.lang.String filename, boolean autoSave, int keep)
filename
- User specified filename, null for autosave or File-SaveautoSave
- Whether or not this was triggered by autosavekeep
- How many autosave files to keep, 0 for "keep all"
private void saveGame(java.lang.String filename, boolean autoSave) throws java.io.IOException
filename
- user specified filename, null for auto-save or File-SaveautoSave
- Whether or not this is autoSave
java.io.IOException
- if the saves directory (for autosave or File-Save)
does not exist and creation failsvoid saveGameWithErrorHandling(java.lang.String filename, boolean autoSave)
filename
- The name of the file to createautoSave
- True if this was triggered by autoSave
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |