MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / load

Method load

source/traps/TrapManager.cpp:304–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304Trap* 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
342void TrapManager::dispose(const Trap* trap)
343{

Callers

nothing calls this directly

Calls 2

getTrapFromStreamMethod · 0.45
importFromStreamMethod · 0.45

Tested by

no test coverage detected