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 IToolDefManager
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 bool registerTool(std::string toolname, const ToolDefinition &def)
38 infostream<<"registerTool: registering tool \""<<toolname<<"\""<<std::endl;
39 core::map<std::string, ToolDefinition*>::Node *n;
40 n = m_tool_definitions.find(toolname);
42 errorstream<<"registerTool: registering tool \""<<toolname
43 <<"\" failed: name is already registered"<<std::endl;
46 m_tool_definitions[toolname] = new ToolDefinition(def);
49 virtual ToolDefinition* getToolDefinition(const std::string &toolname)
51 core::map<std::string, ToolDefinition*>::Node *n;
52 n = m_tool_definitions.find(toolname);
57 virtual std::string getImagename(const std::string &toolname)
59 ToolDefinition *def = getToolDefinition(toolname);
62 return def->imagename;
64 virtual ToolDiggingProperties getDiggingProperties(
65 const std::string &toolname)
67 ToolDefinition *def = getToolDefinition(toolname);
68 // If tool does not exist, just return an impossible
70 // If tool does not exist, try empty name
71 ToolDefinition *def = getToolDefinition("");
72 if(def == NULL) // If that doesn't exist either, return default
73 return ToolDiggingProperties();
74 return def->properties;
76 return def->properties;
80 core::map<std::string, ToolDefinition*> m_tool_definitions;
83 IToolDefManager* createToolDefManager()
85 return new CToolDefManager();