diff --git a/cocos/editor-support/cocostudio/CCComAttribute.cpp b/cocos/editor-support/cocostudio/CCComAttribute.cpp index cd20cf3c02..c0c590af58 100644 --- a/cocos/editor-support/cocostudio/CCComAttribute.cpp +++ b/cocos/editor-support/cocostudio/CCComAttribute.cpp @@ -58,6 +58,51 @@ ComAttribute* ComAttribute::create(void) return pRet; } +void ComAttribute::setInt(const char *key, int value) +{ + CCASSERT(key != NULL, "Argument must be non-nil"); + _jsonDict->insertItem(key, value); +} + +void ComAttribute::setFloat(const char *key, float value) +{ + CCASSERT(key != NULL, "Argument must be non-nil"); + _jsonDict->insertItem(key, value); +} + +void ComAttribute::setBool(const char *key, bool value) +{ + CCASSERT(key != NULL, "Argument must be non-nil"); + _jsonDict->insertItem(key, value); +} + +void ComAttribute::setCString(const char *key, const char *value) +{ + CCASSERT(key != NULL, "Argument must be non-nil"); + _jsonDict->insertItem(key, value); +} + + +int ComAttribute::getInt(const char *key) const +{ + return _jsonDict->getItemIntValue(key, -1); +} + +float ComAttribute::getFloat(const char *key) const +{ + return _jsonDict->getItemFloatValue(key, -1.0f); +} + +bool ComAttribute::getBool(const char *key) const +{ + return _jsonDict->getItemBoolvalue(key, false); +} + +const char* ComAttribute::getCString(const char *key) const +{ + return _jsonDict->getItemStringValue(key); +} + JsonDictionary* ComAttribute::getDict() const { return _jsonDict; diff --git a/cocos/editor-support/cocostudio/CCComAttribute.h b/cocos/editor-support/cocostudio/CCComAttribute.h index dcb1b177e3..dea396c121 100644 --- a/cocos/editor-support/cocostudio/CCComAttribute.h +++ b/cocos/editor-support/cocostudio/CCComAttribute.h @@ -47,6 +47,17 @@ protected: public: virtual bool init(); static ComAttribute* create(void); + + void setInt(const char *key, int value); + void setFloat(const char *key, float value); + void setBool(const char *key, bool value); + void setCString(const char *key, const char *value); + + int getInt(const char *key) const; + float getFloat(const char *key) const; + bool getBool(const char *key) const; + const char* getCString(const char *key) const; + JsonDictionary* getDict() const; private: diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp index 2bfc93c02c..e563377357 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp @@ -39,7 +39,8 @@ void SceneController::onEnter() _projectiles->retain(); ((ComAudio*)(_owner->getComponent("Audio")))->playBackgroundMusic("background-music-aac.wav", true); - ((ComAttribute*)(_owner->getComponent("ComAttribute")))->getDict()->insertItem("KillCount", 0); + ((ComAttribute*)(_owner->getComponent("ComAttribute")))->setInt("KillCount", 0); + } void SceneController::onExit() @@ -102,10 +103,10 @@ void SceneController::spriteMoveFinished(Node* sender) void SceneController::increaseKillCount() { - int nProjectilesDestroyed = ((ComAttribute*)(_owner->getComponent("ComAttribute")))->getDict()->getItemIntValue("KillCount", -1); + int nProjectilesDestroyed = ((ComAttribute*)(_owner->getComponent("ComAttribute")))->getInt("KillCount"); ComAttribute *p = (ComAttribute*)(_owner->getComponent("ComAttribute")); - p->getDict()->insertItem("KillCount", ++nProjectilesDestroyed); + p->setInt("KillCount", ++nProjectilesDestroyed); if (nProjectilesDestroyed >= 5) {