summaryrefslogtreecommitdiff
path: root/assetFactory/style.h
blob: e8fd012b3e54bbf251e1e110e161d60380ff8133 (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
#pragma once

#include "modelFactoryMesh.h"
#include "persistence.h"
#include "shape.h"
#include <optional>
#include <string>
#include <utility>

class Style {
public:
	using StyleStack = std::vector<const Style *>;
	using Colour = glm::vec3;
	using ColourAlpha = glm::vec4;

	void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const Shape::CreatedFaces &) const;
	void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const ModelFactoryMesh::FaceHandle &) const;

	template<typename T>
	static std::optional<std::reference_wrapper<const T>>
	getProperty(const StyleStack & parents, T Style::*member, auto && test)
	{
		if (const auto itr = std::find_if(parents.rbegin(), parents.rend(), std::forward<decltype(test)>(test));
				itr != parents.rend()) {
			return (*itr)->*member;
		}
		return {};
	}

	ColourAlpha colour {};

protected:
	bool persist(Persistence::PersistenceStore & store);
};