]> git.lizzy.rs Git - dragonfireclient.git/blob - src/texture_override.h
Merge pull request #14 from corarona/master
[dragonfireclient.git] / src / texture_override.h
1 /*
2 Minetest
3 Copyright (C) 2020 Hugues Ross <hugues.ross@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes.h"
23 #include <string>
24 #include <vector>
25
26 //! Bitmask enum specifying what a texture override should apply to
27 enum class OverrideTarget : u8
28 {
29         INVALID = 0,
30         TOP = 1 << 0,
31         BOTTOM = 1 << 1,
32         LEFT = 1 << 2,
33         RIGHT = 1 << 3,
34         FRONT = 1 << 4,
35         BACK = 1 << 5,
36         INVENTORY = 1 << 6,
37         WIELD = 1 << 7,
38
39         SIDES = LEFT | RIGHT | FRONT | BACK,
40         ALL_FACES = TOP | BOTTOM | SIDES,
41         ITEM_TARGETS = INVENTORY | WIELD,
42 };
43
44 struct TextureOverride
45 {
46         std::string id;
47         std::string texture;
48         u8 target;
49
50         // Helper function for checking if an OverrideTarget is found in
51         // a TextureOverride without casting
52         inline bool hasTarget(OverrideTarget overrideTarget) const
53         {
54                 return (target & static_cast<u8>(overrideTarget)) != 0;
55         }
56 };
57
58 //! Class that provides texture override information from a texture pack
59 class TextureOverrideSource
60 {
61 public:
62         TextureOverrideSource(std::string filepath);
63
64         //! Get all overrides that apply to item definitions
65         std::vector<TextureOverride> getItemTextureOverrides();
66
67         //! Get all overrides that apply to node definitions
68         std::vector<TextureOverride> getNodeTileOverrides();
69
70 private:
71         std::vector<TextureOverride> m_overrides;
72 };