Skip to content

Commit

Permalink
libdoomsday: Game profile last played time
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 3, 2018
1 parent 6ab15f1 commit b770352
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/game.h
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h
Expand Up @@ -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);

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/libdoomsday/src/game.cpp
Expand Up @@ -89,18 +89,18 @@ DENG2_PIMPL(Game)
qDeleteAll(manifests);
}

GameProfile const *profile() const
GameProfile *profile() const
{
return maybeAs<GameProfile>(DoomsdayApp::gameProfiles().tryFind(self().title()));
}

StringList packagesFromProfile() const
{
if (auto const *prof = profile())
if (const auto *prof = profile())
{
return prof->packages();
}
return StringList();
return {};
}
};

Expand Down Expand Up @@ -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();
Expand Down
41 changes: 33 additions & 8 deletions doomsday/apps/libdoomsday/src/gameprofiles.cpp
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
{
Expand All @@ -195,6 +200,7 @@ DENG2_PIMPL_NOREF(GameProfiles::Profile)
bool useGameRequirements = true;
String autoStartMap;
int autoStartSkill = DEFAULT_SKILL;
Time lastPlayedAt = Time::invalidTime();

Impl() {}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit b770352

Please sign in to comment.