summaryrefslogtreecommitdiff
path: root/assetFactory/style.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-02-27 23:56:03 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-02-27 23:56:03 +0000
commit5c703a1549b88339ca48ac3c48f67ab7503d223a (patch)
treed56cb2b44002c14ea0dcc57605a83895b2ff1da8 /assetFactory/style.cpp
parentLoad the X11 RGB colour definitions into a map (diff)
downloadilt-5c703a1549b88339ca48ac3c48f67ab7503d223a.tar.bz2
ilt-5c703a1549b88339ca48ac3c48f67ab7503d223a.tar.xz
ilt-5c703a1549b88339ca48ac3c48f67ab7503d223a.zip
Support for named colours in assets
Fixes up some error handling in colour parser.
Diffstat (limited to 'assetFactory/style.cpp')
-rw-r--r--assetFactory/style.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp
index 099d81a..d2977a7 100644
--- a/assetFactory/style.cpp
+++ b/assetFactory/style.cpp
@@ -1,12 +1,16 @@
#include "style.h"
+#include "assetFactory.h"
ModelFactoryMesh::Color
Style::parseColour(const std::string_view & in)
{
if (in.empty()) {
- return {};
+ throw std::runtime_error("Empty colour specification");
}
if (in[0] == '#') {
+ if (in.length() > 9 || in.length() % 2 == 0) {
+ throw std::runtime_error("Invalid hex colour specification");
+ }
ModelFactoryMesh::Color out {0, 0, 0, 1};
std::generate_n(out.begin(), (in.length() - 1) / 2, [in = in.data() + 1]() mutable {
uint8_t channel;
@@ -16,7 +20,13 @@ Style::parseColour(const std::string_view & in)
});
return out;
}
- return {};
+ if (auto mf = std::dynamic_pointer_cast<const AssetFactory>(Persistence::sharedObjects.at("assetFactory"))) {
+ if (const auto colour = mf->colours.find(in); colour != mf->colours.end()) {
+ const auto out = glm::vec3 {colour->second} / 256.F;
+ return {out.r, out.g, out.b, 1.f};
+ }
+ }
+ throw std::runtime_error("No such asset factory colour");
}
void