Multi-thumbnail support in packages.
Allow multiple thumbnails per variant / package, including tagging with types so we can require certain thumbnails in the future.
This commit is contained in:
@@ -35,4 +35,9 @@
|
|||||||
exit(1); \
|
exit(1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SG_TEST_FAIL(msg) \
|
||||||
|
std::cerr << "failure:" << msg; \
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
|
||||||
#endif // of SG_MISC_TEST_MACROS_HXX
|
#endif // of SG_MISC_TEST_MACROS_HXX
|
||||||
|
|||||||
@@ -150,6 +150,43 @@ int parseTest()
|
|||||||
COMPARE(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p");
|
COMPARE(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p");
|
||||||
COMPARE(p2->description(), "A plane made by Cessna");
|
COMPARE(p2->description(), "A plane made by Cessna");
|
||||||
|
|
||||||
|
pkg::Package::ThumbnailVec thumbs = p2->thumbnailsForVariant(0);
|
||||||
|
COMPARE(thumbs.size(), 3);
|
||||||
|
|
||||||
|
auto index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Thumbnail& t)
|
||||||
|
{ return (t.type == pkg::Package::Thumbnail::Type::EXTERIOR); });
|
||||||
|
VERIFY(index != thumbs.end());
|
||||||
|
COMPARE(index->path, "thumb-exterior.png");
|
||||||
|
COMPARE(index->url, "http://foo.bar.com/thumb-exterior.png");
|
||||||
|
VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR);
|
||||||
|
|
||||||
|
index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Thumbnail& t)
|
||||||
|
{ return (t.type == pkg::Package::Thumbnail::Type::PANEL); });
|
||||||
|
VERIFY(index != thumbs.end());
|
||||||
|
COMPARE(index->path, "thumb-panel.png");
|
||||||
|
COMPARE(index->url, "http://foo.bar.com/thumb-panel.png");
|
||||||
|
VERIFY(index->type == pkg::Package::Thumbnail::Type::PANEL);
|
||||||
|
|
||||||
|
// test variants
|
||||||
|
try {
|
||||||
|
p2->indexOfVariant("fofofo");
|
||||||
|
SG_TEST_FAIL("lookup of non-existant variant did not throw");
|
||||||
|
} catch (sg_exception& e) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int skisVariant = p2->indexOfVariant("c172p-skis");
|
||||||
|
VERIFY(skisVariant > 0);
|
||||||
|
|
||||||
|
pkg::Package::ThumbnailVec thumbs2 = p2->thumbnailsForVariant(skisVariant);
|
||||||
|
COMPARE(thumbs2.size(), 2);
|
||||||
|
|
||||||
|
index = std::find_if(thumbs2.begin(), thumbs2.end(), [](const pkg::Package::Thumbnail& t)
|
||||||
|
{ return (t.type == pkg::Package::Thumbnail::Type::EXTERIOR); });
|
||||||
|
VERIFY(index != thumbs2.end());
|
||||||
|
COMPARE(index->path, "thumb-exterior-skis.png");
|
||||||
|
COMPARE(index->url, "http://foo.bar.com/thumb-exterior-skis.png");
|
||||||
|
VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR);
|
||||||
|
|
||||||
|
|
||||||
// test filtering / searching too
|
// test filtering / searching too
|
||||||
|
|||||||
@@ -338,6 +338,24 @@ std::string Package::nameForVariant(const std::string& vid) const
|
|||||||
throw sg_exception("Unknow variant +" + vid + " in package " + id());
|
throw sg_exception("Unknow variant +" + vid + " in package " + id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Package::indexOfVariant(const std::string& vid) const
|
||||||
|
{
|
||||||
|
if (vid == id()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int result = 1;
|
||||||
|
for (SGPropertyNode* var : m_props->getChildren("variant")) {
|
||||||
|
if (var->getStringValue("id") == vid) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw sg_exception("Unknow variant " + vid + " in package " + id());
|
||||||
|
}
|
||||||
|
|
||||||
std::string Package::nameForVariant(const unsigned int vIndex) const
|
std::string Package::nameForVariant(const unsigned int vIndex) const
|
||||||
{
|
{
|
||||||
if (vIndex == 0)
|
if (vIndex == 0)
|
||||||
@@ -351,6 +369,48 @@ std::string Package::nameForVariant(const unsigned int vIndex) const
|
|||||||
throw sg_exception("Unknow variant in package " + id());
|
throw sg_exception("Unknow variant in package " + id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Package::ThumbnailVec Package::thumbnailsForVariant(unsigned int vIndex) const
|
||||||
|
{
|
||||||
|
if (vIndex == 0) {
|
||||||
|
return thumbnailsFromProps(m_props);
|
||||||
|
}
|
||||||
|
|
||||||
|
SGPropertyNode_ptr var = m_props->getChild("variant", vIndex - 1);
|
||||||
|
if (!var) {
|
||||||
|
throw sg_exception("Unknow variant in package " + id());
|
||||||
|
}
|
||||||
|
|
||||||
|
return thumbnailsFromProps(var);
|
||||||
|
}
|
||||||
|
|
||||||
|
Package::Thumbnail::Type thumbnailTypeFromString(const std::string& s)
|
||||||
|
{
|
||||||
|
if (s == "exterior") return Package::Thumbnail::Type::EXTERIOR;
|
||||||
|
if (s == "interior") return Package::Thumbnail::Type::INTERIOR;
|
||||||
|
if (s == "panel") return Package::Thumbnail::Type::PANEL;
|
||||||
|
return Package::Thumbnail::Type::UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
Package::Thumbnail::Thumbnail(const std::string& aUrl, const std::string& aPath, Type aType) :
|
||||||
|
url(aUrl),
|
||||||
|
path(aPath),
|
||||||
|
type(aType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Package::ThumbnailVec Package::thumbnailsFromProps(const SGPropertyNode_ptr& ptr) const
|
||||||
|
{
|
||||||
|
ThumbnailVec result;
|
||||||
|
|
||||||
|
for (auto thumbNode : ptr->getChildren("thumbnail")) {
|
||||||
|
Thumbnail t(thumbNode->getStringValue("url"),
|
||||||
|
thumbNode->getStringValue("path"),
|
||||||
|
thumbnailTypeFromString(thumbNode->getStringValue("type")));
|
||||||
|
result.push_back(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // of namespace pkg
|
} // of namespace pkg
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
std::string qualifiedVariantId(const unsigned int variantIndex) const;
|
std::string qualifiedVariantId(const unsigned int variantIndex) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
unsigned int indexOfVariant(const std::string& vid) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* human-readable name - note this is probably not localised,
|
* human-readable name - note this is probably not localised,
|
||||||
* although this is not ruled out for the future.
|
* although this is not ruled out for the future.
|
||||||
@@ -134,6 +139,35 @@ public:
|
|||||||
*/
|
*/
|
||||||
string_list thumbnails() const;
|
string_list thumbnails() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* information about a thumbnail
|
||||||
|
*/
|
||||||
|
struct Thumbnail {
|
||||||
|
enum class Type
|
||||||
|
{
|
||||||
|
UNKNOWN,
|
||||||
|
PANEL,
|
||||||
|
INTERIOR,
|
||||||
|
EXTERIOR
|
||||||
|
|
||||||
|
// NIGHT / GROUND as modifiers? does this add any
|
||||||
|
// actual value for GUIs?
|
||||||
|
};
|
||||||
|
|
||||||
|
Thumbnail(const std::string& url, const std::string& path, Type ty = Type::UNKNOWN);
|
||||||
|
|
||||||
|
std::string url;
|
||||||
|
std::string path;
|
||||||
|
Type type = Type::UNKNOWN;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<Thumbnail> ThumbnailVec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieve all the thumbnails for a variant
|
||||||
|
*/
|
||||||
|
ThumbnailVec thumbnailsForVariant(unsigned int vIndex) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Packages we depend upon.
|
* Packages we depend upon.
|
||||||
* If the dependency list cannot be satisifed for some reason,
|
* If the dependency list cannot be satisifed for some reason,
|
||||||
@@ -160,6 +194,8 @@ private:
|
|||||||
|
|
||||||
std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
|
std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
|
||||||
|
|
||||||
|
ThumbnailVec thumbnailsFromProps(const SGPropertyNode_ptr& ptr) const;
|
||||||
|
|
||||||
SGPropertyNode_ptr m_props;
|
SGPropertyNode_ptr m_props;
|
||||||
std::string m_id;
|
std::string m_id;
|
||||||
string_set m_tags;
|
string_set m_tags;
|
||||||
|
|||||||
@@ -48,6 +48,23 @@
|
|||||||
<revision>10</revision>
|
<revision>10</revision>
|
||||||
</depends>
|
</depends>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>exterior</type>
|
||||||
|
<path>thumb-exterior.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-exterior.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>panel</type>
|
||||||
|
<path>thumb-panel.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<path>thumb-something.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-something.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
<variant>
|
<variant>
|
||||||
<id>c172p-2d-panel</id>
|
<id>c172p-2d-panel</id>
|
||||||
<name>C172 with 2d panel only</name>
|
<name>C172 with 2d panel only</name>
|
||||||
@@ -56,11 +73,35 @@
|
|||||||
<variant>
|
<variant>
|
||||||
<id>c172p-floats</id>
|
<id>c172p-floats</id>
|
||||||
<name>C172 with floats</name>
|
<name>C172 with floats</name>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>exterior</type>
|
||||||
|
<path>thumb-exterior-floats.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-exterior-floats.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>panel</type>
|
||||||
|
<path>thumb-panel.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||||
|
</thumbnail>
|
||||||
</variant>
|
</variant>
|
||||||
|
|
||||||
<variant>
|
<variant>
|
||||||
<id>c172p-skis</id>
|
<id>c172p-skis</id>
|
||||||
<name>C172 with skis</name>
|
<name>C172 with skis</name>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>exterior</type>
|
||||||
|
<path>thumb-exterior-skis.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-exterior-skis.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>panel</type>
|
||||||
|
<path>thumb-panel.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||||
|
</thumbnail>
|
||||||
</variant>
|
</variant>
|
||||||
|
|
||||||
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
|
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
|
||||||
@@ -99,6 +140,18 @@
|
|||||||
|
|
||||||
<md5>a94ca5704f305b90767f40617d194ed6</md5>
|
<md5>a94ca5704f305b90767f40617d194ed6</md5>
|
||||||
<url>http://localhost:2000/catalogTest1/b737.tar.gz</url>
|
<url>http://localhost:2000/catalogTest1/b737.tar.gz</url>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>exterior</type>
|
||||||
|
<path>thumb-exterior.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-exterior.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>panel</type>
|
||||||
|
<path>thumb-panel.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||||
|
</thumbnail>
|
||||||
</package>
|
</package>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,23 @@
|
|||||||
<revision>10</revision>
|
<revision>10</revision>
|
||||||
</depends>
|
</depends>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>exterior</type>
|
||||||
|
<path>thumb-exterior.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-exterior.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>panel</type>
|
||||||
|
<path>thumb-panel.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<path>thumb-something.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-something.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
<variant>
|
<variant>
|
||||||
<id>c172p-2d-panel</id>
|
<id>c172p-2d-panel</id>
|
||||||
<name>C172 with 2d panel only</name>
|
<name>C172 with 2d panel only</name>
|
||||||
@@ -56,11 +73,35 @@
|
|||||||
<variant>
|
<variant>
|
||||||
<id>c172p-floats</id>
|
<id>c172p-floats</id>
|
||||||
<name>C172 with floats</name>
|
<name>C172 with floats</name>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>exterior</type>
|
||||||
|
<path>thumb-exterior-floats.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-exterior-floats.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>panel</type>
|
||||||
|
<path>thumb-panel.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||||
|
</thumbnail>
|
||||||
</variant>
|
</variant>
|
||||||
|
|
||||||
<variant>
|
<variant>
|
||||||
<id>c172p-skis</id>
|
<id>c172p-skis</id>
|
||||||
<name>C172 with skis</name>
|
<name>C172 with skis</name>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>exterior</type>
|
||||||
|
<path>thumb-exterior-skis.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-exterior-skis.png</url>
|
||||||
|
</thumbnail>
|
||||||
|
|
||||||
|
<thumbnail>
|
||||||
|
<type>panel</type>
|
||||||
|
<path>thumb-panel.png</path>
|
||||||
|
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||||
|
</thumbnail>
|
||||||
</variant>
|
</variant>
|
||||||
|
|
||||||
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
|
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
|
||||||
|
|||||||
Reference in New Issue
Block a user