Revision: 27764
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27764
Author:   dfelinto
Date:     2010-03-26 08:21:48 +0100 (Fri, 26 Mar 2010)

Log Message:
-----------
BGE: fix for [#21180] - missing min and max values in the API + mode fix 
(interval wasn't working)
of course it wasn't only a matter of adding the properties in the api :)

The code of validValueForIntervalProperty and modeChange are the same BUT in 
the future they shouldn't be, for I think it's fine to keep them as separated 
functions.

Bonus fix: Also we are now checking if the new mode is interval and update the 
range expression.

Modified Paths:
--------------
    trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.h
    trunk/blender/source/gameengine/PyDoc/GameTypes.py

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.cpp    
2010-03-26 07:17:54 UTC (rev 27763)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.cpp    
2010-03-26 07:21:48 UTC (rev 27764)
@@ -316,10 +316,36 @@
 
 int SCA_PropertySensor::validValueForProperty(void *self, const 
PyAttributeDef*)
 {
+       /*  If someone actually do type checking please make sure the 'max' and 
'min'
+               are checked as well (currently they are calling the 
PrecalculateRangeExpression
+               function directly       */
+
        /*  There is no type checking at this moment, unfortunately...          
 */
        return 0;
 }
 
+int SCA_PropertySensor::validValueForIntervalProperty(void *self, const 
PyAttributeDef*)
+{
+       SCA_PropertySensor*     sensor = 
reinterpret_cast<SCA_PropertySensor*>(self);
+
+       if (sensor->m_checktype==KX_PROPSENSOR_INTERVAL)
+       {
+               sensor->PrecalculateRangeExpression();
+       }
+       return 0;
+}
+
+int SCA_PropertySensor::modeChange(void *self, const PyAttributeDef* attrdef)
+{
+       SCA_PropertySensor*     sensor = 
reinterpret_cast<SCA_PropertySensor*>(self);
+
+       if (sensor->m_checktype==KX_PROPSENSOR_INTERVAL)
+       {
+               sensor->PrecalculateRangeExpression();
+       }
+       return 0;
+}
+
 /* Integration hooks ------------------------------------------------------- */
 PyTypeObject SCA_PropertySensor::Type = {
        PyVarObject_HEAD_INIT(NULL, 0)
@@ -348,9 +374,11 @@
 };
 
 PyAttributeDef SCA_PropertySensor::Attributes[] = {
-       
KX_PYATTRIBUTE_INT_RW("mode",KX_PROPSENSOR_NODEF,KX_PROPSENSOR_MAX-1,false,SCA_PropertySensor,m_checktype),
+       
KX_PYATTRIBUTE_INT_RW_CHECK("mode",KX_PROPSENSOR_NODEF,KX_PROPSENSOR_MAX-1,false,SCA_PropertySensor,m_checktype,modeChange),
        
KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,100,false,SCA_PropertySensor,m_checkpropname,CheckProperty),
        
KX_PYATTRIBUTE_STRING_RW_CHECK("value",0,100,false,SCA_PropertySensor,m_checkpropval,validValueForProperty),
+       
KX_PYATTRIBUTE_STRING_RW_CHECK("min",0,100,false,SCA_PropertySensor,m_checkpropval,validValueForIntervalProperty),
+       
KX_PYATTRIBUTE_STRING_RW_CHECK("max",0,100,false,SCA_PropertySensor,m_checkpropmaxval,validValueForIntervalProperty),
        { NULL }        //Sentinel
 };
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.h      
2010-03-26 07:17:54 UTC (rev 27763)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.h      
2010-03-26 07:21:48 UTC (rev 27764)
@@ -95,6 +95,16 @@
         */
        static int validValueForProperty(void* self, const PyAttributeDef*);
 
+       /**
+        * Test whether this is a sensible value for interval (type check) and 
updates Range Expression
+        */
+       static int validValueForIntervalProperty(void* self, const 
PyAttributeDef*);
+
+       /**
+        * Test if the new mode is interval. If positive updates Range 
Expression
+        */
+       static int modeChange(void* self, const PyAttributeDef* attrdef);
+
 #endif
 };
 

Modified: trunk/blender/source/gameengine/PyDoc/GameTypes.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/GameTypes.py  2010-03-26 07:17:54 UTC 
(rev 27763)
+++ trunk/blender/source/gameengine/PyDoc/GameTypes.py  2010-03-26 07:21:48 UTC 
(rev 27764)
@@ -5152,6 +5152,10 @@
        @type propName: string
        @ivar value: the value with which the sensor compares to the value of 
the property.
        @type value: string
+       @ivar min: the minimum value of the range used to evaluate the property 
when in interval mode.
+       @type min: string
+       @ivar max: the maximum value of the range used to evaluate the property 
when in interval mode.
+       @type max: string
        """
 #{ Deprecated
        def getType():


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to