MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / writeComponents

Method writeComponents

plugins/dm.objectives/ObjectiveEntity.cpp:470–512  ·  view source on GitHub ↗

Write the Components from a single Objective to the underlying entity

Source from the content-addressed store, hash-verified

468
469// Write the Components from a single Objective to the underlying entity
470void 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
514void ObjectiveEntity::clearEntity(Entity* entity) {
515 // Get all keyvalues matching the "obj" prefix.

Callers

nothing calls this directly

Calls 14

isSatisfiedMethod · 0.80
isInvertedMethod · 0.80
isIrreversibleMethod · 0.80
isPlayerResponsibleMethod · 0.80
getClockIntervalMethod · 0.80
getArgumentStringMethod · 0.80
to_stringFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
setKeyValueMethod · 0.45
getNameMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected