ObjDefManager::ObjDefManager(IGameDef *gamedef, ObjDefType type)
{
m_objtype = type;
- m_ndef = gamedef->getNodeDefManager();
+ m_ndef = gamedef ? gamedef->getNodeDefManager() : NULL;
}
ObjDef *ObjDefManager::set(ObjDefHandle handle, ObjDef *obj)
{
u32 index = validateHandle(handle);
- return (index != OBJDEF_INVALID_INDEX) ? setRaw(index, obj) : NULL;
+ if (index == OBJDEF_INVALID_INDEX)
+ return NULL;
+
+ ObjDef *oldobj = setRaw(index, obj);
+
+ obj->uid = oldobj->uid;
+ obj->index = oldobj->index;
+ obj->handle = oldobj->handle;
+
+ return oldobj;
}
std::string name;
};
+// WARNING: Ownership of ObjDefs is transferred to the ObjDefManager it is
+// added/set to. Note that ObjDefs managed by ObjDefManager are NOT refcounted,
+// so the same ObjDef instance must not be referenced multiple
class ObjDefManager {
public:
ObjDefManager(IGameDef *gamedef, ObjDefType type);
virtual ~ObjDefManager();
- virtual const char *getObjectTitle() const = 0;
+ virtual const char *getObjectTitle() const { return "ObjDef"; }
virtual void clear();
virtual ObjDef *getByName(const std::string &name) const;