Skip to content

Commit

Permalink
Resources|libdoomsday: Configuring local packages for multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 4, 2017
1 parent e42c3a0 commit 48ab26c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
16 changes: 16 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/game.h
Expand Up @@ -107,6 +107,12 @@ class LIBDOOMSDAY_PUBLIC Game : public de::IObject
*/
de::StringList requiredPackages() const;

/**
* Returns the list of packages that the user has chosen to be loaded when
* joining multiplayer using this game. The list of packages is read from Config.
*/
de::StringList localMultiplayerPackages() const;

/**
* Determines the status of the game.
*
Expand Down Expand Up @@ -272,6 +278,16 @@ class LIBDOOMSDAY_PUBLIC Game : public de::IObject

static de::String logoImageForId(de::String const &id);

static de::StringList localMultiplayerPackages(de::String const &gameId);

/**
* Sets the packages that will be loaded locally in addition to the server's
* packages. This is saved to Config.
*
* @param packages List of local packages.
*/
static void setLocalMultiplayerPackages(de::String const &gameId, de::StringList const &packages);

private:
DENG2_PRIVATE(d)
};
Expand Down
37 changes: 37 additions & 0 deletions doomsday/apps/libdoomsday/src/game.cpp
Expand Up @@ -30,6 +30,8 @@

#include <de/App>
#include <de/CommandLine>
#include <de/Config>
#include <de/DictionaryValue>
#include <de/Error>
#include <de/Log>
#include <de/PackageLoader>
Expand Down Expand Up @@ -151,6 +153,41 @@ StringList Game::requiredPackages() const
return d->requiredPackages;
}

StringList Game::localMultiplayerPackages() const
{
return localMultiplayerPackages(id());
}

StringList Game::localMultiplayerPackages(String const &gameId) // static
{
try
{
auto const &pkgDict = Config::get().getdt("resource.localPackagesForGame");
TextValue const key(gameId);
if (pkgDict.contains(key))
{
return pkgDict.element(key).as<ArrayValue>().toStringList();
}
return StringList();
}
catch (Error const &)
{
return StringList();
}
}

void Game::setLocalMultiplayerPackages(String const &gameId, StringList const &packages) // static
{
std::unique_ptr<ArrayValue> ids(new ArrayValue);
for (String const &pkg : packages)
{
ids->add(pkg);
}
Config::get()["resource.localPackagesForGame"]
.value().as<DictionaryValue>()
.setElement(TextValue(gameId), ids.release());
}

void Game::addManifest(ResourceManifest &manifest)
{
// Ensure we don't add duplicates.
Expand Down
3 changes: 1 addition & 2 deletions doomsday/apps/libdoomsday/src/gamestatefolder.cpp
Expand Up @@ -389,8 +389,7 @@ String GameStateFolder::Metadata::asStyledText() const
StringList pkgIds;
for (auto const *val : pkgs.elements())
{
auto const id_ver = Package::split(val->asText());
pkgIds << String("%1 (%2)").arg(id_ver.first).arg(id_ver.second.asText());
pkgIds << Package::splitToHumanReadable(val->asText());
}

return String(_E(1) "%1\n" _E(.)
Expand Down

0 comments on commit 48ab26c

Please sign in to comment.