Package horizons :: Module savegamemanager :: Class SavegameManager
[hide private]
[frames] | no frames]

Class SavegameManager

source code

Controls savegamefiles.

This class is rather a namespace than a "real" object, since it has no members. The instance in horizons.main is nevertheless important, since it creates the savegame directories

The return value usually is a tuple: (list_of_savegame_files, list_of_savegame_names), where savegame_names are meant for displaying to the user.

IMPORTANT: Whenever you make a change that breaks compatibility with old savegames, increment horizons/constants.py:VERSION.SAVEGAMEREVISION and add an upgrade path in horizons/util/savegameupgrader.py.

Class Methods [hide private]
 
init(cls) source code
 
__get_displaynames(cls, files)
Returns player-facing names for the savegames *files*.
source code
 
__get_saves_from_dirs(cls, dirs, include_displaynames, filename_extension, order_by_date)
Returns the savegame files in each directory in *dirs*.
source code
 
create_filename(cls, savegamename)
Returns the full path for a regular save of the name *savegamename*.
source code
 
create_autosave_filename(cls)
Builds filename for a new autosave.
source code
 
create_quicksave_filename(cls)
Returns the filename for a quicksave
source code
 
create_multiplayer_quicksave_name(cls)
Will create a name, not a path
source code
 
create_multiplayer_autosave_name(cls)
Will create a name, not a path
source code
 
create_multiplayersave_filename(cls, name)
Builds filename for a multiplayer savegame *name*.
source code
 
delete_dispensable_savegames(cls, autosaves=False, quicksaves=False)
Delete oldest savegames that are no longer needed.
source code
 
get_recommended_number_of_players(cls, mapfile)
Returns amount of players recommended for a map *mapfile*.
source code
 
get_metadata(cls, savegamefile)
Returns metainfo of a savegame as dict.
source code
 
_write_screenshot(cls, db)
special handling for screenshot (as blob)
source code
 
write_metadata(cls, db, savecounter, rng_state)
Writes metadata into database *db*.
source code
 
get_regular_saves(cls, include_displaynames=True)
Returns all savegames that were saved via the ingame save dialog.
source code
 
get_maps(cls, include_displaynames=True)
Returns all maps in content/maps/ and ~/.unknown-horizons/maps/.
source code
 
get_map(cls, map_name) source code
 
get_multiplayersave_map(cls, name) source code
 
get_saves(cls, include_displaynames=True)
Returns all savegames: regular, auto- and quicksaves.
source code
 
get_multiplayersaves(cls, include_displaynames=True) source code
 
get_quicksaves(cls, include_displaynames=True)
Returns all quicksave savegames.
source code
 
get_scenarios(cls, include_displaynames=True)
Returns all scenarios
source code
 
get_available_scenarios(cls, include_displaynames=True, locales=False)
Returns available scenarios.
source code
 
get_scenario_metadata(cls, scenario="", filename="")
Return the `metadata` dict for a scenario.
source code
 
get_savegamename_from_filename(cls, savegamefile)
Returns a displayable name, extracted from a filename
source code
 
get_filename_from_map_name(cls, map_name) source code
Class Variables [hide private]
  log = logging.getLogger("savegamemanager")
  savegame_dir = os.path.join(PATHS.USER_DIR, "save")
  autosave_dir = os.path.join(savegame_dir, "autosave")
  multiplayersave_dir = os.path.join(savegame_dir, "multiplayer_...
  quicksave_dir = os.path.join(savegame_dir, "quicksave")
  maps_dir = os.path.join("content", "maps")
  scenario_maps_dir = os.path.join("content", "scenariomaps")
  scenarios_dir = os.path.join("content", "scenarios")
  savegame_extension = "sqlite"
  scenario_extension = "yaml"
  autosave_basename = "autosave-"
  quicksave_basename = "quicksave-"
  multiplayersave_name_regex = r"^[0-9a-zA-Z _.-]+$"
  save_filename_timeformat = "{prefix}%Y-%m-%d--%H-%M-%S"
  autosave_filenamepattern = save_filename_timeformat.format(pre...
  quicksave_filenamepattern = save_filename_timeformat.format(pr...
  filename = "{{directory}}{sep}{{name}}.{ext}".format(sep= os.p...
  savegame_screenshot_width = 290
  savegame_metadata = {'timestamp':-1, 'savecounter': 0, 'savega...
  savegame_metadata_types = {'timestamp': float, 'savecounter': ...
Method Details [hide private]

__get_displaynames(cls, files)
Class Method

source code 

Returns player-facing names for the savegames *files*.

Parameters:
  • files - iterable object containing strings.
Returns:
list of names to be displayed for each file.

__get_saves_from_dirs(cls, dirs, include_displaynames, filename_extension, order_by_date)
Class Method

source code 

Returns the savegame files in each directory in *dirs*. Internal method.

Parameters:
  • include_displaynames - Whether to add player-readable names displayed in gui.

delete_dispensable_savegames(cls, autosaves=False, quicksaves=False)
Class Method

source code 

Delete oldest savegames that are no longer needed.

This is usually called to make space for new savegames when the limit (defined in settings) for that kind of saves is reached.

Parameters:
  • autosaves - set to True if autosaves should be cleaned.
  • quicksaves - set to True if quicksaves should be cleaned.

write_metadata(cls, db, savecounter, rng_state)
Class Method

source code 

Writes metadata into database *db*.

Parameters:
  • db - DbReader instance.
  • savecounter - int, how many times this file has been saved.

get_regular_saves(cls, include_displaynames=True)
Class Method

source code 

Returns all savegames that were saved via the ingame save dialog.

Parameters:
  • include_displaynames - Whether to add player-readable names displayed in gui.

get_maps(cls, include_displaynames=True)
Class Method

source code 

Returns all maps in content/maps/ and ~/.unknown-horizons/maps/.

Parameters:
  • include_displaynames - Whether to add player-readable names displayed in gui.

get_saves(cls, include_displaynames=True)
Class Method

source code 

Returns all savegames: regular, auto- and quicksaves.

Parameters:
  • include_displaynames - Whether to add player-readable names displayed in gui.

get_scenario_metadata(cls, scenario="", filename="")
Class Method

source code 

Return the `metadata` dict for a scenario.

Pass either the scenario name (*scenario*) or a .yaml *filename*.


Class Variable Details [hide private]

multiplayersave_dir

Value:
os.path.join(savegame_dir, "multiplayer_save")

autosave_filenamepattern

Value:
save_filename_timeformat.format(prefix= autosave_basename)

quicksave_filenamepattern

Value:
save_filename_timeformat.format(prefix= quicksave_basename)

filename

Value:
"{{directory}}{sep}{{name}}.{ext}".format(sep= os.path.sep, ext= saveg\
ame_extension)

savegame_metadata

Value:
{'timestamp':-1, 'savecounter': 0, 'savegamerev': 0, 'rng_state': ""}

savegame_metadata_types

Value:
{'timestamp': float, 'savecounter': int, 'savegamerev': int, 'rng_stat\
e': str}