summaryrefslogtreecommitdiff
path: root/assetFactory/style.h
blob: 8c64276925660cc394b31046d143665ac3885eb0 (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
#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 {};
	}

	static std::optional<std::reference_wrapper<const ColourAlpha>> getColour(const StyleStack & parents);

	ColourAlpha colour {};
	std::string texture;
	std::string textureRotation; // Multiples of 90deg, no int/enum support

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