Skip to content

Commit c1c2010

Browse files
committed
up
1 parent 5043987 commit c1c2010

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

kbe/src/lib/entitydef/entity_component.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ PyObject* EntityComponent::owner(bool attempt)
150150
return owner_;
151151
}
152152

153+
//-------------------------------------------------------------------------------------
154+
void EntityComponent::updateOwner(ENTITY_ID id, PyObject* pOwner)
155+
{
156+
ownerID_ = id;
157+
owner_ = pOwner;
158+
159+
if (owner_)
160+
Py_INCREF(owner_);
161+
}
162+
153163
//-------------------------------------------------------------------------------------
154164
PyObject* EntityComponent::pyGetOwner()
155165
{
@@ -1344,7 +1354,7 @@ void EntityComponent::updateFromDict(PyObject* pyDict)
13441354
}
13451355

13461356
//-------------------------------------------------------------------------------------
1347-
void EntityComponent::convertDictDataToEntityComponent(ENTITY_ID entityID, ScriptDefModule* pEntityScriptDescrs, PyObject* cellData)
1357+
void EntityComponent::convertDictDataToEntityComponent(ENTITY_ID entityID, PyObject* pEntity, ScriptDefModule* pEntityScriptDescrs, PyObject* cellData)
13481358
{
13491359
ScriptDefModule::COMPONENTDESCRIPTION_MAP& componentDescrs = pEntityScriptDescrs->getComponentDescrs();
13501360

@@ -1380,7 +1390,10 @@ void EntityComponent::convertDictDataToEntityComponent(ENTITY_ID entityID, Scrip
13801390

13811391
PropertyDescription* pPropertyDescription = pEntityScriptDescrs->findCellPropertyDescription(comps_iter->first.c_str());
13821392
KBE_ASSERT(pPropertyDescription);
1393+
13831394
pEntityComponent->pPropertyDescription(pPropertyDescription);
1395+
pEntityComponent->updateOwner(entityID, pEntity);
1396+
13841397
PyDict_SetItemString(cellData, comps_iter->first.c_str(), pEntityComponent);
13851398
Py_DECREF(pEntityComponent);
13861399
}

kbe/src/lib/entitydef/entity_component.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class EntityComponent : public script::ScriptObject
8080
DECLARE_PY_GET_MOTHOD(pyGetOwnerID);
8181

8282
PyObject* owner(bool attempt = false);
83+
void updateOwner(ENTITY_ID id, PyObject* pOwner);
8384

8485
DECLARE_PY_GET_MOTHOD(pyIsDestroyed);
8586

@@ -185,7 +186,7 @@ class EntityComponent : public script::ScriptObject
185186
void createFromDict(PyObject* pyDict);
186187
void updateFromDict(PyObject* pyDict);
187188

188-
static void convertDictDataToEntityComponent(ENTITY_ID entityID, ScriptDefModule* pEntityScriptDescrs, PyObject* cellData);
189+
static void convertDictDataToEntityComponent(ENTITY_ID entityID, PyObject* pEntity, ScriptDefModule* pEntityScriptDescrs, PyObject* cellData);
189190
static std::vector<EntityComponent*> getComponents(const std::string& name, PyObject* pEntity, ScriptDefModule* pEntityScriptDescrs);
190191

191192
/**

kbe/src/lib/entitydef/entity_macro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public: \
417417
if(cellDataDict == NULL) \
418418
{ \
419419
PyErr_Clear(); \
420-
EntityComponent::convertDictDataToEntityComponent(id(), pScriptModule_, dictData); \
420+
EntityComponent::convertDictDataToEntityComponent(id(), this, pScriptModule_, dictData); \
421421
} \
422422
\
423423
while(PyDict_Next(dictData, &pos, &key, &value)) \

0 commit comments

Comments
 (0)