summaryrefslogtreecommitdiff
path: root/assetFactory/style.cpp
blob: 5303d96cfe81a0edf82fe6fafad21c0ac5c16a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "style.h"
#include "assetFactory.h"

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()) {
		for (const auto & face : faces) {
			mesh.set_color(face.second, effectiveColour->get());
		}
	}
}

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()) {
		mesh.set_color(face, effectiveColour->get());
	}
}

bool
Style::persist(Persistence::PersistenceStore & store)
{
	struct ColourParser : public Persistence::SelectionV<ColourAlpha> {
		using Persistence::SelectionV<ColourAlpha>::SelectionV;
		using Persistence::SelectionV<ColourAlpha>::setValue;
		void
		setValue(std::string && str) override
		{
			if (auto mf = Persistence::ParseBase::getShared<const AssetFactory>("assetFactory")) {
				v = mf->parseColour(str);
			}
		}
	};

	return STORE_HELPER(colour, ColourParser) && STORE_MEMBER(texture) && STORE_MEMBER(textureRotation);
}