| 72 | } |
| 73 | |
| 74 | void setEntityClassname(const std::string& classname) |
| 75 | { |
| 76 | if (classname.empty()) |
| 77 | { |
| 78 | throw cmd::ExecutionFailure(_("Cannot set classname to an empty string.")); |
| 79 | } |
| 80 | |
| 81 | if (classname == "worldspawn") |
| 82 | { |
| 83 | throw cmd::ExecutionFailure(_("Cannot change classname to worldspawn.")); |
| 84 | } |
| 85 | |
| 86 | std::set<scene::INodePtr> entitiesToProcess; |
| 87 | |
| 88 | // Collect all entities that should have their classname set |
| 89 | GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node) |
| 90 | { |
| 91 | // Check if we have an entity |
| 92 | Entity* entity = Node_getEntity(node); |
| 93 | |
| 94 | if (entity != NULL && Node_isSelected(node)) |
| 95 | { |
| 96 | if (!entity->isWorldspawn()) |
| 97 | { |
| 98 | entitiesToProcess.insert(node); |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | throw cmd::ExecutionFailure(_("Cannot change classname of worldspawn entity.")); |
| 103 | } |
| 104 | } |
| 105 | }); |
| 106 | |
| 107 | for (const scene::INodePtr& node : entitiesToProcess) |
| 108 | { |
| 109 | // "Rename" the entity, this deletes the old node and creates a new one |
| 110 | scene::INodePtr newNode = changeEntityClassname(node, classname); |
| 111 | |
| 112 | // Select the new entity node |
| 113 | Node_setSelected(newNode, true); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | void setEntityKeyValue(const std::string& key, const std::string& value) |
| 118 | { |
no test coverage detected