texture_override.h 2.3 KB

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