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.
20 #ifndef CRAFTDEF_HEADER
21 #define CRAFTDEF_HEADER
29 struct CraftPointerInput
32 std::vector<InventoryItem*> items;
34 CraftPointerInput(unsigned int width_, const std::vector<InventoryItem*> &items_):
42 unsigned int height() const{
43 return (items.size() + width - 1) / width;
50 std::vector<std::string> items;
52 CraftInput(unsigned int width_, const std::vector<std::string> &items_):
59 unsigned int height() const{
60 return (items.size() + width - 1) / width;
62 std::string dump() const;
65 struct CraftDefinition
71 CraftDefinition(const std::string &output_, unsigned int width_,
72 const std::vector<std::string> &input_):
77 std::string dump() const;
78 void serialize(std::ostream &os) const;
79 void deSerialize(std::istream &is);
82 class ICraftDefManager
86 virtual ~ICraftDefManager(){}
87 virtual InventoryItem* getCraftResult(const CraftPointerInput &input_cpi,
88 IGameDef *gamedef) const=0;
90 virtual void serialize(std::ostream &os)=0;
93 class IWritableCraftDefManager : public ICraftDefManager
96 IWritableCraftDefManager(){}
97 virtual ~IWritableCraftDefManager(){}
98 virtual InventoryItem* getCraftResult(const CraftPointerInput &input_cpi,
99 IGameDef *gamedef) const=0;
101 virtual void registerCraft(const CraftDefinition &def)=0;
102 virtual void clear()=0;
104 virtual void serialize(std::ostream &os)=0;
105 virtual void deSerialize(std::istream &is)=0;
108 IWritableCraftDefManager* createCraftDefManager();