While testing YoFrankie with the new API attributes found some issues...

- corrections to docs
- disallow calling controller.activate(actuator) when the controller is not active. (Raise a SystemError)
- Added 2 new attributes, CValue.name - deprecates CValue.getName(), KX_GameObject.children deprecated KX_GameObject.getChildren(), (same for getChildrenRecursive()).
This commit is contained in:
Campbell Barton 2009-05-17 16:30:18 +00:00
parent 65796e2c07
commit 41acd3b81c
7 changed files with 58 additions and 9 deletions

@ -66,13 +66,14 @@ PyParentObject CValue::Parents[] = {
};
PyMethodDef CValue::Methods[] = {
// { "printHello", (PyCFunction) CValue::sPyPrintHello, METH_VARARGS},
{ "getName", (PyCFunction) CValue::sPyGetName, METH_NOARGS},
{NULL,NULL} //Sentinel
};
PyObject* CValue::PyGetName()
{
ShowDeprecationWarning("getName()", "the name property");
return PyString_FromString(this->GetName());
}
@ -550,6 +551,7 @@ static PyMethodDef CValueMethods[] =
};
PyAttributeDef CValue::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("name", CValue, pyattr_get_name),
{ NULL } //Sentinel
};
@ -574,6 +576,11 @@ PyObject* CValue::py_getattro_dict() {
py_getattro_dict_up(PyObjectPlus);
}
PyObject * CValue::pyattr_get_name(void * self_v, const KX_PYATTRIBUTE_DEF * attrdef) {
CValue * self = static_cast<CValue *> (self_v);
return PyString_FromString(self->GetName());
}
CValue* CValue::ConvertPythonToValue(PyObject* pyobj, const char *error_prefix)
{

@ -236,6 +236,8 @@ public:
virtual int py_delattro(PyObject *attr);
virtual int py_setattro(PyObject *attr, PyObject* value);
static PyObject * pyattr_get_name(void * self, const KX_PYATTRIBUTE_DEF * attrdef);
virtual PyObject* ConvertKeysToPython( void );
KX_PYMETHOD_NOARGS(CValue,GetName);

@ -494,6 +494,11 @@ int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value)
PyObject* SCA_PythonController::PyActivate(PyObject *value)
{
if(m_sCurrentController != this) {
PyErr_SetString(PyExc_SystemError, "Cannot add an actuator from a non-active controller");
return NULL;
}
SCA_IActuator* actu = LinkedActuatorFromPy(value);
if(actu==NULL)
return NULL;
@ -504,6 +509,11 @@ PyObject* SCA_PythonController::PyActivate(PyObject *value)
PyObject* SCA_PythonController::PyDeActivate(PyObject *value)
{
if(m_sCurrentController != this) {
PyErr_SetString(PyExc_SystemError, "Cannot add an actuator from a non-active controller");
return NULL;
}
SCA_IActuator* actu = LinkedActuatorFromPy(value);
if(actu==NULL)
return NULL;

@ -757,7 +757,7 @@ KX_PYMETHODDEF_DOC_O(KX_Camera, enableViewport,
"Sets this camera's viewport status\n"
)
{
ShowDeprecationWarning("enableViewport(bool)", "the isViewport property");
ShowDeprecationWarning("enableViewport(bool)", "the useViewport property");
int viewport = PyObject_IsTrue(value);
if (viewport == -1) {

@ -1213,6 +1213,8 @@ PyAttributeDef KX_GameObject::Attributes[] = {
KX_PYATTRIBUTE_RW_FUNCTION("worldPosition", KX_GameObject, pyattr_get_worldPosition, pyattr_set_worldPosition),
KX_PYATTRIBUTE_RW_FUNCTION("localScale", KX_GameObject, pyattr_get_localScaling, pyattr_set_localScaling),
KX_PYATTRIBUTE_RO_FUNCTION("worldScale", KX_GameObject, pyattr_get_worldScaling),
KX_PYATTRIBUTE_RO_FUNCTION("children", KX_GameObject, pyattr_get_children),
KX_PYATTRIBUTE_RO_FUNCTION("childrenRecursive", KX_GameObject, pyattr_get_children_recursive),
KX_PYATTRIBUTE_RO_FUNCTION("attrDict", KX_GameObject, pyattr_get_attrDict),
/* Experemental, dont rely on these yet */
@ -1753,6 +1755,18 @@ PyObject* KX_GameObject::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE
return KX_PythonSeq_CreatePyObject((static_cast<KX_GameObject*>(self_v))->m_proxy, KX_PYGENSEQ_OB_TYPE_ACTUATORS);
}
PyObject* KX_GameObject::pyattr_get_children(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return self->GetChildren()->NewProxy(true);
}
PyObject* KX_GameObject::pyattr_get_children_recursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
return self->GetChildrenRecursive()->NewProxy(true);
}
PyObject* KX_GameObject::pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
@ -2155,11 +2169,15 @@ PyObject* KX_GameObject::PyRemoveParent()
PyObject* KX_GameObject::PyGetChildren()
{
ShowDeprecationWarning("getChildren()", "the children property");
return GetChildren()->NewProxy(true);
}
PyObject* KX_GameObject::PyGetChildrenRecursive()
{
ShowDeprecationWarning("getChildrenRecursive()", "the childrenRecursive property");
return GetChildrenRecursive()->NewProxy(true);
}
@ -2304,7 +2322,7 @@ PyObject* KX_GameObject::PyGetAxisVect(PyObject* value)
PyObject* KX_GameObject::PySetPosition(PyObject* value)
{
ShowDeprecationWarning("setPosition()", "the position property");
ShowDeprecationWarning("setPosition()", "the localPosition property");
MT_Point3 pos;
if (PyVecTo(value, pos))
{

@ -902,6 +902,8 @@ public:
static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_children(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_children_recursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
/* Experemental! */

@ -45,11 +45,14 @@ class PyObjectPlus:
class CValue(PyObjectPlus):
"""
This class is a basis for other classes.
@ivar name: The name of this CValue derived object (read-only).
@type name: string
"""
def getName():
"""
Returns the name of the CValue.
@deprecated: Use the L{name} attribute instead.
@note: in most cases the CValue's subclasses will override this function.
@rtype: string
"""
@ -1584,7 +1587,11 @@ class KX_GameObject(SCA_IObject):
@type actuators: list
@ivar attrDict: get the objects internal python attribute dictionary for direct (faster) access.
@type attrDict: dict
@group Deprecated: getPosition, setPosition, setWorldPosition, getOrientation, setOrientation, getState, setState, getParent, getVisible, getMass, getMesh
@ivar children: direct children of this object, (read-only).
@type children: L{CListValue} of L{KX_GameObject}'s
@ivar childrenRecursive: all children of this object including childrens children, (read-only).
@type childrenRecursive: L{CListValue} of L{KX_GameObject}'s
@group Deprecated: getPosition, setPosition, setWorldPosition, getOrientation, setOrientation, getState, setState, getParent, getVisible, getMass, getMesh, getChildren, getChildrenRecursive
"""
def endObject():
"""
@ -1647,6 +1654,7 @@ class KX_GameObject(SCA_IObject):
"""
Sets the game object's position in world coordinates regardless if the object is root or child.
@deprecated: use L{worldPosition}
@type pos: [x, y, z]
@param pos: the new position, in world coordinates.
"""
@ -2386,7 +2394,7 @@ class KX_MouseFocusSensor(SCA_MouseSensor):
@ivar hitNormal: the worldspace normal from the face at point of intersection.
@type hitNormal: list (normalized vector of 3 floats)
"""
#{ Deprecated
def getHitNormal():
"""
Returns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray.
@ -2435,6 +2443,7 @@ class KX_MouseFocusSensor(SCA_MouseSensor):
@rtype: list [x, y, z]
@return: the ray target.
"""
#}
class KX_TouchSensor(SCA_ISensor):
"""
@ -2736,8 +2745,7 @@ class KX_ObjectActuator(SCA_IActuator):
@rtype: list [dx, dy, dz, local]
@return: A four item list, containing the angular displacement vector, and whether
the displacement is applied in local coordinates (True) or world
coordinates (False)
the displacement is applied in local coordinates (True) or world coordinates (False)
"""
def setDRot(dx, dy, dz, local):
"""
@ -3660,7 +3668,7 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator):
# The mesh is a different mesh - switch it.
# Check the current mesh is not a better fit.
if curmesh == None or curmesh[1] < depth or curmesh[2] > depth:
act.setMesh(obj.getName() + newmesh[0])
act.mesh = obj.getName() + newmesh[0]
GameLogic.addActiveActuator(act, True)
@warning: Replace mesh actuators will be ignored if at game start, the
@ -4008,7 +4016,7 @@ class KX_SoundActuator(SCA_IActuator):
"""
Sets the position this sound will come from.
@deprecated: Use the L{position} attribute instead.
@deprecated: Use the L{localPosition} attribute instead.
@type x: float
@param x: The x coordinate of the sound.
@type y: float
@ -4120,6 +4128,7 @@ class KX_TrackToActuator(SCA_IActuator):
@type use3D: boolean
"""
#{ Deprecated
def setObject(object):
"""
Sets the object to track.
@ -4168,6 +4177,7 @@ class KX_TrackToActuator(SCA_IActuator):
@deprecated: Use the L{use3D} attribute instead.
@rtype: boolean
"""
#}
class KX_VehicleWrapper(PyObjectPlus):
"""