diff --git a/radiantcore/eclass/EClassManager.cpp b/radiantcore/eclass/EClassManager.cpp index 1d2abd4094..624efcce58 100644 --- a/radiantcore/eclass/EClassManager.cpp +++ b/radiantcore/eclass/EClassManager.cpp @@ -51,25 +51,20 @@ IEntityClassPtr EClassManager::findOrInsert(const std::string& name, bool has_br // Return an error if no name is given if (name.empty()) - { return IEntityClassPtr(); - } - // Convert string to lowercase, for case-insensitive lookup - std::string lName = string::to_lower_copy(name); + // Convert string to lowercase, for case-insensitive lookup + std::string lName = string::to_lower_copy(name); // Find and return if exists EntityClass::Ptr eclass = findInternal(lName); if (eclass) - { return eclass; - } - // Otherwise insert the new EntityClass - //IEntityClassPtr eclass = eclass::EntityClass::create(lName, has_brushes); + // Otherwise insert the new EntityClass. // greebo: Changed fallback behaviour when unknown entites are encountered to TRUE // so that brushes of unknown entites don't get lost (issue #240) - eclass = EntityClass::create(lName, true); + eclass = EntityClass::createDefault(lName, true); // Any overrides should also apply to entityDefs that are crated on the fly GlobalEclassColourManager().applyColours(*eclass); diff --git a/radiantcore/eclass/EntityClass.cpp b/radiantcore/eclass/EntityClass.cpp index e8d07fc5ec..2f7679ad9d 100644 --- a/radiantcore/eclass/EntityClass.cpp +++ b/radiantcore/eclass/EntityClass.cpp @@ -19,13 +19,18 @@ namespace const EntityClassAttribute EntityClass::_emptyAttribute("", "", ""); -EntityClass::EntityClass(const std::string& name, const vfs::FileInfo& fileInfo, bool fixedSize) +EntityClass::EntityClass(const std::string& name, bool fixedSize) : _name(name), - _fileInfo(fileInfo), _colour(UndefinedColour), _fixedSize(fixedSize) {} +EntityClass::EntityClass(const std::string& name, const vfs::FileInfo& fileInfo, bool fixedSize) +: EntityClass(name, fixedSize) +{ + _fileInfo = fileInfo; +} + const std::string& EntityClass::getName() const { return _name; @@ -156,10 +161,9 @@ void EntityClass::emplaceAttribute(EntityClassAttribute&& attribute) } } -EntityClass::Ptr EntityClass::create(const std::string& name, bool brushes) +EntityClass::Ptr EntityClass::createDefault(const std::string& name, bool brushes) { - vfs::FileInfo emptyFileInfo("def/", "_autogenerated_by_darkradiant_.def", vfs::Visibility::HIDDEN); - auto eclass = std::make_shared(name, emptyFileInfo, !brushes); + auto eclass = std::make_shared(name, !brushes); // Force the entity class colour to default eclass->setColour(UndefinedColour); @@ -293,7 +297,7 @@ bool EntityClass::isOfType(const std::string& className) std::string EntityClass::getDefFileName() { - return _fileInfo.fullPath(); + return _fileInfo ? _fileInfo->fullPath() : ""; } // Find a single attribute diff --git a/radiantcore/eclass/EntityClass.h b/radiantcore/eclass/EntityClass.h index 087f2b64ba..f98a2c4c12 100644 --- a/radiantcore/eclass/EntityClass.h +++ b/radiantcore/eclass/EntityClass.h @@ -36,8 +36,9 @@ class EntityClass // The name of this entity class std::string _name; - // Source file information - vfs::FileInfo _fileInfo; + // Source file information. May not exist if the entity class was created in code rather than + // loaded from a .def file. + std::optional _fileInfo; // Parent class pointer (or NULL) EntityClass* _parent = nullptr; @@ -91,28 +92,16 @@ class EntityClass bool editorKeys) const; public: - /** - * Static function to create a default entity class. - * - * @param name - * The name of the entity class to create. - * - * @param brushes - * Whether the entity contains brushes or not. - */ - static EntityClass::Ptr create(const std::string& name, bool brushes); - /** - * Constructor. - * - * @param name - * Entity class name. - * - * @param fixedSize - * Whether this entity has a fixed size. - */ + /// Construct an EntityClass with no FileInfo. + EntityClass(const std::string& name, bool isFixedSize = false); + + /// Construct an EntityClass with a given FileInfo. EntityClass(const std::string& name, const vfs::FileInfo& fileInfo, bool fixedSize = false); + /// Create a heap-allocated default/empty EntityClass + static EntityClass::Ptr createDefault(const std::string& name, bool brushes); + void emplaceAttribute(EntityClassAttribute&& attribute); // IEntityClass implementation