| 134 | } |
| 135 | |
| 136 | std::shared_ptr<Texture> CoronaLoader::loadMap(const Ref<XML>& xml) |
| 137 | { |
| 138 | /* process map node */ |
| 139 | if (xml->name == "map") |
| 140 | { |
| 141 | std::string mapClass = xml->parm("class"); |
| 142 | |
| 143 | /* load textures */ |
| 144 | if (mapClass == "Texture") |
| 145 | { |
| 146 | const FileName src = load<FileName>(xml->child("image")); |
| 147 | |
| 148 | /* load images only once */ |
| 149 | if (textureFileMap.find(src) != textureFileMap.end()) |
| 150 | return textureFileMap[src]; |
| 151 | |
| 152 | try { |
| 153 | return Texture::load(path+src); |
| 154 | } catch (const std::runtime_error& e) { |
| 155 | std::cerr << "failed to load " << path+src << ": " << e.what() << std::endl; |
| 156 | } |
| 157 | } |
| 158 | else if (mapClass == "Reference") { |
| 159 | const std::string name = load<std::string>(xml); |
| 160 | return textureMap[name]; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /* recurse into every unknown node to find some texture */ |
| 165 | for (auto& child : xml->children) { |
| 166 | std::shared_ptr<Texture> texture = loadMap(child); |
| 167 | if (texture) return texture; |
| 168 | } |
| 169 | return std::shared_ptr<Texture>(); |
| 170 | } |
| 171 | |
| 172 | void CoronaLoader::loadMapDefinition(const Ref<XML>& xml) |
| 173 | { |