3 Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "irrlichttypes.h"
25 class CToolDefManager: public IWritableToolDefManager
28 virtual ~CToolDefManager()
30 for(core::map<std::string, ToolDefinition*>::Iterator
31 i = m_tool_definitions.getIterator();
32 i.atEnd() == false; i++){
33 delete i.getNode()->getValue();
36 virtual const ToolDefinition* getToolDefinition(const std::string &toolname) const
38 core::map<std::string, ToolDefinition*>::Node *n;
39 n = m_tool_definitions.find(toolname);
44 virtual std::string getImagename(const std::string &toolname) const
46 const ToolDefinition *def = getToolDefinition(toolname);
49 return def->imagename;
51 virtual ToolDiggingProperties getDiggingProperties(
52 const std::string &toolname) const
54 const ToolDefinition *def = getToolDefinition(toolname);
55 // If tool does not exist, just return an impossible
57 // If tool does not exist, try empty name
58 const ToolDefinition *def = getToolDefinition("");
59 if(def == NULL) // If that doesn't exist either, return default
60 return ToolDiggingProperties();
61 return def->properties;
63 return def->properties;
65 virtual bool registerTool(std::string toolname, const ToolDefinition &def)
67 infostream<<"registerTool: registering tool \""<<toolname<<"\""<<std::endl;
68 core::map<std::string, ToolDefinition*>::Node *n;
69 n = m_tool_definitions.find(toolname);
71 errorstream<<"registerTool: registering tool \""<<toolname
72 <<"\" failed: name is already registered"<<std::endl;
75 m_tool_definitions[toolname] = new ToolDefinition(def);
80 core::map<std::string, ToolDefinition*> m_tool_definitions;
83 IWritableToolDefManager* createToolDefManager()
85 return new CToolDefManager();