From e0e18db48ee55f287036fafc486e018c13feda52 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Mon, 21 Mar 2022 20:29:25 +0000 Subject: [PATCH] #5907: replace many calls to IEntityClass::getAttribute() These were calls to getAttribute() whose return EntityClassAttribute& was only used for subsequent getValue() or getDescription() calls, allowing them to be replaced by the more straightforward getAttributeValue() and getAttributeDescription(). --- plugins/dm.difficulty/DifficultySettings.cpp | 17 +++---- .../DifficultySettingsManager.cpp | 3 +- .../dm.editing/DeprecatedEclassCollector.h | 9 ++-- plugins/dm.editing/SpawnargLinkedCheckbox.h | 5 +- plugins/dm.editing/SpawnargLinkedSpinButton.h | 10 ++-- plugins/dm.stimresponse/ResponseEffect.cpp | 8 +-- radiant/ui/eclasstree/EClassTreeBuilder.cpp | 51 ++++++++----------- 7 files changed, 43 insertions(+), 60 deletions(-) diff --git a/plugins/dm.difficulty/DifficultySettings.cpp b/plugins/dm.difficulty/DifficultySettings.cpp index 0921f89aef..b3bd359554 100644 --- a/plugins/dm.difficulty/DifficultySettings.cpp +++ b/plugins/dm.difficulty/DifficultySettings.cpp @@ -232,14 +232,10 @@ std::string DifficultySettings::getParentClass(const std::string& className) { // Get the parent eclass IEntityClassPtr eclass = GlobalEntityClassManager().findClass(className); - - if (eclass == NULL) - { + if (!eclass) return ""; // Invalid! - } - EntityClassAttribute inheritAttr = eclass->getAttribute("inherit"); - return inheritAttr.getValue(); + return eclass->getAttributeValue("inherit"); } wxDataViewItem DifficultySettings::findOrInsertClassname(const std::string& className) @@ -359,12 +355,11 @@ void DifficultySettings::parseFromEntityDef(const IEntityClassPtr& def) // 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()); + SettingPtr setting = createSetting( + def->getAttributeValue(diffPrefix + "class_" + indexStr) + ); setting->spawnArg = attr.getValue(); - setting->argument = argAttr.getValue(); + setting->argument = def->getAttributeValue(diffPrefix + "arg_" + indexStr); // This has been parsed from the default entityDef setting->isDefault = true; diff --git a/plugins/dm.difficulty/DifficultySettingsManager.cpp b/plugins/dm.difficulty/DifficultySettingsManager.cpp index 440250a132..681713f97d 100644 --- a/plugins/dm.difficulty/DifficultySettingsManager.cpp +++ b/plugins/dm.difficulty/DifficultySettingsManager.cpp @@ -111,8 +111,7 @@ class ModDifficultyNames { if (_menuEclass) { - EntityClassAttribute attr = _menuEclass->getAttribute(nameKey); - std::string rawName = attr.getValue(); + std::string rawName = _menuEclass->getAttributeValue(nameKey); if (!rawName.empty()) { // Look for a translation, otherwise use the raw name diff --git a/plugins/dm.editing/DeprecatedEclassCollector.h b/plugins/dm.editing/DeprecatedEclassCollector.h index 286281c661..162431a4c6 100644 --- a/plugins/dm.editing/DeprecatedEclassCollector.h +++ b/plugins/dm.editing/DeprecatedEclassCollector.h @@ -17,15 +17,12 @@ class DeprecatedEclassCollector : public: void visit(const IEntityClassPtr& eclass) { - const EntityClassAttribute& attr = eclass->getAttribute("editor_replacement"); - - if (attr.getValue().empty()) - { + const std::string attr = eclass->getAttributeValue("editor_replacement"); + if (attr.empty()) return; - } // Non-empty editor_replacement, add fixup code - _fixupCode += ENTITYDEF_PREFIX + eclass->getName() + " => " + attr.getValue() + "\n"; + _fixupCode += ENTITYDEF_PREFIX + eclass->getName() + " => " + attr + "\n"; } const std::string& getFixupCode() const diff --git a/plugins/dm.editing/SpawnargLinkedCheckbox.h b/plugins/dm.editing/SpawnargLinkedCheckbox.h index 45848c4974..afcf1d2af0 100644 --- a/plugins/dm.editing/SpawnargLinkedCheckbox.h +++ b/plugins/dm.editing/SpawnargLinkedCheckbox.h @@ -59,9 +59,10 @@ class SpawnargLinkedCheckbox : return; } - SetToolTip(_propertyName + ": " + _entity->getEntityClass()->getAttribute(_propertyName).getDescription()); + SetToolTip(_propertyName + ": " + + _entity->getEntityClass()->getAttributeDescription(_propertyName)); - std::string keyValue = _entity->getKeyValue(_propertyName); + std::string keyValue = _entity->getKeyValue(_propertyName); bool value = _entity->getKeyValue(_propertyName) == "1"; diff --git a/plugins/dm.editing/SpawnargLinkedSpinButton.h b/plugins/dm.editing/SpawnargLinkedSpinButton.h index 6017b5fc81..a4f4d7d4fa 100644 --- a/plugins/dm.editing/SpawnargLinkedSpinButton.h +++ b/plugins/dm.editing/SpawnargLinkedSpinButton.h @@ -81,8 +81,9 @@ class SpawnargLinkedSpinButton : return; } - std::string desc = _propertyName + ": " + _entity->getEntityClass()->getAttribute(_propertyName).getDescription(); - _spinCtrl->SetToolTip(desc); + std::string desc = _propertyName + ": " + + _entity->getEntityClass()->getAttributeDescription(_propertyName); + _spinCtrl->SetToolTip(desc); if (_updateLock) return; @@ -107,9 +108,8 @@ class SpawnargLinkedSpinButton : std::string newValue = fmt::format("{0:." + string::to_string(_spinCtrl->GetDigits()) + "f}", floatVal); // Check if the new value conincides with an inherited one - const EntityClassAttribute& attr = _entity->getEntityClass()->getAttribute(_propertyName); - - if (!attr.getValue().empty() && string::to_float(attr.getValue()) == floatVal) + const std::string attr = _entity->getEntityClass()->getAttributeValue(_propertyName); + if (!attr.empty() && string::to_float(attr) == floatVal) { // in which case the property just gets removed from the entity newValue = ""; diff --git a/plugins/dm.stimresponse/ResponseEffect.cpp b/plugins/dm.stimresponse/ResponseEffect.cpp index f698144f58..b6e6ea7634 100644 --- a/plugins/dm.stimresponse/ResponseEffect.cpp +++ b/plugins/dm.stimresponse/ResponseEffect.cpp @@ -154,10 +154,10 @@ void ResponseEffect::buildArgumentList() { if (_eclass == NULL) return; for (int i = 1; i < 1000; i++) { - std::string argType = _eclass->getAttribute("editor_argType" + string::to_string(i)).getValue(); - std::string argDesc = _eclass->getAttribute("editor_argDesc" + string::to_string(i)).getValue(); - std::string argTitle = _eclass->getAttribute("editor_argTitle" + string::to_string(i)).getValue(); - std::string optional = _eclass->getAttribute("editor_argOptional" + string::to_string(i)).getValue(); + std::string argType = _eclass->getAttributeValue("editor_argType" + string::to_string(i)); + std::string argDesc = _eclass->getAttributeValue("editor_argDesc" + string::to_string(i)); + std::string argTitle = _eclass->getAttributeValue("editor_argTitle" + string::to_string(i)); + std::string optional = _eclass->getAttributeValue("editor_argOptional" + string::to_string(i)); if (argType != "") { // Check if the argument exists diff --git a/radiant/ui/eclasstree/EClassTreeBuilder.cpp b/radiant/ui/eclasstree/EClassTreeBuilder.cpp index 52a17240bd..c697380556 100644 --- a/radiant/ui/eclasstree/EClassTreeBuilder.cpp +++ b/radiant/ui/eclasstree/EClassTreeBuilder.cpp @@ -104,41 +104,32 @@ void EClassTreeBuilder::visit(wxutil::TreeModel& /* store */, wxutil::TreeModel: std::string EClassTreeBuilder::getInheritancePathRecursive(const IEntityClassPtr& eclass) { - std::string returnValue; + std::string returnValue; - try - { - EntityClassAttribute attribute = eclass->getAttribute( + try { + std::string attribute = eclass->getAttributeValue( INHERIT_KEY, false /* includeInherited*/ ); // Don't use empty "inherit" keys - if (!attribute.getValue().empty()) - { - // Get the inherited eclass first and resolve the path - IEntityClassPtr parent = GlobalEntityClassManager().findClass( - attribute.getValue() - ); - - if (parent != NULL) - { - returnValue += getInheritancePathRecursive(parent); - } - else - { - rError() << "EClassTreeBuilder: Cannot resolve inheritance path for " - << eclass->getName() << std::endl; - } - - returnValue += attribute.getValue() + "/"; - } - } - catch (std::runtime_error&) - { - // no inherit key - } - - return returnValue; + if (!attribute.empty()) { + // Get the inherited eclass first and resolve the path + IEntityClassPtr parent = GlobalEntityClassManager().findClass(attribute); + if (parent) { + returnValue += getInheritancePathRecursive(parent); + } else { + rError() << "EClassTreeBuilder: Cannot resolve inheritance path for " + << eclass->getName() << std::endl; + } + + returnValue += attribute + "/"; + } + } + catch (std::runtime_error&) { + // no inherit key + } + + return returnValue; } } // namespace ui