diff --git a/doomsday/apps/libdoomsday/include/doomsday/game.h b/doomsday/apps/libdoomsday/include/doomsday/game.h index af728d586f..36850998dd 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/game.h +++ b/doomsday/apps/libdoomsday/include/doomsday/game.h @@ -248,7 +248,7 @@ class LIBDOOMSDAY_PUBLIC Game : public de::IObject /** * Returns the built-in profile of the game. */ - GameProfile const &profile() const; + GameProfile &profile() const; // IObject. de::Record const &objectNamespace() const; diff --git a/doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h b/doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h index b513c90735..763e3f0741 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h +++ b/doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h @@ -50,6 +50,7 @@ class LIBDOOMSDAY_PUBLIC GameProfiles : public de::Profiles void setUseGameRequirements(bool useGameRequirements); void setAutoStartMap(de::String const &map); void setAutoStartSkill(int level); + void setLastPlayedAt(const de::Time &at = de::Time()); bool appendPackage(de::String const &id); @@ -60,6 +61,7 @@ class LIBDOOMSDAY_PUBLIC GameProfiles : public de::Profiles bool isUsingGameRequirements() const; de::String autoStartMap() const; int autoStartSkill() const; + de::Time lastPlayedAt() const; /** * Returns a list of the game's packages in addition to the profile's diff --git a/doomsday/apps/libdoomsday/src/game.cpp b/doomsday/apps/libdoomsday/src/game.cpp index d7922af4e7..ca87317469 100644 --- a/doomsday/apps/libdoomsday/src/game.cpp +++ b/doomsday/apps/libdoomsday/src/game.cpp @@ -89,18 +89,18 @@ DENG2_PIMPL(Game) qDeleteAll(manifests); } - GameProfile const *profile() const + GameProfile *profile() const { return maybeAs(DoomsdayApp::gameProfiles().tryFind(self().title())); } StringList packagesFromProfile() const { - if (auto const *prof = profile()) + if (const auto *prof = profile()) { return prof->packages(); } - return StringList(); + return {}; } }; @@ -444,7 +444,7 @@ void Game::addResource(resourceclassid_t classId, dint rflags, } } -GameProfile const &Game::profile() const +GameProfile &Game::profile() const { DENG2_ASSERT(d->profile()); // all games have a matching built-in profile return *d->profile(); diff --git a/doomsday/apps/libdoomsday/src/gameprofiles.cpp b/doomsday/apps/libdoomsday/src/gameprofiles.cpp index 9e85f65111..e0def0f75b 100644 --- a/doomsday/apps/libdoomsday/src/gameprofiles.cpp +++ b/doomsday/apps/libdoomsday/src/gameprofiles.cpp @@ -35,6 +35,7 @@ static String const VAR_USER_CREATED ("userCreated"); static String const VAR_USE_GAME_REQUIREMENTS("useGameRequirements"); static String const VAR_AUTO_START_MAP ("autoStartMap"); static String const VAR_AUTO_START_SKILL("autoStartSkill"); +static String const VAR_LAST_PLAYED ("lastPlayed"); static int const DEFAULT_SKILL = 3; // Normal skill level (1-5) @@ -181,11 +182,15 @@ Profiles::AbstractProfile *GameProfiles::profileFromInfoBlock(Info::BlockElement { prof->setAutoStartSkill(block.keyValue(VAR_AUTO_START_SKILL).text.toInt()); } + if (block.contains(VAR_LAST_PLAYED)) + { + prof->setLastPlayedAt(Time::fromText(block.keyValue(VAR_LAST_PLAYED).text)); + } return prof.release(); } -//--------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- DENG2_PIMPL_NOREF(GameProfiles::Profile) { @@ -195,6 +200,7 @@ DENG2_PIMPL_NOREF(GameProfiles::Profile) bool useGameRequirements = true; String autoStartMap; int autoStartSkill = DEFAULT_SKILL; + Time lastPlayedAt = Time::invalidTime(); Impl() {} @@ -221,13 +227,14 @@ GameProfiles::Profile::Profile(Profile const &other) GameProfiles::Profile &GameProfiles::Profile::operator = (Profile const &other) { - AbstractProfile::operator = (other); - d->gameId = other.d->gameId; - d->packages = other.d->packages; - d->userCreated = other.d->userCreated; - d->useGameRequirements = other.d->useGameRequirements; - d->autoStartMap = other.d->autoStartMap; - d->autoStartSkill = other.d->autoStartSkill; + AbstractProfile::operator=(other); + d->gameId = other.d->gameId; + d->packages = other.d->packages; + d->userCreated = other.d->userCreated; + d->useGameRequirements = other.d->useGameRequirements; + d->autoStartMap = other.d->autoStartMap; + d->autoStartSkill = other.d->autoStartSkill; + d->lastPlayedAt = other.d->lastPlayedAt; return *this; } @@ -287,6 +294,15 @@ void GameProfiles::Profile::setAutoStartSkill(int level) } } +void GameProfiles::Profile::setLastPlayedAt(const Time &at) +{ + if (d->lastPlayedAt != at) + { + d->lastPlayedAt = at; + notifyChange(); + } +} + bool GameProfiles::Profile::appendPackage(String const &id) { if (!d->packages.contains(id)) @@ -338,6 +354,11 @@ int GameProfiles::Profile::autoStartSkill() const return d->autoStartSkill; } +Time GameProfiles::Profile::lastPlayedAt() const +{ + return d->lastPlayedAt; +} + StringList GameProfiles::Profile::allRequiredPackages() const { StringList list; @@ -424,6 +445,10 @@ String GameProfiles::Profile::toInfoSource() const os << "\n" << VAR_AUTO_START_MAP << ": " << d->autoStartMap; } os << "\n" << VAR_AUTO_START_SKILL << ": " << d->autoStartSkill; + if (d->lastPlayedAt.isValid()) + { + os << "\n" << VAR_LAST_PLAYED << ": " << d->lastPlayedAt.asText(); + } return info; }