/* Minetest Copyright (C) 2023 cx384 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 #include #include "itemgroup.h" #include #include "irrlichttypes.h" enum class PointabilityType : u8 { // Can be pointed through. // Note: This MUST be the 0-th item in the enum for backwards compat. // Older Minetest versions send "pointable=false" as "0". POINTABLE_NOT, // Is pointable. // Note: This MUST be the 1-th item in the enum for backwards compat: // Older Minetest versions send "pointable=true" as "1". POINTABLE, // Note: Since (u8) 2 is truthy, // older clients will understand this as "pointable=true", // which is a reasonable fallback. POINTABLE_BLOCKING, }; // An object to store overridden pointable properties struct Pointabilities { // Nodes std::unordered_map nodes; std::unordered_map node_groups; // Objects std::unordered_map objects; std::unordered_map object_groups; // armor_groups // Match functions return fitting pointability, // otherwise the default pointability should be used. std::optional matchNode(const std::string &name, const ItemGroupList &groups) const; std::optional matchObject(const std::string &name, const ItemGroupList &groups) const; // For players only armor groups will work std::optional matchPlayer(const ItemGroupList &groups) const; void serialize(std::ostream &os) const; void deSerialize(std::istream &is); // For a save enum conversion. static PointabilityType deSerializePointabilityType(std::istream &is); static void serializePointabilityType(std::ostream &os, PointabilityType pointable_type); static std::string toStringPointabilityType(PointabilityType pointable_type); private: static std::optional matchGroups(const ItemGroupList &groups, const std::unordered_map &pointable_groups); static void serializeTypeMap(std::ostream &os, const std::unordered_map &map); static void deSerializeTypeMap(std::istream &is, std::unordered_map &map); };