std::string EClassTreeBuilder::getInheritancePathRecursive(const IEntityClassPtr& eclass) { std::string returnValue; try { EntityClassAttribute attribute = eclass->getAttribute(INHERIT_KEY); // Don't use empty or derived "inherit" keys if (!attribute.value.empty() && !attribute.inherited) { // Get the inherited eclass first and resolve the path IEntityClassPtr parent = GlobalEntityClassManager().findClass( attribute.value ); if (parent != NULL) { returnValue += getInheritancePathRecursive(parent); } else { globalErrorStream() << "EClassTreeBuilder: Cannot resolve inheritance path for " << eclass->getName() << std::endl; } returnValue += attribute.value + "/"; } } catch (std::runtime_error&) { // no inherit key } return returnValue; }
// Required visit function void EntityClassTreePopulator::visit(const IEntityClassPtr& eclass) { std::string folderPath = eclass->getAttribute(_folderKey).getValue(); if (!folderPath.empty()) { folderPath = "/" + folderPath; } // Create the folder to put this EntityClass in, depending on the value // of the DISPLAY_FOLDER_KEY. addPath(eclass->getModName() + folderPath + "/" + eclass->getName()); }
std::string DifficultySettings::getParentClass(const std::string& className) { // Get the parent eclass IEntityClassPtr eclass = GlobalEntityClassManager().findClass(className); if (eclass == NULL) { return ""; // Invalid! } EntityClassAttribute inheritAttr = eclass->getAttribute("inherit"); return inheritAttr.getValue(); }
scene::INodePtr Doom3EntityCreator::getEntityForEClass(const IEntityClassPtr& eclass) { // Null entityclass check if (!eclass) { throw std::runtime_error( _("Doom3EntityCreator::getEntityForEClass(): " "cannot create entity for NULL entityclass.") ); } // Otherwise create the correct entity subclass based on the entity class // parameters. scene::INodePtr returnValue; if (eclass->isLight()) { LightNodePtr node(new LightNode(eclass)); node->construct(); returnValue = node; } else if (!eclass->isFixedSize()) { // Variable size entity Doom3GroupNodePtr node(new Doom3GroupNode(eclass)); node->construct(); returnValue = node; } else if (!eclass->getAttribute("model").value.empty()) { // Fixed size, has model path EclassModelNodePtr node(new EclassModelNode(eclass)); node->construct(); returnValue = node; } else if (eclass->getName() == "speaker") { SpeakerNodePtr node(new SpeakerNode(eclass)); node->construct(); returnValue = node; } else { // Fixed size, no model path GenericEntityNodePtr node(new GenericEntityNode(eclass)); node->construct(); returnValue = node; } return returnValue; }
void DifficultySettings::parseFromEntityDef(const IEntityClassPtr& def) { // Construct the prefix for the desired difficulty level std::string diffPrefix = "diff_" + string::to_string(_level) + "_"; std::string prefix = diffPrefix + "change_"; eclass::AttributeList spawnargs = eclass::getSpawnargsWithPrefix(*def, prefix); for (eclass::AttributeList::iterator i = spawnargs.begin(); i != spawnargs.end(); ++i) { EntityClassAttribute& attr = *i; if (attr.getValue().empty()) { continue; // empty spawnarg attribute => invalid } // Get the index from the string's tail std::string indexStr = attr.getName().substr(prefix.length()); const EntityClassAttribute& classAttr = def->getAttribute(diffPrefix + "class_" + indexStr); const EntityClassAttribute& argAttr = def->getAttribute(diffPrefix + "arg_" + indexStr); SettingPtr setting = createSetting(classAttr.getValue()); setting->spawnArg = attr.getValue(); setting->argument = argAttr.getValue(); // This has been parsed from the default entityDef setting->isDefault = true; // Interpret/parse the argument string setting->parseAppType(); } clearTreeModel(); updateTreeModel(); }
void Doom3EntityClass::buildInheritanceChain() { _inheritanceChain.clear(); // We start with the name of this class _inheritanceChain.push_back(_name); // Walk up the inheritance chain std::string parentClassName = getAttribute("inherit").value; while (!parentClassName.empty()) { _inheritanceChain.push_front(parentClassName); // Get the parent eclass IEntityClassPtr parentClass = GlobalEntityClassManager().findClass(parentClassName); if (parentClass == NULL) { break; } parentClassName = parentClass->getAttribute("inherit").value; } }
void DifficultySettingsManager::loadDifficultyNames() { // Locate the worldspawn entity Entity* worldspawn = Scene_FindEntityByClass("worldspawn"); // Try to locate the difficulty menu entity, where the default names are defined IEntityClassPtr eclass = GlobalEntityClassManager().findClass( game::current::getValue<std::string>(GKEY_DIFFICULTY_ENTITYDEF_MENU) ); // greebo: Setup the default difficulty levels using the found entityDef int numLevels = game::current::getValue<int>(GKEY_DIFFICULTY_LEVELS); for (int i = 0; i < numLevels; i++) { std::string nameKey = "diff" + string::to_string(i) + "default"; // First, try to find a map-specific name if (worldspawn != NULL) { std::string name = worldspawn->getKeyValue(nameKey); if (!name.empty()) { // Found a setting on worldspawn, take it _difficultyNames.push_back(name); continue; // done for this level } } // If the above failed, try to load the default setting if (eclass != NULL) { EntityClassAttribute attr = eclass->getAttribute(nameKey); if (!attr.getValue().empty()) { _difficultyNames.push_back(attr.getValue()); continue; } } // Fall back to a non-empty default _difficultyNames.push_back(string::to_string(i)); } }