summary refs log tree commit diff stats
path: root/src/world.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/world.cpp b/src/world.cpp index 9b1e4f6..3b6bd41 100644 --- a/src/world.cpp +++ b/src/world.cpp
@@ -63,6 +63,10 @@ World::World(std::string filename)
63 xmlFree(key); 63 xmlFree(key);
64 64
65 std::vector<int> mapTiles; 65 std::vector<int> mapTiles;
66 Map::Adjacent leftAdj;
67 Map::Adjacent rightAdj;
68 Map::Adjacent upAdj;
69 Map::Adjacent downAdj;
66 70
67 for (xmlNodePtr mapNode = node->xmlChildrenNode; 71 for (xmlNodePtr mapNode = node->xmlChildrenNode;
68 mapNode != nullptr; 72 mapNode != nullptr;
@@ -82,6 +86,54 @@ World::World(std::string filename)
82 } 86 }
83 87
84 xmlFree(key); 88 xmlFree(key);
89 } else if (!xmlStrcmp(
90 mapNode->name,
91 reinterpret_cast<const xmlChar*>("adjacent")))
92 {
93 key = getProp(mapNode, "type");
94 std::string adjTypeStr(reinterpret_cast<char*>(key));
95 xmlFree(key);
96
97 Map::Adjacent::Type adjType;
98 if (adjTypeStr == "wall")
99 {
100 adjType = Map::Adjacent::Type::wall;
101 } else if (adjTypeStr == "wrap")
102 {
103 adjType = Map::Adjacent::Type::wrap;
104 } else if (adjTypeStr == "warp")
105 {
106 adjType = Map::Adjacent::Type::warp;
107 } else if (adjTypeStr == "reverseWarp")
108 {
109 adjType = Map::Adjacent::Type::reverse;
110 } else {
111 throw std::logic_error("Invalid adjacency type");
112 }
113
114 key = getProp(mapNode, "map");
115 int adjMapId = atoi(reinterpret_cast<char*>(key));
116 xmlFree(key);
117
118 key = getProp(mapNode, "dir");
119 std::string adjDir(reinterpret_cast<char*>(key));
120 xmlFree(key);
121
122 if (adjDir == "left")
123 {
124 leftAdj = {adjType, adjMapId};
125 } else if (adjDir == "right")
126 {
127 rightAdj = {adjType, adjMapId};
128 } else if (adjDir == "up")
129 {
130 upAdj = {adjType, adjMapId};
131 } else if (adjDir == "down")
132 {
133 downAdj = {adjType, adjMapId};
134 } else {
135 throw std::logic_error("Invalid adjacency direction");
136 }
85 } 137 }
86 } 138 }
87 139
@@ -91,7 +143,11 @@ World::World(std::string filename)
91 std::forward_as_tuple( 143 std::forward_as_tuple(
92 mapId, 144 mapId,
93 std::move(mapTiles), 145 std::move(mapTiles),
94 std::move(mapTitle))); 146 std::move(mapTitle),
147 leftAdj,
148 rightAdj,
149 upAdj,
150 downAdj));
95 } 151 }
96 } 152 }
97 153