Skip to content

Commit

Permalink
libdoomsday: Game profiles can specify all the required packages
Browse files Browse the repository at this point in the history
By default, a game profile always uses the packages required in the
the Game.
  • Loading branch information
skyjake committed Nov 22, 2016
1 parent eefc50b commit 60c1cc8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/gameprofiles.h
Expand Up @@ -44,10 +44,12 @@ class LIBDOOMSDAY_PUBLIC GameProfiles : public de::Profiles
void setGame(de::String const &id);
void setPackages(de::StringList const &packagesInOrder);
void setUserCreated(bool userCreated);
void setUseGameRequirements(bool useGameRequirements);

de::String game() const;
de::StringList packages() const;
bool isUserCreated() const;
bool isUsingGameRequirements() const;

/**
* Returns a list of the game's packages in addition to the profile's
Expand All @@ -57,6 +59,8 @@ class LIBDOOMSDAY_PUBLIC GameProfiles : public de::Profiles

de::StringList packagesAffectingGameplay() const;

de::StringList unavailablePackages() const;

bool isCompatibleWithPackages(de::StringList const &ids) const;

bool isPlayable() const;
Expand Down
47 changes: 42 additions & 5 deletions doomsday/apps/libdoomsday/src/gameprofiles.cpp
Expand Up @@ -32,6 +32,7 @@ using namespace de;
static String const VAR_GAME ("game");
static String const VAR_PACKAGES ("packages");
static String const VAR_USER_CREATED("userCreated");
static String const VAR_USE_GAME_REQUIREMENTS("useGameRequirements");

static GameProfile nullGameProfile;

Expand Down Expand Up @@ -126,6 +127,11 @@ Profiles::AbstractProfile *GameProfiles::profileFromInfoBlock(Info::BlockElement
}

prof->setUserCreated(!block.keyValue(VAR_USER_CREATED).text.compareWithoutCase("True"));
if (block.contains(VAR_USE_GAME_REQUIREMENTS))
{
prof->setUseGameRequirements(!block.keyValue(VAR_USE_GAME_REQUIREMENTS)
.text.compareWithoutCase("True"));
}

return prof.release();
}
Expand All @@ -137,13 +143,15 @@ DENG2_PIMPL_NOREF(GameProfiles::Profile)
String gameId;
StringList packages;
bool userCreated = false;
bool useGameRequirements = true;

Impl() {}

Impl(Impl const &other)
: gameId (other.gameId)
, packages (other.packages)
, userCreated(other.userCreated)
: gameId (other.gameId)
, packages (other.packages)
, userCreated (other.userCreated)
, useGameRequirements(other.useGameRequirements)
{}
};

Expand Down Expand Up @@ -173,6 +181,11 @@ void GameProfiles::Profile::setUserCreated(bool userCreated)
d->userCreated = userCreated;
}

void GameProfiles::Profile::setUseGameRequirements(bool useGameRequirements)
{
d->useGameRequirements = useGameRequirements;
}

String GameProfiles::Profile::game() const
{
return d->gameId;
Expand All @@ -188,9 +201,19 @@ bool GameProfiles::Profile::isUserCreated() const
return d->userCreated;
}

bool GameProfiles::Profile::isUsingGameRequirements() const
{
return d->useGameRequirements;
}

StringList GameProfiles::Profile::allRequiredPackages() const
{
return DoomsdayApp::games()[d->gameId].requiredPackages() + d->packages;
StringList list;
if (d->useGameRequirements)
{
list = DoomsdayApp::games()[d->gameId].requiredPackages();
}
return list + d->packages;
}

StringList GameProfiles::Profile::packagesAffectingGameplay() const
Expand All @@ -207,6 +230,19 @@ StringList GameProfiles::Profile::packagesAffectingGameplay() const
return ids;
}

StringList GameProfiles::Profile::unavailablePackages() const
{
StringList ids;
for (String const &pkg : allRequiredPackages())
{
if (!App::packageLoader().isAvailable(pkg))
{
ids << pkg;
}
}
return ids;
}

bool GameProfiles::Profile::isCompatibleWithPackages(StringList const &ids) const
{
return GameProfiles::arePackageListsCompatible(packagesAffectingGameplay(), ids);
Expand Down Expand Up @@ -255,7 +291,8 @@ String GameProfiles::Profile::toInfoSource() const

os << VAR_GAME << ": " << d->gameId << "\n"
<< VAR_PACKAGES << " <" << String::join(d->packages, ", ") << ">\n"
<< VAR_USER_CREATED << ": " << (d->userCreated? "True" : "False");
<< VAR_USER_CREATED << ": " << (d->userCreated? "True" : "False")
<< VAR_USE_GAME_REQUIREMENTS << ": " << (d->useGameRequirements? "True" : "False");

return info;
}
Expand Down

0 comments on commit 60c1cc8

Please sign in to comment.