]> git.lizzy.rs Git - minetest-m13.git/blob - src/itemdef.h
ed01b1b6f727331cf04c302e7a44146576a36072
[minetest-m13.git] / src / itemdef.h
1 /*
2 Minetest-m13
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2011 Kahrl <kahrl@gmx.net>
5
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.
10
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.
15
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.
19 */
20
21 #ifndef ITEMDEF_HEADER
22 #define ITEMDEF_HEADER
23
24 #include "common_irrlicht.h"
25 #include <string>
26 #include <iostream>
27 #include <set>
28 class IGameDef;
29 struct ToolDiggingProperties;
30
31 /*
32         Base item definition
33 */
34
35 enum ItemType
36 {
37         ITEM_NONE,
38         ITEM_NODE,
39         ITEM_CRAFT,
40         ITEM_TOOL,
41 };
42
43 struct ItemDefinition
44 {
45         /*
46                 Basic item properties
47         */
48         ItemType type;
49         std::string name; // "" = hand
50         std::string description; // Shown in tooltip.
51
52         /*
53                 Visual properties
54         */
55         std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
56         std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
57         v3f wield_scale;
58
59         /*
60                 Item stack and interaction properties
61         */
62         s16 stack_max;
63         bool usable;
64         bool liquids_pointable;
65         // May be NULL. If non-NULL, deleted by destructor
66         ToolDiggingProperties *tool_digging_properties;
67
68         /*
69                 Cached stuff
70         */
71 #ifndef SERVER
72         video::ITexture *inventory_texture;
73         scene::IMesh *wield_mesh;
74 #endif
75
76         /*
77                 Some helpful methods
78         */
79         ItemDefinition();
80         ItemDefinition(const ItemDefinition &def);
81         ItemDefinition& operator=(const ItemDefinition &def);
82         ~ItemDefinition();
83         void reset();
84         void serialize(std::ostream &os) const;
85         void deSerialize(std::istream &is);
86 private:
87         void resetInitial();
88 };
89
90 class IItemDefManager
91 {
92 public:
93         IItemDefManager(){}
94         virtual ~IItemDefManager(){}
95
96         // Get item definition
97         virtual const ItemDefinition& get(const std::string &name) const=0;
98         // Get alias definition
99         virtual std::string getAlias(const std::string &name) const=0;
100         // Get set of all defined item names and aliases
101         virtual std::set<std::string> getAll() const=0;
102         // Check if item is known
103         virtual bool isKnown(const std::string &name) const=0;
104
105         virtual void serialize(std::ostream &os)=0;
106 };
107
108 class IWritableItemDefManager : public IItemDefManager
109 {
110 public:
111         IWritableItemDefManager(){}
112         virtual ~IWritableItemDefManager(){}
113
114         // Get item definition
115         virtual const ItemDefinition& get(const std::string &name) const=0;
116         // Get alias definition
117         virtual std::string getAlias(const std::string &name) const=0;
118         // Get set of all defined item names and aliases
119         virtual std::set<std::string> getAll() const=0;
120         // Check if item is known
121         virtual bool isKnown(const std::string &name) const=0;
122
123         // Remove all registered item and node definitions and aliases
124         // Then re-add the builtin item definitions
125         virtual void clear()=0;
126         // Register item definition
127         virtual void registerItem(const ItemDefinition &def)=0;
128         // Set an alias so that items named <name> will load as <convert_to>.
129         // Alias is not set if <name> has already been defined.
130         // Alias will be removed if <name> is defined at a later point of time.
131         virtual void registerAlias(const std::string &name,
132                         const std::string &convert_to)=0;
133
134         /*
135                 Update inventory textures and wield meshes to latest
136                 return values of ITextureSource and INodeDefManager.
137                 Call after updating the texture atlas of a texture source.
138         */
139         virtual void updateTexturesAndMeshes(IGameDef *gamedef)=0;
140
141         virtual void serialize(std::ostream &os)=0;
142         virtual void deSerialize(std::istream &is)=0;
143 };
144
145 IWritableItemDefManager* createItemDefManager();
146
147 #endif