diff options
author | Hugues Ross <hugues.ross@gmail.com> | 2020-04-14 14:41:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-14 20:41:29 +0200 |
commit | 5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7 (patch) | |
tree | de590965f9f1cf68a4b6ee7ca802aaa5c0b987ee /src/texture_override.h | |
parent | 7e21b3cd4883eb8b9eb7e9ca49e50f6f0c7bc0d6 (diff) | |
download | hax-minetest-server-5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7.tar.gz hax-minetest-server-5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7.zip |
Refactor texture overrides and add new features (#9600)
* Refactor texture overrides, and add new features:
- Texture overrides can support multiple targets in one line
- Texture override files can have comment lines
- Item images/wield images can be overridden
* Formatting changes
* Address soime feedback
- Pass vectors by const reference
- Log syntax errors as warnings
- Remove 'C' prefix from TextureOverrideSource
* Simplify override target checks with an inline helper function
* make linter happy
* Apply feedback suggestions
Co-Authored-By: rubenwardy <rw@rubenwardy.com>
* Remove remaining != 0 checks
* Update copyright notice
Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: rubenwardy <rw@rubenwardy.com>
Diffstat (limited to '')
-rw-r--r-- | src/texture_override.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/texture_override.h b/src/texture_override.h new file mode 100644 index 000000000..db03bd014 --- /dev/null +++ b/src/texture_override.h @@ -0,0 +1,72 @@ +/* +Minetest +Copyright (C) 2020 Hugues Ross <hugues.ross@gmail.com> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "irrlichttypes.h" +#include <string> +#include <vector> + +//! Bitmask enum specifying what a texture override should apply to +enum class OverrideTarget : u8 +{ + INVALID = 0, + TOP = 1 << 0, + BOTTOM = 1 << 1, + LEFT = 1 << 2, + RIGHT = 1 << 3, + FRONT = 1 << 4, + BACK = 1 << 5, + INVENTORY = 1 << 6, + WIELD = 1 << 7, + + SIDES = LEFT | RIGHT | FRONT | BACK, + ALL_FACES = TOP | BOTTOM | SIDES, + ITEM_TARGETS = INVENTORY | WIELD, +}; + +struct TextureOverride +{ + std::string id; + std::string texture; + u8 target; + + // Helper function for checking if an OverrideTarget is found in + // a TextureOverride without casting + inline bool hasTarget(OverrideTarget overrideTarget) const + { + return (target & static_cast<u8>(overrideTarget)) != 0; + } +}; + +//! Class that provides texture override information from a texture pack +class TextureOverrideSource +{ +public: + TextureOverrideSource(std::string filepath); + + //! Get all overrides that apply to item definitions + std::vector<TextureOverride> getItemTextureOverrides(); + + //! Get all overrides that apply to node definitions + std::vector<TextureOverride> getNodeTileOverrides(); + +private: + std::vector<TextureOverride> m_overrides; +}; |