Skip to content

Commit

Permalink
Reverted change about expecting entities returned from engine to have…
Browse files Browse the repository at this point in the history
… a scriptable component...
  • Loading branch information
Chukobyte committed Jan 12, 2022
1 parent be900dd commit 25d7460
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
39 changes: 33 additions & 6 deletions src/core/scripting/python/python_modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,15 @@ PyObject* PythonModules::node_get_parent(PyObject *self, PyObject *args, PyObjec
if (PyArg_ParseTupleAndKeywords(args, kwargs, "i", nodeGetEntityKWList, &entity)) {
Entity parentEntity = entityComponentOrchestrator->GetEntityParent(entity);
if (parentEntity != NULL_ENTITY) {
CPyObject& instance = pythonCache->GetClassInstance(parentEntity);
instance.AddRef();
return Py_BuildValue("O", instance.GetObj());
if (pythonCache->HasActiveInstance(parentEntity)) {
CPyObject& instance = pythonCache->GetClassInstance(parentEntity);
instance.AddRef();
return Py_BuildValue("O", instance.GetObj());
} else {
NodeComponent nodeComponent = entityComponentOrchestrator->GetComponent<NodeComponent>(parentEntity);
const std::string &nodeTypeString = NodeTypeHelper::GetNodeTypeString(nodeComponent.type);
return Py_BuildValue("(si)", nodeTypeString.c_str(), parentEntity);
}
}
Py_RETURN_NONE;
}
Expand All @@ -691,7 +697,12 @@ PyObject* PythonModules::node_get_children(PyObject *self, PyObject *args, PyObj
PyErr_Print();
}
} else {
Logger::GetInstance()->Error("Trying to get instance that isn't an active python instance as a child node!");
NodeComponent nodeComponent = entityComponentOrchestrator->GetComponent<NodeComponent>(collidedEntity);
const std::string &nodeTypeString = NodeTypeHelper::GetNodeTypeString(nodeComponent.type);
if (PyList_Append(pCollidedNodesList, Py_BuildValue("(si)", nodeTypeString.c_str(), collidedEntity)) == -1) {
Logger::GetInstance()->Error("Error appending list");
PyErr_Print();
}
}
}
}
Expand Down Expand Up @@ -1570,7 +1581,12 @@ PyObject* PythonModules::collision_get_collided_nodes(PyObject *self, PyObject *
PyErr_Print();
}
} else {
Logger::GetInstance()->Error("Error appending collision node to list, entity doesn't exist as a python instance!");
NodeComponent nodeComponent = componentManager->GetComponent<NodeComponent>(collidedEntity);
const std::string &nodeTypeString = NodeTypeHelper::GetNodeTypeString(nodeComponent.type);
if (PyList_Append(pCollidedNodesList, Py_BuildValue("(si)", nodeTypeString.c_str(), collidedEntity)) == -1) {
Logger::GetInstance()->Error("Error appending list");
PyErr_Print();
}
}
}
}
Expand Down Expand Up @@ -1603,7 +1619,12 @@ PyObject* PythonModules::collision_get_collided_nodes_by_tag(PyObject *self, PyO
PyErr_Print();
}
} else {
Logger::GetInstance()->Error("Error appending collision node (with tag) to list, entity doesn't exist as a python instance!");
NodeComponent nodeComponent = componentManager->GetComponent<NodeComponent>(collidedEntity);
const std::string &nodeTypeString = NodeTypeHelper::GetNodeTypeString(nodeComponent.type);
if (PyList_Append(pCollidedNodesList, Py_BuildValue("(si)", nodeTypeString.c_str(), collidedEntity)) == -1) {
Logger::GetInstance()->Error("Error appending list");
PyErr_Print();
}
}
}
}
Expand Down Expand Up @@ -1644,6 +1665,12 @@ PyObject* PythonModules::collision_get_nodes_under_mouse(PyObject *self, PyObjec
PyErr_Print();
}
} else {
NodeComponent nodeComponent = componentManager->GetComponent<NodeComponent>(collidedEntity);
const std::string &nodeTypeString = NodeTypeHelper::GetNodeTypeString(nodeComponent.type);
if (PyList_Append(pCollidedNodesList, Py_BuildValue("(si)", nodeTypeString.c_str(), collidedEntity)) == -1) {
Logger::GetInstance()->Error("Error appending to list without instance!");
PyErr_Print();
}
Logger::GetInstance()->Error("Error appending collision node (under mouse) to list, entity doesn't exist as a python instance!");
}
}
Expand Down
41 changes: 34 additions & 7 deletions src/core/scripting/python/python_source.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef PYTHON_SOURCE_H
#define PYTHON_SOURCE_H

// Seika Engine API v0.13.1
// Seika Engine API v0.13.2

using PythonSource = const std::string&;

Expand Down Expand Up @@ -932,12 +932,14 @@ static PythonSource PYTHON_SOURCE_NODE_MODULE =
" def parse_scene_node_from_engine(scene_node):\n"
" if not isinstance(scene_node, tuple):\n"
" return scene_node\n"
" else:\n"
" elif scene_node:\n"
" node_type = scene_node[0]\n"
" entity_id = scene_node[1]\n"
" node_class = globals()[node_type]\n"
" instance = node_class(entity_id=entity_id)\n"
" return instance\n"
" print(\"Error with python api function 'parse_scene_node_from_engine'\")\n"
" return None\n"
"\n"
" def add_child(self, child_node) -> None:\n"
" seika_engine_api.node_add_child(\n"
Expand Down Expand Up @@ -1001,10 +1003,19 @@ static PythonSource PYTHON_SOURCE_NODE_MODULE =
" self.hide()\n"
"\n"
" def get_parent(self):\n"
" return seika_engine_api.node_get_parent(entity_id=self.entity_id)\n"
" parent_node = seika_engine_api.node_get_parent(entity_id=self.entity_id)\n"
" if parent_node:\n"
" return parent_node\n"
" return self.parse_scene_node_from_engine(scene_node=parent_node)\n"
"\n"
" def get_children(self) -> list:\n"
" return seika_engine_api.node_get_children(entity_id=self.entity_id)\n"
" children_nodes = []\n"
" children = seika_engine_api.node_get_children(entity_id=self.entity_id)\n"
" for child_node in children:\n"
" children_nodes.append(\n"
" self.parse_scene_node_from_engine(scene_node=child_node)\n"
" )\n"
" return children_nodes\n"
"\n"
"\n"
"class Timer(Node):\n"
Expand Down Expand Up @@ -1549,13 +1560,29 @@ static PythonSource PYTHON_SOURCE_PHYSICS_MODULE =
" seika_engine_api.collision_update_collisions(\n"
" entity_id=node.entity_id, offset_x=offset.x, offset_y=offset.y\n"
" )\n"
" return seika_engine_api.collision_get_collided_nodes(entity_id=node.entity_id)\n"
" collided_nodes_from_engine = seika_engine_api.collision_get_collided_nodes(\n"
" entity_id=node.entity_id\n"
" )\n"
" collided_nodes = []\n"
" for collided_node in collided_nodes_from_engine:\n"
" collided_nodes.append(\n"
" Node.parse_scene_node_from_engine(scene_node=collided_node)\n"
" )\n"
" return collided_nodes\n"
"\n"
" @staticmethod\n"
" def get_collided_nodes_by_tag(node: Node, tag: str, offset=Vector2(0, 0)) -> list:\n"
" return seika_engine_api.collision_get_collided_nodes_by_tag(\n"
" entity_id=node.entity_id, tag=tag, offset_x=offset.x, offset_y=offset.y\n"
" collided_nodes_from_engine = (\n"
" seika_engine_api.collision_get_collided_nodes_by_tag(\n"
" entity_id=node.entity_id, tag=tag, offset_x=offset.x, offset_y=offset.y\n"
" )\n"
" )\n"
" collided_nodes = []\n"
" for collided_node in collided_nodes_from_engine:\n"
" collided_nodes.append(\n"
" Node.parse_scene_node_from_engine(scene_node=collided_node)\n"
" )\n"
" return collided_nodes\n"
"\n"
" @staticmethod\n"
" def get_nodes_under_mouse() -> list:\n"
Expand Down

0 comments on commit 25d7460

Please sign in to comment.