change const char* to const std::string&

This commit is contained in:
yinkaile 2013-12-23 14:05:46 +08:00
parent 87103434e3
commit ba809a0096
20 changed files with 115 additions and 122 deletions

View File

@ -56,7 +56,7 @@ Armature *Armature::create()
} }
Armature *Armature::create(const char *name) Armature *Armature::create(const std::string& name)
{ {
Armature *armature = new Armature(); Armature *armature = new Armature();
if (armature && armature->init(name)) if (armature && armature->init(name))
@ -68,7 +68,7 @@ Armature *Armature::create(const char *name)
return nullptr; return nullptr;
} }
Armature *Armature::create(const char *name, Bone *parentBone) Armature *Armature::create(const std::string& name, Bone *parentBone)
{ {
Armature *armature = new Armature(); Armature *armature = new Armature();
if (armature && armature->init(name, parentBone)) if (armature && armature->init(name, parentBone))
@ -105,7 +105,7 @@ bool Armature::init()
} }
bool Armature::init(const char *name) bool Armature::init(const std::string& name)
{ {
bool bRet = false; bool bRet = false;
do do
@ -121,14 +121,12 @@ bool Armature::init(const char *name)
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
_name = name == nullptr ? "" : name; _name = name;
ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance(); ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance();
if(_name.length() != 0) if(_name.length() != 0)
{ {
_name = name;
AnimationData *animationData = armatureDataManager->getAnimationData(name); AnimationData *animationData = armatureDataManager->getAnimationData(name);
CCASSERT(animationData, "AnimationData not exist! "); CCASSERT(animationData, "AnimationData not exist! ");
@ -196,14 +194,14 @@ bool Armature::init(const char *name)
return bRet; return bRet;
} }
bool Armature::init(const char *name, Bone *parentBone) bool Armature::init(const std::string& name, Bone *parentBone)
{ {
_parentBone = parentBone; _parentBone = parentBone;
return init(name); return init(name);
} }
Bone *Armature::createBone(const char *boneName) Bone *Armature::createBone(const std::string& boneName)
{ {
Bone *existedBone = getBone(boneName); Bone *existedBone = getBone(boneName);
if(existedBone != nullptr) if(existedBone != nullptr)
@ -233,12 +231,12 @@ Bone *Armature::createBone(const char *boneName)
} }
void Armature::addBone(Bone *bone, const char *parentName) void Armature::addBone(Bone *bone, const std::string& parentName)
{ {
CCASSERT( bone != nullptr, "Argument must be non-nil"); CCASSERT( bone != nullptr, "Argument must be non-nil");
CCASSERT(_boneDic.at(bone->getName()) == nullptr, "bone already added. It can't be added again"); CCASSERT(_boneDic.at(bone->getName()) == nullptr, "bone already added. It can't be added again");
if (nullptr != parentName) if ("" != parentName)
{ {
Bone *boneParent = _boneDic.at(parentName); Bone *boneParent = _boneDic.at(parentName);
if (boneParent) if (boneParent)
@ -278,13 +276,13 @@ void Armature::removeBone(Bone *bone, bool recursion)
} }
Bone *Armature::getBone(const char *name) const Bone *Armature::getBone(const std::string& name) const
{ {
return _boneDic.at(name); return _boneDic.at(name);
} }
void Armature::changeBoneParent(Bone *bone, const char *parentName) void Armature::changeBoneParent(Bone *bone, const std::string& parentName)
{ {
CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!"); CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!");
@ -294,7 +292,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
bone->setParentBone(nullptr); bone->setParentBone(nullptr);
} }
if (parentName != nullptr) if (parentName != "")
{ {
Bone *boneParent = _boneDic.at(parentName); Bone *boneParent = _boneDic.at(parentName);

View File

@ -84,9 +84,9 @@ public:
* @param name Armature will use the name to find the ArmatureData to initializes it. * @param name Armature will use the name to find the ArmatureData to initializes it.
* @return A initialized armature which is marked as "autorelease". * @return A initialized armature which is marked as "autorelease".
*/ */
static Armature *create(const char *name); static Armature *create(const std::string& name);
static Armature *create(const char *name, Bone *parentBone); static Armature *create(const std::string& name, Bone *parentBone);
public: public:
/** /**
@ -108,29 +108,29 @@ public:
* Init an armature with specified name * Init an armature with specified name
* @param name Armature name * @param name Armature name
*/ */
virtual bool init(const char *name); virtual bool init(const std::string& name);
virtual bool init(const char *name, Bone *parentBone); virtual bool init(const std::string& name, Bone *parentBone);
/** /**
* Add a Bone to this Armature, * Add a Bone to this Armature,
* *
* @param bone The Bone you want to add to Armature * @param bone The Bone you want to add to Armature
* @param parentName The parent Bone's name you want to add to . If it's nullptr, then set Armature to its parent * @param parentName The parent Bone's name you want to add to . If it's nullptr, then set Armature to its parent
*/ */
virtual void addBone(Bone *bone, const char *parentName); virtual void addBone(Bone *bone, const std::string& parentName);
/** /**
* Get a bone with the specified name * Get a bone with the specified name
* *
* @param name The bone's name you want to get * @param name The bone's name you want to get
*/ */
virtual Bone *getBone(const char *name) const; virtual Bone *getBone(const std::string& name) const;
/** /**
* Change a bone's parent with the specified parent name. * Change a bone's parent with the specified parent name.
* *
* @param bone The bone you want to change parent * @param bone The bone you want to change parent
* @param parentName The new parent's name. * @param parentName The new parent's name.
*/ */
virtual void changeBoneParent(Bone *bone, const char *parentName); virtual void changeBoneParent(Bone *bone, const std::string& parentName);
/** /**
* Remove a bone with the specified name. If recursion it will also remove child Bone recursionly. * Remove a bone with the specified name. If recursion it will also remove child Bone recursionly.
* *
@ -247,7 +247,7 @@ protected:
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
Bone *createBone(const char *boneName ); Bone *createBone(const std::string& boneName );
protected: protected:
ArmatureData *_armatureData; ArmatureData *_armatureData;

View File

@ -164,11 +164,11 @@ float ArmatureAnimation::getSpeedScale() const
} }
void ArmatureAnimation::play(const char *animationName, int durationTo, int loop) void ArmatureAnimation::play(const std::string& animationName, int durationTo, int loop)
{ {
CCASSERT(_animationData, "_animationData can not be null"); CCASSERT(_animationData, "_animationData can not be null");
_movementData = _animationData->getMovement(animationName); _movementData = _animationData->getMovement(animationName.c_str());
CCASSERT(_movementData, "_movementData can not be null"); CCASSERT(_movementData, "_movementData can not be null");
//! Get key frame count //! Get key frame count
@ -461,11 +461,11 @@ void ArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCall
_frameEventCallFunc = callFunc; _frameEventCallFunc = callFunc;
} }
void ArmatureAnimation::setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> listener) void ArmatureAnimation::setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const std::string& movementID)> listener)
{ {
_movementEventListener = listener; _movementEventListener = listener;
} }
void ArmatureAnimation::setFrameEventCallFunc(std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> listener) void ArmatureAnimation::setFrameEventCallFunc(std::function<void(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)> listener)
{ {
_frameEventListener = listener; _frameEventListener = listener;
} }
@ -477,7 +477,7 @@ void ArmatureAnimation::setUserObject(Object *pUserObject)
_userObject = pUserObject; _userObject = pUserObject;
} }
void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex) void ArmatureAnimation::frameEvent(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)
{ {
if ((_frameEventTarget && _frameEventCallFunc) || _frameEventListener) if ((_frameEventTarget && _frameEventCallFunc) || _frameEventListener)
{ {
@ -492,7 +492,7 @@ void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int o
} }
void ArmatureAnimation::movementEvent(Armature *armature, MovementEventType movementType, const char *movementID) void ArmatureAnimation::movementEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
{ {
if ((_movementEventTarget && _movementEventCallFunc) || _movementEventListener) if ((_movementEventTarget && _movementEventCallFunc) || _movementEventListener)
{ {

View File

@ -44,8 +44,8 @@ enum MovementEventType
class Armature; class Armature;
class Bone; class Bone;
typedef void (cocos2d::Object::*SEL_MovementEventCallFunc)(Armature *, MovementEventType, const char *); typedef void (cocos2d::Object::*SEL_MovementEventCallFunc)(Armature *, MovementEventType, const std::string&);
typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const char *, int, int); typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const std::string&, int, int);
#define movementEvent_selector(_SELECTOR) (cocostudio::SEL_MovementEventCallFunc)(&_SELECTOR) #define movementEvent_selector(_SELECTOR) (cocostudio::SEL_MovementEventCallFunc)(&_SELECTOR)
#define frameEvent_selector(_SELECTOR) (cocostudio::SEL_FrameEventCallFunc)(&_SELECTOR) #define frameEvent_selector(_SELECTOR) (cocostudio::SEL_FrameEventCallFunc)(&_SELECTOR)
@ -53,7 +53,7 @@ typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const char *, in
struct FrameEvent struct FrameEvent
{ {
Bone *bone; Bone *bone;
const char *frameEventName; std::string frameEventName;
int originFrameIndex; int originFrameIndex;
int currentFrameIndex; int currentFrameIndex;
}; };
@ -62,7 +62,7 @@ struct MovementEvent
{ {
Armature *armature; Armature *armature;
MovementEventType movementType; MovementEventType movementType;
const char *movementID; std::string movementID;
}; };
class ArmatureAnimation : public ProcessBase class ArmatureAnimation : public ProcessBase
@ -123,7 +123,7 @@ public:
* loop = 0 : this animation is not loop * loop = 0 : this animation is not loop
* loop > 0 : this animation is loop * loop > 0 : this animation is loop
*/ */
virtual void play(const char *animationName, int durationTo = -1, int loop = -1); virtual void play(const std::string& animationName, int durationTo = -1, int loop = -1);
/** /**
* Play animation by index, the other param is the same to play. * Play animation by index, the other param is the same to play.
@ -191,8 +191,8 @@ public:
*/ */
CC_DEPRECATED_ATTRIBUTE void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc); CC_DEPRECATED_ATTRIBUTE void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc);
void setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> listener); void setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const std::string& movementID)> listener);
void setFrameEventCallFunc(std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> listener); void setFrameEventCallFunc(std::function<void(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)> listener);
virtual void setAnimationData(AnimationData *data) virtual void setAnimationData(AnimationData *data)
{ {
@ -254,12 +254,12 @@ protected:
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex); void frameEvent(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex);
/** /**
* Emit a movement event * Emit a movement event
*/ */
void movementEvent(Armature *armature, MovementEventType movementType, const char *movementID); void movementEvent(Armature *armature, MovementEventType movementType, const std::string& movementID);
void updateMovementList(); void updateMovementList();
@ -319,8 +319,8 @@ protected:
cocos2d::Object *_frameEventTarget; cocos2d::Object *_frameEventTarget;
std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> _movementEventListener; std::function<void(Armature *armature, MovementEventType movementType, const std::string& movementID)> _movementEventListener;
std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> _frameEventListener; std::function<void(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)> _frameEventListener;
}; };
} }

View File

@ -89,7 +89,7 @@ bool ArmatureDataManager::init()
return bRet; return bRet;
} }
void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath) void ArmatureDataManager::removeArmatureFileInfo(const std::string& configFilePath)
{ {
if (RelativeData *data = getRelativeData(configFilePath)) if (RelativeData *data = getRelativeData(configFilePath))
{ {
@ -119,7 +119,7 @@ void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath)
} }
void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath) void ArmatureDataManager::addArmatureData(const std::string& id, ArmatureData *armatureData, const std::string& configFilePath)
{ {
if (RelativeData *data = getRelativeData(configFilePath)) if (RelativeData *data = getRelativeData(configFilePath))
{ {
@ -129,19 +129,19 @@ void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armature
_armarureDatas.insert(id, armatureData); _armarureDatas.insert(id, armatureData);
} }
ArmatureData *ArmatureDataManager::getArmatureData(const char *id) ArmatureData *ArmatureDataManager::getArmatureData(const std::string& id)
{ {
ArmatureData *armatureData = nullptr; ArmatureData *armatureData = nullptr;
armatureData = (ArmatureData *)_armarureDatas.at(id); armatureData = (ArmatureData *)_armarureDatas.at(id);
return armatureData; return armatureData;
} }
void ArmatureDataManager::removeArmatureData(const char *id) void ArmatureDataManager::removeArmatureData(const std::string& id)
{ {
_armarureDatas.erase(id); _armarureDatas.erase(id);
} }
void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath) void ArmatureDataManager::addAnimationData(const std::string& id, AnimationData *animationData, const std::string& configFilePath)
{ {
if (RelativeData *data = getRelativeData(configFilePath)) if (RelativeData *data = getRelativeData(configFilePath))
{ {
@ -151,19 +151,19 @@ void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animat
_animationDatas.insert(id, animationData); _animationDatas.insert(id, animationData);
} }
AnimationData *ArmatureDataManager::getAnimationData(const char *id) AnimationData *ArmatureDataManager::getAnimationData(const std::string& id)
{ {
AnimationData *animationData = nullptr; AnimationData *animationData = nullptr;
animationData = (AnimationData *)_animationDatas.at(id); animationData = (AnimationData *)_animationDatas.at(id);
return animationData; return animationData;
} }
void ArmatureDataManager::removeAnimationData(const char *id) void ArmatureDataManager::removeAnimationData(const std::string& id)
{ {
_animationDatas.erase(id); _animationDatas.erase(id);
} }
void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData, const char *configFilePath) void ArmatureDataManager::addTextureData(const std::string& id, TextureData *textureData, const std::string& configFilePath)
{ {
if (RelativeData *data = getRelativeData(configFilePath)) if (RelativeData *data = getRelativeData(configFilePath))
{ {
@ -174,7 +174,7 @@ void ArmatureDataManager::addTextureData(const char *id, TextureData *textureDat
} }
TextureData *ArmatureDataManager::getTextureData(const char *id) TextureData *ArmatureDataManager::getTextureData(const std::string& id)
{ {
TextureData *textureData = nullptr; TextureData *textureData = nullptr;
textureData = (TextureData *)_textureDatas.at(id); textureData = (TextureData *)_textureDatas.at(id);
@ -182,12 +182,12 @@ TextureData *ArmatureDataManager::getTextureData(const char *id)
} }
void ArmatureDataManager::removeTextureData(const char *id) void ArmatureDataManager::removeTextureData(const std::string& id)
{ {
_textureDatas.erase(id); _textureDatas.erase(id);
} }
void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath) void ArmatureDataManager::addArmatureFileInfo(const std::string& configFilePath)
{ {
addRelativeData(configFilePath); addRelativeData(configFilePath);
@ -195,7 +195,7 @@ void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath)
DataReaderHelper::getInstance()->addDataFromFile(configFilePath); DataReaderHelper::getInstance()->addDataFromFile(configFilePath);
} }
void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector) void ArmatureDataManager::addArmatureFileInfoAsync(const std::string& configFilePath, Object *target, SEL_SCHEDULE selector)
{ {
addRelativeData(configFilePath); addRelativeData(configFilePath);
@ -203,7 +203,7 @@ void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, O
DataReaderHelper::getInstance()->addDataFromFileAsync("", "", configFilePath, target, selector); DataReaderHelper::getInstance()->addDataFromFileAsync("", "", configFilePath, target, selector);
} }
void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath) void ArmatureDataManager::addArmatureFileInfo(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath)
{ {
addRelativeData(configFilePath); addRelativeData(configFilePath);
@ -212,7 +212,7 @@ void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char
addSpriteFrameFromFile(plistPath, imagePath); addSpriteFrameFromFile(plistPath, imagePath);
} }
void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector) void ArmatureDataManager::addArmatureFileInfoAsync(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath, Object *target, SEL_SCHEDULE selector)
{ {
addRelativeData(configFilePath); addRelativeData(configFilePath);
@ -221,7 +221,7 @@ void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const
addSpriteFrameFromFile(plistPath, imagePath); addSpriteFrameFromFile(plistPath, imagePath);
} }
void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath, const char *configFilePath) void ArmatureDataManager::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath, const std::string& configFilePath)
{ {
if (RelativeData *data = getRelativeData(configFilePath)) if (RelativeData *data = getRelativeData(configFilePath))
{ {
@ -249,7 +249,7 @@ const cocos2d::Map<std::string, TextureData*>& ArmatureDataManager::getTextureDa
return _textureDatas; return _textureDatas;
} }
void CCArmatureDataManager::addRelativeData(const char *configFilePath) void CCArmatureDataManager::addRelativeData(const std::string& configFilePath)
{ {
if (_relativeDatas.find(configFilePath) == _relativeDatas.end()) if (_relativeDatas.find(configFilePath) == _relativeDatas.end())
{ {
@ -257,7 +257,7 @@ void CCArmatureDataManager::addRelativeData(const char *configFilePath)
} }
} }
RelativeData *CCArmatureDataManager::getRelativeData(const char* configFilePath) RelativeData *CCArmatureDataManager::getRelativeData(const std::string& configFilePath)
{ {
return &_relativeDatas[configFilePath]; return &_relativeDatas[configFilePath];
} }

View File

@ -77,89 +77,89 @@ public:
* @param id The id of the armature data * @param id The id of the armature data
* @param armatureData ArmatureData * * @param armatureData ArmatureData *
*/ */
void addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath = ""); void addArmatureData(const std::string& id, ArmatureData *armatureData, const std::string& configFilePath = "");
/** /**
* @brief get armature data * @brief get armature data
* @param id the id of the armature data you want to get * @param id the id of the armature data you want to get
* @return ArmatureData * * @return ArmatureData *
*/ */
ArmatureData *getArmatureData(const char *id); ArmatureData *getArmatureData(const std::string& id);
/** /**
* @brief remove armature data * @brief remove armature data
* @param id the id of the armature data you want to get * @param id the id of the armature data you want to get
*/ */
void removeArmatureData(const char *id); void removeArmatureData(const std::string& id);
/** /**
* @brief add animation data * @brief add animation data
* @param id the id of the animation data * @param id the id of the animation data
* @return AnimationData * * @return AnimationData *
*/ */
void addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath = ""); void addAnimationData(const std::string& id, AnimationData *animationData, const std::string& configFilePath = "");
/** /**
* @brief get animation data from _animationDatas(Dictionary) * @brief get animation data from _animationDatas(Dictionary)
* @param id the id of the animation data you want to get * @param id the id of the animation data you want to get
* @return AnimationData * * @return AnimationData *
*/ */
AnimationData *getAnimationData(const char *id); AnimationData *getAnimationData(const std::string& id);
/** /**
* @brief remove animation data * @brief remove animation data
* @param id the id of the animation data * @param id the id of the animation data
*/ */
void removeAnimationData(const char *id); void removeAnimationData(const std::string& id);
/** /**
* @brief add texture data * @brief add texture data
* @param id the id of the texture data * @param id the id of the texture data
* @return TextureData * * @return TextureData *
*/ */
void addTextureData(const char *id, TextureData *textureData, const char *configFilePath = ""); void addTextureData(const std::string& id, TextureData *textureData, const std::string& configFilePath = "");
/** /**
* @brief get texture data * @brief get texture data
* @param id the id of the texture data you want to get * @param id the id of the texture data you want to get
* @return TextureData * * @return TextureData *
*/ */
TextureData *getTextureData(const char *id); TextureData *getTextureData(const std::string& id);
/** /**
* @brief remove texture data * @brief remove texture data
* @param id the id of the texture data you want to get * @param id the id of the texture data you want to get
*/ */
void removeTextureData(const char *id); void removeTextureData(const std::string& id);
/** /**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
*/ */
void addArmatureFileInfo(const char *configFilePath); void addArmatureFileInfo(const std::string& configFilePath);
/** /**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
* It will load data in a new thread * It will load data in a new thread
*/ */
void addArmatureFileInfoAsync(const char *configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector); void addArmatureFileInfoAsync(const std::string& configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
/** /**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
*/ */
void addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath); void addArmatureFileInfo(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath);
/** /**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
* It will load data in a new thread * It will load data in a new thread
*/ */
void addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector); void addArmatureFileInfoAsync(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
/** /**
* @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name * @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
*/ */
void addSpriteFrameFromFile(const char *plistPath, const char *imagePath, const char *configFilePath = ""); void addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath, const std::string& configFilePath = "");
virtual void removeArmatureFileInfo(const char *configFilePath); virtual void removeArmatureFileInfo(const std::string& configFilePath);
/** /**
@ -173,8 +173,8 @@ public:
const cocos2d::Map<std::string, TextureData*>& getTextureDatas() const; const cocos2d::Map<std::string, TextureData*>& getTextureDatas() const;
protected: protected:
void addRelativeData(const char* configFilePath); void addRelativeData(const std::string& configFilePath);
RelativeData *getRelativeData(const char* configFilePath); RelativeData *getRelativeData(const std::string& configFilePath);
private: private:
/** /**
* @brief save amature datas * @brief save amature datas

View File

@ -47,7 +47,7 @@ Bone *Bone::create()
} }
Bone *Bone::create(const char *name) Bone *Bone::create(const std::string& name)
{ {
Bone *pBone = new Bone(); Bone *pBone = new Bone();
@ -101,16 +101,13 @@ bool Bone::init()
} }
bool Bone::init(const char *name) bool Bone::init(const std::string& name)
{ {
bool bRet = false; bool bRet = false;
do do
{ {
if(nullptr != name)
{
_name = name; _name = name;
}
CC_SAFE_DELETE(_tweenData); CC_SAFE_DELETE(_tweenData);
_tweenData = new FrameData(); _tweenData = new FrameData();
@ -425,7 +422,7 @@ void Bone::changeDisplayByIndex(int index, bool force)
} }
void Bone::changeDisplayByName(const char *name, bool force) void Bone::changeDisplayByName(const std::string& name, bool force)
{ {
_displayManager->changeDisplayByName(name, force); _displayManager->changeDisplayByName(name, force);
} }

View File

@ -50,7 +50,7 @@ public:
* @param name If name is not null, then set name to the bone's name * @param name If name is not null, then set name to the bone's name
* @return A initialized bone which is marked as "autorelease". * @return A initialized bone which is marked as "autorelease".
*/ */
static Bone *create(const char *name); static Bone *create(const std::string& name);
public: public:
/** /**
@ -72,7 +72,7 @@ public:
* Initializes a Bone with the specified name * Initializes a Bone with the specified name
* @param name Bone's name. * @param name Bone's name.
*/ */
virtual bool init(const char *name); virtual bool init(const std::string& name);
/** /**
* Add display and use displayData to init the display. * Add display and use displayData to init the display.
@ -92,7 +92,7 @@ public:
void removeDisplay(int index); void removeDisplay(int index);
void changeDisplayByIndex(int index, bool force); void changeDisplayByIndex(int index, bool force);
void changeDisplayByName(const char *name, bool force); void changeDisplayByName(const std::string& name, bool force);
/** /**
* Add a child to this bone, and it will let this child call setParent(Bone *parent) function to set self to it's parent * Add a child to this bone, and it will let this child call setParent(Bone *parent) function to set self to it's parent

View File

@ -254,7 +254,7 @@ DataReaderHelper::~DataReaderHelper()
_dataReaderHelper = nullptr; _dataReaderHelper = nullptr;
} }
void DataReaderHelper::addDataFromFile(const char *filePath) void DataReaderHelper::addDataFromFile(const std::string& filePath)
{ {
/* /*
* Check if file is already added to ArmatureDataManager, if then return. * Check if file is already added to ArmatureDataManager, if then return.
@ -307,7 +307,7 @@ void DataReaderHelper::addDataFromFile(const char *filePath)
free(pFileContent); free(pFileContent);
} }
void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *plistPath, const char *filePath, Object *target, SEL_SCHEDULE selector) void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Object *target, SEL_SCHEDULE selector)
{ {
/* /*
* Check if file is already added to ArmatureDataManager, if then return. * Check if file is already added to ArmatureDataManager, if then return.
@ -470,7 +470,7 @@ void DataReaderHelper::addDataAsyncCallBack(float dt)
} }
void DataReaderHelper::removeConfigFile(const char *configFile) void DataReaderHelper::removeConfigFile(const std::string& configFile)
{ {
std::vector<std::string>::iterator it = _configFileList.end(); std::vector<std::string>::iterator it = _configFileList.end();
for (std::vector<std::string>::iterator i = _configFileList.begin(); i != _configFileList.end(); i++) for (std::vector<std::string>::iterator i = _configFileList.begin(); i != _configFileList.end(); i++)

View File

@ -108,12 +108,12 @@ public:
*/ */
~DataReaderHelper(); ~DataReaderHelper();
void addDataFromFile(const char *filePath); void addDataFromFile(const std::string& filePath);
void addDataFromFileAsync(const char *imagePath, const char *plistPath, const char *filePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector); void addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
void addDataAsyncCallBack(float dt); void addDataAsyncCallBack(float dt);
void removeConfigFile(const char *configFile); void removeConfigFile(const std::string& configFile);
public: public:
/** /**

View File

@ -142,7 +142,7 @@ Color4B BaseData::getColor()
return Color4B(r, g, b, a); return Color4B(r, g, b, a);
} }
const char *DisplayData::changeDisplayToTexture(const char *displayName) const std::string& DisplayData::changeDisplayToTexture(const std::string& displayName)
{ {
// remove .xxx // remove .xxx
std::string textureName = displayName; std::string textureName = displayName;
@ -241,7 +241,7 @@ void ArmatureData::addBoneData(BoneData *boneData)
boneDataDic.insert(boneData->name, boneData); boneDataDic.insert(boneData->name, boneData);
} }
BoneData *ArmatureData::getBoneData(const char *boneName) BoneData *ArmatureData::getBoneData(const std::string& boneName)
{ {
return static_cast<BoneData*>(boneDataDic.at(boneName)); return static_cast<BoneData*>(boneDataDic.at(boneName));
} }
@ -343,7 +343,7 @@ void MovementData::addMovementBoneData(MovementBoneData *movBoneData)
movBoneDataDic.insert(movBoneData->name, movBoneData); movBoneDataDic.insert(movBoneData->name, movBoneData);
} }
MovementBoneData *MovementData::getMovementBoneData(const char *boneName) MovementBoneData *MovementData::getMovementBoneData(const std::string& boneName)
{ {
return movBoneDataDic.at(boneName); return movBoneDataDic.at(boneName);
} }
@ -364,7 +364,7 @@ void AnimationData::addMovement(MovementData *movData)
movementNames.push_back(movData->name); movementNames.push_back(movData->name);
} }
MovementData *AnimationData::getMovement(const char *movementName) MovementData *AnimationData::getMovement(const std::string& movementName)
{ {
return movementDataDic.at(movementName); return movementDataDic.at(movementName);
} }

View File

@ -136,7 +136,7 @@ class DisplayData : public cocos2d::Object
public: public:
CC_CREATE_NO_PARAM_NO_INIT(DisplayData) CC_CREATE_NO_PARAM_NO_INIT(DisplayData)
static const char *changeDisplayToTexture(const char *displayName); static const std::string& changeDisplayToTexture(const std::string& displayName);
public: public:
/** /**
* @js ctor * @js ctor
@ -279,7 +279,7 @@ public:
bool init(); bool init();
void addBoneData(BoneData *boneData); void addBoneData(BoneData *boneData);
BoneData *getBoneData(const char *boneName); BoneData *getBoneData(const std::string& boneName);
public: public:
std::string name; std::string name;
cocos2d::Map<std::string, BoneData*> boneDataDic; cocos2d::Map<std::string, BoneData*> boneDataDic;
@ -403,7 +403,7 @@ public:
~MovementData(void); ~MovementData(void);
void addMovementBoneData(MovementBoneData *movBoneData); void addMovementBoneData(MovementBoneData *movBoneData);
MovementBoneData *getMovementBoneData(const char *boneName); MovementBoneData *getMovementBoneData(const std::string& boneName);
public: public:
std::string name; std::string name;
int duration; //! the frames this movement will last int duration; //! the frames this movement will last
@ -435,7 +435,7 @@ public:
/** /**
* @brief save movment bone data * @brief save movment bone data
* @key const char * * @key const std::string&
* @value MovementBoneData * * @value MovementBoneData *
*/ */
cocos2d::Map<std::string, MovementBoneData*> movBoneDataDic; cocos2d::Map<std::string, MovementBoneData*> movBoneDataDic;
@ -465,7 +465,7 @@ public:
~AnimationData(void); ~AnimationData(void);
void addMovement(MovementData *movData); void addMovement(MovementData *movData);
MovementData *getMovement(const char *movementName); MovementData *getMovement(const std::string& movementName);
ssize_t getMovementCount(); ssize_t getMovementCount();
public: public:
std::string name; std::string name;

View File

@ -243,7 +243,7 @@ void DisplayManager::changeDisplayByIndex(int index, bool force)
setCurrentDecorativeDisplay(decoDisplay); setCurrentDecorativeDisplay(decoDisplay);
} }
void CCDisplayManager::changeDisplayByName(const char *name, bool force) void CCDisplayManager::changeDisplayByName(const std::string& name, bool force)
{ {
for (int i = 0; i<_decoDisplayList.size(); i++) for (int i = 0; i<_decoDisplayList.size(); i++)
{ {

View File

@ -85,7 +85,7 @@ public:
*/ */
void changeDisplayByIndex(int index, bool force); void changeDisplayByIndex(int index, bool force);
void changeDisplayByName(const char *name, bool force); void changeDisplayByName(const std::string& name, bool force);
cocos2d::Node *getDisplayRenderNode() const; cocos2d::Node *getDisplayRenderNode() const;
DisplayType getDisplayRenderNodeType() const; DisplayType getDisplayRenderNodeType() const;

View File

@ -51,7 +51,7 @@ Skin *Skin::create()
return nullptr; return nullptr;
} }
Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName) Skin *Skin::createWithSpriteFrameName(const std::string& pszSpriteFrameName)
{ {
Skin *skin = new Skin(); Skin *skin = new Skin();
if(skin && skin->initWithSpriteFrameName(pszSpriteFrameName)) if(skin && skin->initWithSpriteFrameName(pszSpriteFrameName))
@ -63,7 +63,7 @@ Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName)
return nullptr; return nullptr;
} }
Skin *Skin::create(const char *pszFileName) Skin *Skin::create(const std::string& pszFileName)
{ {
Skin *skin = new Skin(); Skin *skin = new Skin();
if(skin && skin->initWithFile(pszFileName)) if(skin && skin->initWithFile(pszFileName))

View File

@ -34,8 +34,8 @@ class Skin : public cocos2d::Sprite
{ {
public: public:
static Skin *create(); static Skin *create();
static Skin *createWithSpriteFrameName(const char *pszSpriteFrameName); static Skin *createWithSpriteFrameName(const std::string& pszSpriteFrameName);
static Skin *create(const char *pszFileName); static Skin *create(const std::string& pszFileName);
public: public:
/** /**
* @js ctor * @js ctor

View File

@ -47,7 +47,7 @@ void SpriteFrameCacheHelper::purge()
_spriteFrameCacheHelper = nullptr; _spriteFrameCacheHelper = nullptr;
} }
void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath) void SpriteFrameCacheHelper::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath)
{ {
CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath); CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath);
} }

View File

@ -47,7 +47,7 @@ public:
/** /**
* @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name * @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
*/ */
void addSpriteFrameFromFile(const char *plistPath, const char *imagePath); void addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath);
private: private:
SpriteFrameCacheHelper(); SpriteFrameCacheHelper();

View File

@ -535,20 +535,18 @@ std::string TestAnimationEvent::title() const
{ {
return "Test Armature Animation Event"; return "Test Armature Animation Event";
} }
void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const char *movementID) void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
{ {
std::string id = movementID;
if (movementType == LOOP_COMPLETE) if (movementType == LOOP_COMPLETE)
{ {
if (id.compare("Fire") == 0) if (movementID.compare("Fire") == 0)
{ {
ActionInterval *actionToRight = MoveTo::create(2, Point(VisibleRect::right().x - 50, VisibleRect::right().y)); ActionInterval *actionToRight = MoveTo::create(2, Point(VisibleRect::right().x - 50, VisibleRect::right().y));
armature->stopAllActions(); armature->stopAllActions();
armature->runAction(Sequence::create(actionToRight, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback1, this)), nullptr)); armature->runAction(Sequence::create(actionToRight, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback1, this)), nullptr));
armature->getAnimation()->play("Walk"); armature->getAnimation()->play("Walk");
} }
else if (id.compare("FireMax") == 0) else if (movementID.compare("FireMax") == 0)
{ {
ActionInterval *actionToLeft = MoveTo::create(2, Point(VisibleRect::left().x + 50, VisibleRect::left().y)); ActionInterval *actionToLeft = MoveTo::create(2, Point(VisibleRect::left().x + 50, VisibleRect::left().y));
armature->stopAllActions(); armature->stopAllActions();
@ -596,9 +594,9 @@ std::string TestFrameEvent::title() const
{ {
return "Test Frame Event"; return "Test Frame Event";
} }
void TestFrameEvent::onFrameEvent(Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex) void TestFrameEvent::onFrameEvent(Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
{ {
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt, currentFrameIndex); CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
if (!_gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG) || _gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG)->isDone()) if (!_gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG) || _gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG)->isDone())
{ {
@ -778,9 +776,9 @@ std::string TestColliderDetector::title() const
{ {
return "Test Collider Detector"; return "Test Collider Detector";
} }
void TestColliderDetector::onFrameEvent(Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex) void TestColliderDetector::onFrameEvent(Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
{ {
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt, currentFrameIndex); CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
/* /*
* originFrameIndex is the frame index editted in Action Editor * originFrameIndex is the frame index editted in Action Editor

View File

@ -153,7 +153,7 @@ public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title() const override; virtual std::string title() const override;
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const char *movementID); void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
void callback1(); void callback1();
void callback2(); void callback2();
@ -166,7 +166,7 @@ class TestFrameEvent : public ArmatureTestLayer
public: public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title() const override; virtual std::string title() const override;
void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
void checkAction(float dt); void checkAction(float dt);
protected: protected:
NodeGrid* _gridNode; NodeGrid* _gridNode;
@ -215,7 +215,7 @@ public:
virtual void draw(); virtual void draw();
virtual void update(float delta); virtual void update(float delta);
void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
void initWorld(); void initWorld();
@ -273,7 +273,7 @@ public:
virtual void update(float delta); virtual void update(float delta);
virtual void draw(); virtual void draw();
void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
void initWorld() {}; void initWorld() {};
cocostudio::Armature *armature; cocostudio::Armature *armature;