[wpdev-commits] wolfpack/python char.cpp,1.182,1.183 item.cpp,1.124,1.125
Brought to you by:
rip,
thiagocorrea
From: Sebastian H. <dar...@us...> - 2004-08-25 17:01:43
|
Update of /cvsroot/wpdev/wolfpack/python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11978/python Modified Files: char.cpp item.cpp Log Message: Changed all references to "events" to "scripts" Index: item.cpp =================================================================== RCS file: /cvsroot/wpdev/wolfpack/python/item.cpp,v retrieving revision 1.124 retrieving revision 1.125 diff -C2 -d -r1.124 -r1.125 *** item.cpp 22 Aug 2004 15:12:48 -0000 1.124 --- item.cpp 25 Aug 2004 17:01:33 -0000 1.125 *************** *** 891,950 **** /* ! \method item.removeevent ! \description Remove a python script from the event chain for this object. ! \param event The id of the python script you want to remove from the event chain. */ ! static PyObject* wpItem_removeevent( wpItem* self, PyObject* args ) { ! char* event; ! if ( !PyArg_ParseTuple( args, "s:item.removeevent(name)", &event ) ) { return 0; } ! self->pItem->removeEvent( event ); Py_RETURN_NONE; } /* ! \method item.addevent ! \description Add a pythonscript to the event chain of this object. ! Does nothing if the object already has that event. ! \param event The id of the python script you want to add to the event chain. */ ! static PyObject* wpItem_addevent( wpItem* self, PyObject* args ) { ! char* event; ! if ( !PyArg_ParseTuple( args, "s:item.addevent(name)", &event ) ) { return 0; } ! cPythonScript* script = ScriptManager::instance()->find( event ); ! if ( !script ) { ! PyErr_Format( PyExc_RuntimeError, "No such script: %s", event ); return 0; } ! self->pItem->addEvent( script ); Py_RETURN_NONE; } /* ! \method item.hasevent ! \description Check if this object has a python script in its event chain. ! \param event The id of the python script you are looking for. \return True of the script is in the chain. False otherwise. */ ! static PyObject* wpItem_hasevent( wpItem* self, PyObject* args ) { ! char* event; ! if ( !PyArg_ParseTuple( args, "s:item.hasevent(name)", &event ) ) { return 0; } ! if ( self->pItem->hasEvent( event ) ) { Py_INCREF( Py_True ); --- 891,950 ---- /* ! \method item.removescript ! \description Remove a python script from the script chain for this object. ! \param script The id of the python script you want to remove from the script chain. */ ! static PyObject* wpItem_removescript( wpItem* self, PyObject* args ) { ! char* script; ! if ( !PyArg_ParseTuple( args, "s:item.removescript(name)", &script ) ) { return 0; } ! self->pItem->removeScript( script ); Py_RETURN_NONE; } /* ! \method item.addscript ! \description Add a pythonscript to the script chain of this object. ! Does nothing if the object already has that script. ! \param script The id of the python script you want to add to the script chain. */ ! static PyObject* wpItem_addscript( wpItem* self, PyObject* args ) { ! char* script; ! if ( !PyArg_ParseTuple( args, "s:item.addscript(name)", &script ) ) { return 0; } ! cPythonScript* pscript = ScriptManager::instance()->find( script ); ! if ( !pscript ) { ! PyErr_Format( PyExc_RuntimeError, "No such script: %s", script ); return 0; } ! self->pItem->addScript( pscript ); Py_RETURN_NONE; } /* ! \method item.hasscript ! \description Check if this object has a python script in its script chain. ! \param script The id of the python script you are looking for. \return True of the script is in the chain. False otherwise. */ ! static PyObject* wpItem_hasscript( wpItem* self, PyObject* args ) { ! char* script; ! if ( !PyArg_ParseTuple( args, "s:item.hasscript(name)", &script ) ) { return 0; } ! if ( self->pItem->hasScript( script ) ) { Py_INCREF( Py_True ); *************** *** 1039,1045 **** } ! if ( cPythonScript::canChainHandleEvent( ( ePythonEvent ) event, self->pItem->getEvents() ) ) { ! bool result = cPythonScript::callChainedEventHandler( ( ePythonEvent ) event, self->pItem->getEvents(), eventargs ); if ( result ) --- 1039,1045 ---- } ! if ( cPythonScript::canChainHandleEvent( ( ePythonEvent ) event, self->pItem->getScripts() ) ) { ! bool result = cPythonScript::callChainedEventHandler( ( ePythonEvent ) event, self->pItem->getScripts(), eventargs ); if ( result ) *************** *** 1115,1121 **** // Event handling { "callevent", ( getattrofunc ) wpItem_callevent, METH_VARARGS, 0 }, ! { "addevent", ( getattrofunc ) wpItem_addevent, METH_VARARGS, 0}, ! { "removeevent", ( getattrofunc ) wpItem_removeevent, METH_VARARGS, 0}, ! { "hasevent", ( getattrofunc ) wpItem_hasevent, METH_VARARGS, 0}, // Effects --- 1115,1121 ---- // Event handling { "callevent", ( getattrofunc ) wpItem_callevent, METH_VARARGS, 0 }, ! { "addscript", ( getattrofunc ) wpItem_addscript, METH_VARARGS, 0}, ! { "removescript", ( getattrofunc ) wpItem_removescript, METH_VARARGS, 0}, ! { "hasscript", ( getattrofunc ) wpItem_hasscript, METH_VARARGS, 0}, // Effects *************** *** 1152,1156 **** } /* ! \property item.tags A list of all tag names the object currently has. */ else if ( !strcmp( "tags", name ) ) --- 1152,1156 ---- } /* ! \rproperty item.tags A list of all tag names the object currently has. */ else if ( !strcmp( "tags", name ) ) *************** *** 1195,1203 **** } /* ! \rproperty item.events Returns a list of all event names the object has. */ ! else if ( !strcmp( "events", name ) ) { ! QStringList events = QStringList::split( ",", self->pItem->eventList() ); PyObject* list = PyList_New( events.count() ); for ( uint i = 0; i < events.count(); ++i ) --- 1195,1203 ---- } /* ! \rproperty item.scripts Returns a list of all script names the object has. */ ! else if ( !strcmp( "scripts", name ) ) { ! QStringList events = QStringList::split( ",", self->pItem->scriptList() ); PyObject* list = PyList_New( events.count() ); for ( uint i = 0; i < events.count(); ++i ) *************** *** 1219,1247 **** static int wpItem_setAttr( wpItem* self, char* name, PyObject* value ) { - // Special Python things. - if ( !strcmp( "events", name ) ) - { - if ( !PyList_Check( value ) ) - { - PyErr_BadArgument(); - return -1; - } - - self->pItem->clearEvents(); - int i; - for ( i = 0; i < PyList_Size( value ); ++i ) - { - if ( !PyString_Check( PyList_GetItem( value, i ) ) ) - continue; - - cPythonScript* script = ScriptManager::instance()->find( PyString_AsString( PyList_GetItem( value, i ) ) ); - if ( script ) - self->pItem->addEvent( script ); - } - } /* \rproperty item.container Returns the serial of the container this item is in. Returns 0 if no container. */ ! else if ( !strcmp( "container", name ) ) { if ( checkWpItem( value ) ) --- 1219,1226 ---- static int wpItem_setAttr( wpItem* self, char* name, PyObject* value ) { /* \rproperty item.container Returns the serial of the container this item is in. Returns 0 if no container. */ ! if ( !strcmp( "container", name ) ) { if ( checkWpItem( value ) ) Index: char.cpp =================================================================== RCS file: /cvsroot/wpdev/wolfpack/python/char.cpp,v retrieving revision 1.182 retrieving revision 1.183 diff -C2 -d -r1.182 -r1.183 *** char.cpp 22 Aug 2004 15:12:34 -0000 1.182 --- char.cpp 25 Aug 2004 17:01:33 -0000 1.183 *************** *** 1421,1425 **** dispelargs = PyTuple_New( 0 ); ! if ( cPythonScript::canChainHandleEvent( EVENT_DISPEL, self->pChar->getEvents() ) ) { PyObject* source; --- 1421,1425 ---- dispelargs = PyTuple_New( 0 ); ! if ( cPythonScript::canChainHandleEvent( EVENT_DISPEL, self->pChar->getScripts() ) ) { PyObject* source; *************** *** 1440,1444 **** PyObject* args = Py_BuildValue( "(NNBBsN", self->pChar->getPyObject(), source, 0, force ? 1 : 0, ptype, dispelargs ); ! bool result = cPythonScript::callChainedEventHandler( EVENT_DISPEL, self->pChar->getEvents(), args ); Py_DECREF( args ); --- 1440,1444 ---- PyObject* args = Py_BuildValue( "(NNBBsN", self->pChar->getPyObject(), source, 0, force ? 1 : 0, ptype, dispelargs ); ! bool result = cPythonScript::callChainedEventHandler( EVENT_DISPEL, self->pChar->getScripts(), args ); Py_DECREF( args ); *************** *** 2166,2225 **** /* ! \method char.removeevent ! \description Remove a python script from the event chain for this object. ! \param event The id of the python script you want to remove from the event chain. */ ! static PyObject* wpChar_removeevent( wpChar* self, PyObject* args ) { ! char* event; ! if ( !PyArg_ParseTuple( args, "s:char.removeevent(name)", &event ) ) { return 0; } ! self->pChar->removeEvent( event ); Py_RETURN_NONE; } /* ! \method char.addevent ! \description Add a pythonscript to the event chain of this object. ! Does nothing if the object already has that event. ! \param event The id of the python script you want to add to the event chain. */ ! static PyObject* wpChar_addevent( wpChar* self, PyObject* args ) { ! char* event; ! if ( !PyArg_ParseTuple( args, "s:char.addevent(name)", &event ) ) { return 0; } ! cPythonScript* script = ScriptManager::instance()->find( event ); ! if ( !script ) { ! PyErr_Format( PyExc_RuntimeError, "No such script: %s", event ); return 0; } ! self->pChar->addEvent( script ); Py_RETURN_NONE; } /* ! \method char.hasevent ! \description Check if this object has a python script in its event chain. ! \param event The id of the python script you are looking for. \return True of the script is in the chain. False otherwise. */ ! static PyObject* wpChar_hasevent( wpChar* self, PyObject* args ) { ! char* event; ! if ( !PyArg_ParseTuple( args, "s:char.hasevent(name)", &event ) ) { return 0; } ! if ( self->pChar->hasEvent( event ) ) { Py_INCREF( Py_True ); --- 2166,2225 ---- /* ! \method char.removescript ! \description Remove a python script from the script chain for this object. ! \param script The id of the python script you want to remove from the script chain. */ ! static PyObject* wpChar_removescript( wpChar* self, PyObject* args ) { ! char* script; ! if ( !PyArg_ParseTuple( args, "s:char.removescript(name)", &script ) ) { return 0; } ! self->pChar->removeScript( script ); Py_RETURN_NONE; } /* ! \method char.addscript ! \description Add a pythonscript to the script chain of this object. ! Does nothing if the object already has that script. ! \param script The id of the python script you want to add to the script chain. */ ! static PyObject* wpChar_addscript( wpChar* self, PyObject* args ) { ! char* script; ! if ( !PyArg_ParseTuple( args, "s:char.addscript(name)", &script ) ) { return 0; } ! cPythonScript* pscript = ScriptManager::instance()->find( script ); ! if ( !pscript ) { ! PyErr_Format( PyExc_RuntimeError, "No such script: %s", script ); return 0; } ! self->pChar->addScript( pscript ); Py_RETURN_NONE; } /* ! \method char.hasscript ! \description Check if this object has a python script in its script chain. ! \param script The id of the python script you are looking for. \return True of the script is in the chain. False otherwise. */ ! static PyObject* wpChar_hasscript( wpChar* self, PyObject* args ) { ! char* script; ! if ( !PyArg_ParseTuple( args, "s:char.hasscript(name)", &script ) ) { return 0; } ! if ( self->pChar->hasScript( script ) ) { Py_INCREF( Py_True ); *************** *** 2268,2274 **** } ! if ( cPythonScript::canChainHandleEvent( ( ePythonEvent ) event, self->pChar->getEvents() ) ) { ! bool result = cPythonScript::callChainedEventHandler( ( ePythonEvent ) event, self->pChar->getEvents(), eventargs ); if ( result ) --- 2268,2274 ---- } ! if ( cPythonScript::canChainHandleEvent( ( ePythonEvent ) event, self->pChar->getScripts() ) ) { ! bool result = cPythonScript::callChainedEventHandler( ( ePythonEvent ) event, self->pChar->getScripts(), eventargs ); if ( result ) *************** *** 2329,2335 **** // Event handling functions ! { "addevent", ( getattrofunc ) wpChar_addevent, METH_VARARGS, 0}, ! { "removeevent", ( getattrofunc ) wpChar_removeevent, METH_VARARGS, 0}, ! { "hasevent", ( getattrofunc ) wpChar_hasevent, METH_VARARGS, 0}, { "callevent", ( getattrofunc ) wpChar_callevent, METH_VARARGS, 0}, --- 2329,2335 ---- // Event handling functions ! { "addscript", ( getattrofunc ) wpChar_addscript, METH_VARARGS, 0}, ! { "removescript", ( getattrofunc ) wpChar_removescript, METH_VARARGS, 0}, ! { "hasscript", ( getattrofunc ) wpChar_hasscript, METH_VARARGS, 0}, { "callevent", ( getattrofunc ) wpChar_callevent, METH_VARARGS, 0}, *************** *** 2396,2402 **** /* ! \rproperty char.tags This property is a list of names for all tags attached to this character. ! This property is exclusive to python scripts and overrides normal properties with the same name. ! */ } else if ( !strcmp( "tags", name ) ) --- 2396,2402 ---- /* ! \rproperty char.tags This property is a list of names for all tags attached to this character. ! This property is exclusive to python scripts and overrides normal properties with the same name. ! */ } else if ( !strcmp( "tags", name ) ) *************** *** 2585,2597 **** } /* ! \property char.events The names of the scripts attached to this character. This property is exclusive to python scripts and overrides normal properties with the same name. */ ! else if ( !strcmp( "events", name ) ) { ! QStringList events = QStringList::split( ",", self->pChar->eventList() ); ! PyObject* list = PyList_New( events.count() ); ! for ( uint i = 0; i < events.count(); ++i ) ! PyList_SetItem( list, i, PyString_FromString( events[i].latin1() ) ); return list; /* --- 2585,2597 ---- } /* ! \rproperty char.scripts The names of the scripts attached to this character. This property is exclusive to python scripts and overrides normal properties with the same name. */ ! else if ( !strcmp( "scripts", name ) ) { ! QStringList scripts = QStringList::split( ",", self->pChar->scriptList() ); ! PyObject* list = PyList_New( scripts.count() ); ! for ( uint i = 0; i < scripts.count(); ++i ) ! PyList_SetItem( list, i, PyString_FromString( scripts[i].latin1() ) ); return list; /* *************** *** 2627,2679 **** int wpChar_setAttr( wpChar* self, char* name, PyObject* value ) { ! // Special Python things. ! if ( !strcmp( "events", name ) ) ! { ! if ( !PyList_Check( value ) ) ! { ! PyErr_BadArgument(); ! return -1; ! } ! ! self->pChar->clearEvents(); ! int i; ! for ( i = 0; i < PyList_Size( value ); ++i ) ! { ! if ( !PyString_Check( PyList_GetItem( value, i ) ) ) ! continue; ! ! cPythonScript* script = ScriptManager::instance()->find( PyString_AsString( PyList_GetItem( value, i ) ) ); ! if ( script ) ! self->pChar->addEvent( script ); ! } ! } ! else ! { ! cVariant val; ! if ( PyString_Check( value ) || PyUnicode_Check( value ) ) ! val = cVariant( Python2QString( value ) ); ! else if ( PyInt_Check( value ) ) ! val = cVariant( PyInt_AsLong( value ) ); ! else if ( checkWpItem( value ) ) ! val = cVariant( getWpItem( value ) ); ! else if ( checkWpChar( value ) ) ! val = cVariant( getWpChar( value ) ); ! else if ( checkWpCoord( value ) ) ! val = cVariant( getWpCoord( value ) ); ! else if ( PyFloat_Check( value ) ) ! val = cVariant( PyFloat_AsDouble( value ) ); ! else if ( value == Py_True ) ! val = cVariant( 1 ); // True ! else if ( value == Py_False ) ! val = cVariant( 0 ); // false ! stError * error = self->pChar->setProperty( name, val ); ! if ( error ) ! { ! PyErr_Format( PyExc_TypeError, "Error while setting attribute '%s': %s", name, error->text.latin1() ); ! delete error; ! return 0; ! } } --- 2627,2653 ---- int wpChar_setAttr( wpChar* self, char* name, PyObject* value ) { ! cVariant val; ! if ( PyString_Check( value ) || PyUnicode_Check( value ) ) ! val = cVariant( Python2QString( value ) ); ! else if ( PyInt_Check( value ) ) ! val = cVariant( PyInt_AsLong( value ) ); ! else if ( checkWpItem( value ) ) ! val = cVariant( getWpItem( value ) ); ! else if ( checkWpChar( value ) ) ! val = cVariant( getWpChar( value ) ); ! else if ( checkWpCoord( value ) ) ! val = cVariant( getWpCoord( value ) ); ! else if ( PyFloat_Check( value ) ) ! val = cVariant( PyFloat_AsDouble( value ) ); ! else if ( value == Py_True ) ! val = cVariant( 1 ); // True ! else if ( value == Py_False ) ! val = cVariant( 0 ); // false ! stError * error = self->pChar->setProperty( name, val ); ! if (error) { ! PyErr_Format( PyExc_TypeError, "Error while setting attribute '%s': %s", name, error->text.latin1() ); ! delete error; } |