]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodemetadata.h
forgot some files
[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 NodeMetadata
41 {
42 public:
43         typedef NodeMetadata* (*Factory)(std::istream&);
44
45         NodeMetadata();
46         virtual ~NodeMetadata();
47         
48         static NodeMetadata* deSerialize(std::istream &is);
49         void serialize(std::ostream &os);
50         
51         // This usually is the CONTENT_ value
52         virtual u16 typeId() const = 0;
53         virtual NodeMetadata* clone() = 0;
54         virtual void serializeBody(std::ostream &os) = 0;
55         virtual std::string infoText() { return "<todo: remove this text>"; }
56
57 protected:
58         static void registerType(u16 id, Factory f);
59 private:
60         static core::map<u16, Factory> m_types;
61 };
62
63 class SignNodeMetadata : public NodeMetadata
64 {
65 public:
66         SignNodeMetadata(std::string text);
67         //~SignNodeMetadata();
68         
69         virtual u16 typeId() const;
70         static NodeMetadata* create(std::istream &is);
71         virtual NodeMetadata* clone();
72         virtual void serializeBody(std::ostream &os);
73         virtual std::string infoText();
74
75         std::string getText(){ return m_text; }
76         void setText(std::string t){ m_text = t; }
77
78 private:
79         std::string m_text;
80 };
81
82 class NodeMetadataList
83 {
84 public:
85         ~NodeMetadataList();
86
87         void serialize(std::ostream &os);
88         void deSerialize(std::istream &is);
89         
90         // Get pointer to data
91         NodeMetadata* get(v3s16 p);
92         // Deletes data
93         void remove(v3s16 p);
94         // Deletes old data and sets a new one
95         void set(v3s16 p, NodeMetadata *d);
96 private:
97         core::map<v3s16, NodeMetadata*> m_data;
98 };
99
100 #endif
101