Skip to content

Commit

Permalink
libdeng2|SavedSession: Search .save packages to check availability of…
Browse files Browse the repository at this point in the history
… serialized map states
  • Loading branch information
danij-deng committed Mar 12, 2014
1 parent d7fabfd commit d86da01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
28 changes: 15 additions & 13 deletions doomsday/libdeng2/include/de/game/savedsession.h
Expand Up @@ -32,23 +32,23 @@ namespace game {
class MapStateReader;

/**
* Logical component representing a serialized game state on disk.
* Logical component representing a serialized game session on disk.
*
* @ingroup game
*/
class DENG2_PUBLIC SavedSession
{
public:
/// Notified whenever the status of the saved game session changes.
/// Notified whenever the status of the saved session changes.
DENG2_DEFINE_AUDIENCE2(StatusChange, void savedSessionStatusChanged(SavedSession &session))

/// Notified whenever the metadata of the saved game session changes.
/// Notified whenever the metadata of the saved session changes.
DENG2_DEFINE_AUDIENCE2(MetadataChange, void savedSessionMetadataChanged(SavedSession &session))

/// Required/referenced repository is missing. @ingroup errors
DENG2_ERROR(MissingRepositoryError);

/// The associated game map state file was missing/unrecognized. @ingroup errors
/// The associated map state file was missing/unrecognized. @ingroup errors
DENG2_ERROR(UnrecognizedMapStateError);

/// Logical session status:
Expand Down Expand Up @@ -132,16 +132,16 @@ class DENG2_PUBLIC SavedSession
void setRepository(SavedSessionRepository *newRepository);

/**
* Determines whether a file package exists for the saved session. However, it may not be
* compatible with the current game session.
* Determines whether a file package exists for the saved session in the repository. Note that
* it may not be compatible with the current game session, however.
*
* @see isLoadable()
* @see setRepository(), isLoadable()
*/
bool hasFile() const;

/**
* Determines whether a file package exists for the saved session and if so, reads the
* session metadata. A repository must be configured for this.
* Determines whether a file package exists for the saved session in the repository and if so,
* reads the session metadata.
*
* @return @c true iff the session metadata was read successfully.
*
Expand Down Expand Up @@ -179,7 +179,9 @@ class DENG2_PUBLIC SavedSession

/**
* Uses @a newMetadata to replace that associated with the saved session. Note that this will
* @em not alter file package in the repository. The MetadataChange audience is notified.
* @em not alter the file package in the repository. The MetadataChange audience is notified.
*
* @param newMetadata Replacement Metadata. Ownership is given.
*/
void replaceMetadata(Metadata *newMetadata);

Expand All @@ -193,9 +195,9 @@ class DENG2_PUBLIC SavedSession
bool hasMapState(String mapUriStr) const;

/**
* Determines whether a file package exists for the saved session and if so, reads the
* session metadata and returns a new MapStateReader instance appropriate for deserializing
* map state data. A repository must be configured for this.
* Determines whether a file package exists for the saved session in the repository and if so,
* reads the session metadata and then returns a new MapStateReader instance appropriate for
* deserializing map state data.
*
* @return New reader instance if recognized; otherwise @c 0. Ownership given to the caller.
*/
Expand Down
14 changes: 9 additions & 5 deletions doomsday/libdeng2/src/game/savedsession.cpp
Expand Up @@ -367,15 +367,19 @@ void SavedSession::setFileName(String newName)

bool SavedSession::hasFile() const
{
return repository().folder().has(fileName());
if(!d->repo) return false;
return d->repo->folder().has(fileName());
}

bool SavedSession::hasMapState(String mapUriStr) const
{
if(mapUriStr.isEmpty()) return false;
String mapFileName = d->fileName.fileNameWithoutExtension() + mapUriStr;
/// @todo Open the .save file and check the index.
return repository().folder().has(mapFileName);
if(!mapUriStr.isEmpty() && hasFile())
{
PackageFolder const &pack = d->repo->folder().locate<PackageFolder const>(d->fileName);
String mapStateFileName = d->fileName.fileNameWithoutExtension() + mapUriStr;
return pack.has(mapStateFileName);
}
return false;
}

void SavedSession::updateFromFile()
Expand Down

0 comments on commit d86da01

Please sign in to comment.