initial commit, lordsawar source, slightly modified
[lordsawar] / src / SmallTile.cpp
1 // Copyright (C) 2008, 2009 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #include "SmallTile.h"
19 #include <iostream>
20
21 std::string SmallTile::d_tag = "smallmap";
22
23 using namespace std;
24
25 SmallTile::SmallTile()
26 {
27   d_pattern = SOLID;
28   d_color.set_rgb_p(80.0/255.0,172.0/255.0,28.0/255.0);
29   d_second_color.set_rgb_p(0,0,0);
30   d_third_color.set_rgb_p(0,0,0);
31 }
32
33 SmallTile::SmallTile(XML_Helper* helper)
34 {
35   helper->getData(d_color, "color");
36
37   guint32 i;
38   helper->getData(i, "pattern");
39   SmallTile::Pattern pattern = static_cast<SmallTile::Pattern>(i);
40   setPattern(pattern);
41
42   if (pattern != SOLID)
43     {
44       helper->getData(d_second_color, "2nd_color");
45       if (pattern != STIPPLED && pattern != SUNKEN)
46         helper->getData(d_third_color, "3rd_color");
47     }
48 }
49
50 bool SmallTile::save(XML_Helper *helper) const
51 {
52   bool retval = true;
53
54   retval &= helper->openTag(d_tag);
55   retval &= helper->saveData("pattern", d_pattern);
56   switch (d_pattern)
57     {
58       //patterns with a single colour
59     case SOLID:
60       retval &= helper->saveData("color", d_color);
61       break;
62       //patterns with two colours
63     case STIPPLED: case SUNKEN:
64       retval &= helper->saveData("color", d_color);
65       retval &= helper->saveData("2nd_color", d_second_color);
66       break;
67       //patterns with three colours
68     case RANDOMIZED: case TABLECLOTH: case DIAGONAL: case CROSSHATCH:
69     case SUNKEN_STRIPED:
70       retval &= helper->saveData("color", d_color);
71       retval &= helper->saveData("2nd_color", d_second_color);
72       retval &= helper->saveData("3rd_color", d_third_color);
73       break;
74     }
75   retval &= helper->closeTag();
76
77   return retval;
78 }
79
80 SmallTile::~SmallTile()
81 {
82 }
83
84 // End of file