3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2011 Kahrl <kahrl@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef ITEMDEF_HEADER
22 #define ITEMDEF_HEADER
24 #include "common_irrlicht.h"
30 struct ToolCapabilities;
36 static inline int itemgroup_get(const std::map<std::string, int> &groups,
37 const std::string &name)
39 std::map<std::string, int>::const_iterator i = groups.find(name);
63 std::string name; // "" = hand
64 std::string description; // Shown in tooltip.
69 std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
70 std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
74 Item stack and interaction properties
78 bool liquids_pointable;
79 // May be NULL. If non-NULL, deleted by destructor
80 ToolCapabilities *tool_capabilities;
81 std::map<std::string, int> groups;
87 video::ITexture *inventory_texture;
88 scene::IMesh *wield_mesh;
95 ItemDefinition(const ItemDefinition &def);
96 ItemDefinition& operator=(const ItemDefinition &def);
99 void serialize(std::ostream &os) const;
100 void deSerialize(std::istream &is);
105 class IItemDefManager
109 virtual ~IItemDefManager(){}
111 // Get item definition
112 virtual const ItemDefinition& get(const std::string &name) const=0;
113 // Get alias definition
114 virtual std::string getAlias(const std::string &name) const=0;
115 // Get set of all defined item names and aliases
116 virtual std::set<std::string> getAll() const=0;
117 // Check if item is known
118 virtual bool isKnown(const std::string &name) const=0;
120 virtual void serialize(std::ostream &os)=0;
123 class IWritableItemDefManager : public IItemDefManager
126 IWritableItemDefManager(){}
127 virtual ~IWritableItemDefManager(){}
129 // Get item definition
130 virtual const ItemDefinition& get(const std::string &name) const=0;
131 // Get alias definition
132 virtual std::string getAlias(const std::string &name) const=0;
133 // Get set of all defined item names and aliases
134 virtual std::set<std::string> getAll() const=0;
135 // Check if item is known
136 virtual bool isKnown(const std::string &name) const=0;
138 // Remove all registered item and node definitions and aliases
139 // Then re-add the builtin item definitions
140 virtual void clear()=0;
141 // Register item definition
142 virtual void registerItem(const ItemDefinition &def)=0;
143 // Set an alias so that items named <name> will load as <convert_to>.
144 // Alias is not set if <name> has already been defined.
145 // Alias will be removed if <name> is defined at a later point of time.
146 virtual void registerAlias(const std::string &name,
147 const std::string &convert_to)=0;
150 Update inventory textures and wield meshes to latest
151 return values of ITextureSource and INodeDefManager.
152 Call after updating the texture atlas of a texture source.
154 virtual void updateTexturesAndMeshes(IGameDef *gamedef)=0;
156 virtual void serialize(std::ostream &os)=0;
157 virtual void deSerialize(std::istream &is)=0;
160 IWritableItemDefManager* createItemDefManager();