texture_override.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. SIDES = LEFT | RIGHT | FRONT | BACK,
  40. ALL_FACES = TOP | BOTTOM | SIDES,
  41. ALL_SPECIAL = SPECIAL_1 | SPECIAL_2 | SPECIAL_3 | SPECIAL_4 | SPECIAL_5 | SPECIAL_6,
  42. NODE_TARGETS = ALL_FACES | ALL_SPECIAL,
  43. ITEM_TARGETS = INVENTORY | WIELD,
  44. };
  45. struct TextureOverride
  46. {
  47. std::string id;
  48. std::string texture;
  49. override_t target = 0;
  50. u8 world_scale = 0;
  51. // Helper function for checking if an OverrideTarget is found in
  52. // a TextureOverride without casting
  53. inline bool hasTarget(OverrideTarget overrideTarget) const
  54. {
  55. return (target & static_cast<override_t>(overrideTarget)) != 0;
  56. }
  57. };
  58. //! Class that provides texture override information from a texture pack
  59. class TextureOverrideSource
  60. {
  61. public:
  62. TextureOverrideSource(const std::string &filepath);
  63. //! Get all overrides that apply to item definitions
  64. std::vector<TextureOverride> getItemTextureOverrides() const;
  65. //! Get all overrides that apply to node definitions
  66. std::vector<TextureOverride> getNodeTileOverrides() const;
  67. private:
  68. std::vector<TextureOverride> m_overrides;
  69. };