diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2010-03-26 10:21:48 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2010-03-26 10:21:48 +0300 |
commit | 3925f58b6a9b0a2c49ce6d0e3534542a4975139b (patch) | |
tree | dae153bac06c8ba95f2e77a3a85904d5909c4d62 /source/gameengine/GameLogic | |
parent | ed035bca5a80f5088766947cb87c404df453e449 (diff) |
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.
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r-- | source/gameengine/GameLogic/SCA_PropertySensor.cpp | 30 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PropertySensor.h | 10 |
2 files changed, 39 insertions, 1 deletions
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 134d34fc00d..24dbdb94f95 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -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 }; diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index 0bc1e9b3579..9a5c4762558 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -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 }; |