Skip to content

Commit

Permalink
#5907: replace many calls to IEntityClass::getAttribute()
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
Matthew Mott committed Mar 21, 2022
1 parent 2166c37 commit e0e18db
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 60 deletions.
17 changes: 6 additions & 11 deletions plugins/dm.difficulty/DifficultySettings.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions plugins/dm.difficulty/DifficultySettingsManager.cpp
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions plugins/dm.editing/DeprecatedEclassCollector.h
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions plugins/dm.editing/SpawnargLinkedCheckbox.h
Expand Up @@ -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";

Expand Down
10 changes: 5 additions & 5 deletions plugins/dm.editing/SpawnargLinkedSpinButton.h
Expand Up @@ -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;

Expand All @@ -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 = "";
Expand Down
8 changes: 4 additions & 4 deletions plugins/dm.stimresponse/ResponseEffect.cpp
Expand Up @@ -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
Expand Down
51 changes: 21 additions & 30 deletions radiant/ui/eclasstree/EClassTreeBuilder.cpp
Expand Up @@ -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
Expand Down

0 comments on commit e0e18db

Please sign in to comment.