diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-12 01:29:38 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-12 19:43:14 +0000 |
commit | 0d5b57f31e17b8e46979d8c29b5a3205fbdbd44b (patch) | |
tree | a57e81a59d67c599f1253a16459d7dee1ec3fa1f /assetFactory/style.cpp | |
parent | Support loading texture references into faces (diff) | |
download | ilt-0d5b57f31e17b8e46979d8c29b5a3205fbdbd44b.tar.bz2 ilt-0d5b57f31e17b8e46979d8c29b5a3205fbdbd44b.tar.xz ilt-0d5b57f31e17b8e46979d8c29b5a3205fbdbd44b.zip |
Dedupe looking up the style stack for colour
Diffstat (limited to 'assetFactory/style.cpp')
-rw-r--r-- | assetFactory/style.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index 5303d96..fa585ac 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -4,11 +4,7 @@ void Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const Shape::CreatedFaces & faces) const { - if (const auto effectiveColour = getProperty(parents, &Style::colour, - [](auto && style) { - return style->colour.a > 0; - }); - effectiveColour.has_value()) { + if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) { for (const auto & face : faces) { mesh.set_color(face.second, effectiveColour->get()); } @@ -18,15 +14,19 @@ Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const Sha void Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const ModelFactoryMesh::FaceHandle & face) const { - if (const auto effectiveColour = getProperty(parents, &Style::colour, - [](auto && style) { - return style->colour.a > 0; - }); - effectiveColour.has_value()) { + if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) { mesh.set_color(face, effectiveColour->get()); } } +std::optional<std::reference_wrapper<const Style::ColourAlpha>> +Style::getColour(const StyleStack & parents) +{ + return getProperty(parents, &Style::colour, [](auto && style) { + return style->colour.a > 0; + }); +} + bool Style::persist(Persistence::PersistenceStore & store) { |