]> git.lizzy.rs Git - minetest.git/blob - src/luaentity_common.cpp
Disable word wrap in vertical texts in main menu
[minetest.git] / src / luaentity_common.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 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 #include "luaentity_common.h"
21
22 #include "utility.h"
23
24 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
25 #define PP2(x) "("<<(x).X<<","<<(x).Y<<")"
26
27 LuaEntityProperties::LuaEntityProperties():
28         hp_max(1),
29         physical(false),
30         weight(5),
31         collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
32         visual("sprite"),
33         visual_size(1,1),
34         spritediv(1,1),
35         initial_sprite_basepos(0,0)
36 {
37         textures.push_back("unknown_object.png");
38 }
39
40 std::string LuaEntityProperties::dump()
41 {
42         std::ostringstream os(std::ios::binary);
43         os<<"hp_max="<<hp_max;
44         os<<", physical="<<physical;
45         os<<", weight="<<weight;
46         os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
47         os<<", visual="<<visual;
48         os<<", visual_size="<<PP2(visual_size);
49         os<<", textures=[";
50         for(u32 i=0; i<textures.size(); i++){
51                 os<<"\""<<textures[i]<<"\" ";
52         }
53         os<<"]";
54         os<<", spritediv="<<PP2(spritediv);
55         os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
56         return os.str();
57 }
58
59 void LuaEntityProperties::serialize(std::ostream &os)
60 {
61         writeU8(os, 1); // version
62         writeS16(os, hp_max);
63         writeU8(os, physical);
64         writeF1000(os, weight);
65         writeV3F1000(os, collisionbox.MinEdge);
66         writeV3F1000(os, collisionbox.MaxEdge);
67         os<<serializeString(visual);
68         writeV2F1000(os, visual_size);
69         writeU16(os, textures.size());
70         for(u32 i=0; i<textures.size(); i++){
71                 os<<serializeString(textures[i]);
72         }
73         writeV2S16(os, spritediv);
74         writeV2S16(os, initial_sprite_basepos);
75 }
76
77 void LuaEntityProperties::deSerialize(std::istream &is)
78 {
79         int version = readU8(is);
80         if(version != 1) throw SerializationError(
81                         "unsupported LuaEntityProperties version");
82         hp_max = readS16(is);
83         physical = readU8(is);
84         weight = readF1000(is);
85         collisionbox.MinEdge = readV3F1000(is);
86         collisionbox.MaxEdge = readV3F1000(is);
87         visual = deSerializeString(is);
88         visual_size = readV2F1000(is);
89         textures.clear();
90         u32 texture_count = readU16(is);
91         for(u32 i=0; i<texture_count; i++){
92                 textures.push_back(deSerializeString(is));
93         }
94         spritediv = readV2S16(is);
95         initial_sprite_basepos = readV2S16(is);
96 }
97
98