| 302 | } |
| 303 | |
| 304 | Trap* TrapManager::load(GameMap* gameMap, std::istream& is) |
| 305 | { |
| 306 | if(!is.good()) |
| 307 | return nullptr; |
| 308 | |
| 309 | std::vector<const TrapFactory*>& factories = getFactories(); |
| 310 | std::string nextParam; |
| 311 | OD_ASSERT_TRUE(is >> nextParam); |
| 312 | const TrapFactory* factoryToUse = nullptr; |
| 313 | for(const TrapFactory* factory : factories) |
| 314 | { |
| 315 | if(factory == nullptr) |
| 316 | continue; |
| 317 | |
| 318 | if(factory->getName().compare(nextParam) != 0) |
| 319 | continue; |
| 320 | |
| 321 | factoryToUse = factory; |
| 322 | break; |
| 323 | } |
| 324 | |
| 325 | if(factoryToUse == nullptr) |
| 326 | { |
| 327 | OD_LOG_ERR("Unknown Trap type=" + nextParam); |
| 328 | return nullptr; |
| 329 | } |
| 330 | |
| 331 | Trap* trap = factoryToUse->getTrapFromStream(gameMap, is); |
| 332 | if(!trap->importFromStream(is)) |
| 333 | { |
| 334 | OD_LOG_ERR("Couldn't load creature Trap type=" + nextParam); |
| 335 | delete trap; |
| 336 | return nullptr; |
| 337 | } |
| 338 | |
| 339 | return trap; |
| 340 | } |
| 341 | |
| 342 | void TrapManager::dispose(const Trap* trap) |
| 343 | { |
nothing calls this directly
no test coverage detected