summaryrefslogtreecommitdiff
path: root/assetFactory/style.cpp
blob: b5ddcf15f0f5bd3ad355921f01169b85582fe3de (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
47
48
49
50
51
#include "style.h"
#include "assetFactory.h"

void
Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const Shape::CreatedFaces & faces) const
{
	for (const auto & face : faces) {
		applyStyle(mesh, face.second, getColour(parents));
	}
}

void
Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const ModelFactoryMesh::FaceHandle & face) const
{
	applyStyle(mesh, face, getColour(parents));
}

void
Style::applyStyle(
		ModelFactoryMesh & mesh, const ModelFactoryMesh::FaceHandle & face, EffectiveColour effectiveColour) const
{
	if (effectiveColour.has_value()) {
		mesh.set_color(face, effectiveColour->get());
	}
}

Style::EffectiveColour
Style::getColour(const StyleStack & parents)
{
	return getProperty(parents, &Style::colour, [](auto && style) {
		return style->colour.a > 0;
	});
}

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);
}