Write the Components from a single Objective to the underlying entity
| 468 | |
| 469 | // Write the Components from a single Objective to the underlying entity |
| 470 | void ObjectiveEntity::writeComponents(Entity* entity, |
| 471 | const std::string& keyPrefix, const Objective& obj |
| 472 | ) |
| 473 | { |
| 474 | assert(entity != NULL); |
| 475 | |
| 476 | for (Objective::ComponentMap::const_iterator i = obj.components.begin(); |
| 477 | i != obj.components.end(); |
| 478 | ++i) |
| 479 | { |
| 480 | const Component& c = i->second; |
| 481 | |
| 482 | // Component prefix is like obj1_2_blah |
| 483 | std::string prefix = keyPrefix + string::to_string(i->first) + "_"; |
| 484 | |
| 485 | // Write out Component keyvals |
| 486 | entity->setKeyValue(prefix + "state", c.isSatisfied() ? "1" : "0"); |
| 487 | entity->setKeyValue(prefix + "not", c.isInverted() ? "1" : "0"); |
| 488 | entity->setKeyValue(prefix + "irreversible", c.isIrreversible() ? "1": "0"); |
| 489 | entity->setKeyValue(prefix + "player_responsible", c.isPlayerResponsible() ? "1" : "0"); |
| 490 | entity->setKeyValue(prefix + "type", c.getType().getName()); |
| 491 | |
| 492 | entity->setKeyValue(prefix + "clock_interval", |
| 493 | c.getClockInterval() > 0 ? string::to_string(c.getClockInterval()) : ""); |
| 494 | |
| 495 | // Write out Specifier keyvals |
| 496 | for (int s = Specifier::FIRST_SPECIFIER; s < Specifier::MAX_SPECIFIERS; s++) |
| 497 | { |
| 498 | // The specifier index of the spawnargs is starting from 1, not 0 |
| 499 | std::string indexStr = string::to_string(s + 1); |
| 500 | |
| 501 | SpecifierPtr spec = c.getSpecifier(static_cast<Specifier::SpecifierNumber>(s)); |
| 502 | |
| 503 | if (spec != NULL) { |
| 504 | entity->setKeyValue(prefix + "spec" + indexStr, spec->getType().getName()); |
| 505 | entity->setKeyValue(prefix + "spec_val" + indexStr, spec->getValue()); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | // Export the component arguments |
| 510 | entity->setKeyValue(prefix + "args", c.getArgumentString()); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | void ObjectiveEntity::clearEntity(Entity* entity) { |
| 515 | // Get all keyvalues matching the "obj" prefix. |
nothing calls this directly
no test coverage detected