]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodemetadata.h
Modified windows build parameters a bit to make it build
[dragonfireclient.git] / src / nodemetadata.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef NODEMETADATA_HEADER
21 #define NODEMETADATA_HEADER
22
23 #include "common_irrlicht.h"
24 #include <string>
25 #include <iostream>
26
27 /*
28         Used for storing:
29
30         Oven:
31                 - Item that is being burned
32                 - Burning time
33                 - Item stack that is being heated
34                 - Result item stack
35         
36         Sign:
37                 - Text
38 */
39
40 class Inventory;
41
42 class NodeMetadata
43 {
44 public:
45         typedef NodeMetadata* (*Factory)(std::istream&);
46
47         NodeMetadata();
48         virtual ~NodeMetadata();
49         
50         static NodeMetadata* deSerialize(std::istream &is);
51         void serialize(std::ostream &os);
52         
53         // This usually is the CONTENT_ value
54         virtual u16 typeId() const = 0;
55         virtual NodeMetadata* clone() = 0;
56         virtual void serializeBody(std::ostream &os) = 0;
57         virtual std::string infoText() {return "<todo: remove this text>";}
58         virtual Inventory* getInventory() {return NULL;}
59
60 protected:
61         static void registerType(u16 id, Factory f);
62 private:
63         static core::map<u16, Factory> m_types;
64 };
65
66 class SignNodeMetadata : public NodeMetadata
67 {
68 public:
69         SignNodeMetadata(std::string text);
70         //~SignNodeMetadata();
71         
72         virtual u16 typeId() const;
73         static NodeMetadata* create(std::istream &is);
74         virtual NodeMetadata* clone();
75         virtual void serializeBody(std::ostream &os);
76         virtual std::string infoText();
77
78         std::string getText(){ return m_text; }
79         void setText(std::string t){ m_text = t; }
80
81 private:
82         std::string m_text;
83 };
84
85 class ChestNodeMetadata : public NodeMetadata
86 {
87 public:
88         ChestNodeMetadata();
89         ~ChestNodeMetadata();
90         
91         virtual u16 typeId() const;
92         static NodeMetadata* create(std::istream &is);
93         virtual NodeMetadata* clone();
94         virtual void serializeBody(std::ostream &os);
95         virtual std::string infoText();
96         virtual Inventory* getInventory() {return m_inventory;}
97
98 private:
99         Inventory *m_inventory;
100 };
101
102 class NodeMetadataList
103 {
104 public:
105         ~NodeMetadataList();
106
107         void serialize(std::ostream &os);
108         void deSerialize(std::istream &is);
109         
110         // Get pointer to data
111         NodeMetadata* get(v3s16 p);
112         // Deletes data
113         void remove(v3s16 p);
114         // Deletes old data and sets a new one
115         void set(v3s16 p, NodeMetadata *d);
116 private:
117         core::map<v3s16, NodeMetadata*> m_data;
118 };
119
120 #endif
121