diff --git a/doomsday/sdk/libcore/include/de/filesys/package.h b/doomsday/sdk/libcore/include/de/filesys/package.h index ca485f5842..c6b5402b4c 100644 --- a/doomsday/sdk/libcore/include/de/filesys/package.h +++ b/doomsday/sdk/libcore/include/de/filesys/package.h @@ -168,6 +168,10 @@ class DENG2_PUBLIC Package : public IObject static QStringList tags(File const &packageFile); + static QStringList tags(String const& tagsString); + + static StringList requires(File const &packageFile); + /** * Splits a string containing a package identifier and version. The * expected format of the string is `{packageId}_{version}`. diff --git a/doomsday/sdk/libcore/src/filesys/package.cpp b/doomsday/sdk/libcore/src/filesys/package.cpp index 24e3130ed3..05fdc5afcc 100644 --- a/doomsday/sdk/libcore/src/filesys/package.cpp +++ b/doomsday/sdk/libcore/src/filesys/package.cpp @@ -31,6 +31,7 @@ String const Package::VAR_PACKAGE("package"); static String const PACKAGE_ORDER("package.__order__"); static String const PACKAGE_IMPORT_PATH("package.importPath"); +static String const PACKAGE_REQUIRES("package.requires"); static String const VAR_ID("ID"); static String const VAR_PATH("path"); @@ -328,8 +329,25 @@ Record &Package::initializeMetadata(File &packageFile, String const &id) QStringList Package::tags(File const &packageFile) { - return packageFile.objectNamespace().gets("package.tags") - .split(' ', QString::SkipEmptyParts); + return tags(packageFile.objectNamespace().gets(QStringLiteral("package.tags"))); +} + +QStringList Package::tags(String const &tagsString) +{ + return tagsString.split(' ', QString::SkipEmptyParts); +} + +StringList Package::requires(File const &packageFile) +{ + StringList ids; + if(packageFile.objectNamespace().has(PACKAGE_REQUIRES)) + { + for(auto const *value : packageFile.objectNamespace().geta(PACKAGE_REQUIRES).elements()) + { + ids << value->asText(); + } + } + return ids; } static String stripAfterFirstUnderscore(String str) diff --git a/doomsday/sdk/libcore/src/filesys/packageloader.cpp b/doomsday/sdk/libcore/src/filesys/packageloader.cpp index fdfbd91c08..a99a931d9b 100644 --- a/doomsday/sdk/libcore/src/filesys/packageloader.cpp +++ b/doomsday/sdk/libcore/src/filesys/packageloader.cpp @@ -201,6 +201,10 @@ DENG2_PIMPL(PackageLoader) loaded[packageId]->objectNamespace().gets("path") + "\""); } + // Loads all the packages listed as required for this package. Throws an + // exception is any are missing. + loadRequirements(source); + Package *pkg = new Package(source); loaded.insert(packageId, pkg); pkg->setOrder(loadCounter++); @@ -265,6 +269,17 @@ DENG2_PIMPL(PackageLoader) } } + void loadRequirements(File const &packageFile) + { + for(String const &reqId : Package::requires(packageFile)) + { + if(!self.isLoaded(reqId)) + { + self.load(reqId); + } + } + } + DENG2_PIMPL_AUDIENCE(Activity) DENG2_PIMPL_AUDIENCE(Load) DENG2_PIMPL_AUDIENCE(Unload)