d0eac612d0b541394451365bc2dc2dac133281fc
[supertux.git] / src / worldmap / direction.cpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "direction.hpp"
18
19 #include "util/log.hpp"
20
21 namespace WorldMapNS {
22
23 Direction reverse_dir(Direction direction)
24 {
25   switch(direction)
26   {
27     case D_WEST:
28       return D_EAST;
29     case D_EAST:
30       return D_WEST;
31     case D_NORTH:
32       return D_SOUTH;
33     case D_SOUTH:
34       return D_NORTH;
35     case D_NONE:
36       return D_NONE;
37   }
38   return D_NONE;
39 }
40
41 std::string
42 direction_to_string(Direction direction)
43 {
44   switch(direction)
45   {
46     case D_WEST:
47       return "west";
48     case D_EAST:
49       return "east";
50     case D_NORTH:
51       return "north";
52     case D_SOUTH:
53       return "south";
54     default:
55       return "none";
56   }
57 }
58
59 Direction
60 string_to_direction(const std::string& directory)
61 {
62   if (directory == "west")
63     return D_WEST;
64   else if (directory == "east")
65     return D_EAST;
66   else if (directory == "north")
67     return D_NORTH;
68   else if (directory == "south")
69     return D_SOUTH;
70   else if (directory == "none")
71     return D_NONE;
72   else {
73     log_warning << "unknown direction: \"" << directory << "\"" << std::endl;
74     return D_NONE;
75   }
76 }
77
78 } // namespace WorldMapNS
79
80 /* EOF */