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.
This commit is contained in:
Dalai Felinto
2010-03-26 07:21:48 +00:00
parent ed035bca5a
commit 3925f58b6a
3 changed files with 43 additions and 1 deletions

View File

@@ -316,10 +316,36 @@ CValue* SCA_PropertySensor::FindIdentifier(const STR_String& identifiername)
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 @@ PyMethodDef SCA_PropertySensor::Methods[] = {
};
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
};

View File

@@ -95,6 +95,16 @@ public:
*/
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
};

View File

@@ -5152,6 +5152,10 @@ class SCA_PropertySensor(SCA_ISensor):
@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():