#pragma once

#include "CAnimation.h"

typedef struct _CCSkeletonFactory *PCCSkeletonFactory;

typedef struct _CCArmatureData : public CCObject {
    static  _CCArmatureData *create() {
        _CCArmatureData *pArmatureData = new _CCArmatureData();
        if (pArmatureData) {
            pArmatureData->autorelease();
            return pArmatureData;
        }
        CC_SAFE_DELETE(pArmatureData);
        return NULL;
    }

    std::string name;
    std::string parent;
    float x;
    float y;
    float z;
    float registrationPointX;
    float registrationPointY;
    float width;
    float height;
} CCArmatureData, *PCCArmatureData;

class CCBoneDisplayFactory {
public:
    virtual CCSprite* createBoneDisplay(const char* _boneName) = 0;
};

class CCArmatureDisplayFactory {
public:
    virtual CCSprite* createArmatureDisplay(const char* _armatureName) = 0;
};

/*ǼܣĹ*/
class CCArmature : public CCNode,
    public CCBoneDisplayFactory,
    public CCArmatureDisplayFactory

{

public:
    /**
    * Ǽɷ
    * @param _name Ǽ
    * @param _animationName 
    * @param _plistPath 
	* @param _imagePath 
	* @param _batchNode 
	* @param _isRadian Ƿû
    */
    static CCArmature *create(const char* _name, const char* _animationName, const char* _plistPath, const char* _imagePath, CCSpriteBatchNode *_batchNode, int _index = 0, bool _isRadian = false, const char* _eachImageSuffix = ".png");

    

public:
    /**
    * 캯
    * @param _display йʾʾ
    * @param _isRadian תǶǷûƣ Starling ʹõǻ
    */
    CCArmature();
    ~CCArmature(void);

    virtual bool init(const char* _name, const char* _animationName, const char* _plistPath, const char* _imagePath,  CCSpriteBatchNode *_batchNode, int _index = 0, bool _isRadian = false, const char* _eachImageSuffix = ".png");

    /**
    *  TweenBoneAnimation
    */
    void	update(float dt);
    /**
    * ɾ
    */
    void	remove();
 
    /**
    * 󶨹
    * @param _name 
    * @param _parentName 󶨵
    * @param _display ʾ
    * @param _index ʾ󶨵ȣ滻ԭʾʹԭʾȡ-1:ӵߴ-2:ִaddChild
    * @return ɵ Bone ʵ
    */
    CCBone	*addBone(const char* _name, const char* _parentName = NULL, CCNode* _display=NULL, int _index = -1);
    /**
    * ȡǼеĹ
    * @param _name 
    */
    CCBone	*getBone(const char* _name);
    /**
    * ɾ
    * @param _name 
    */
    void	removeBone(const char* _name);

private:
    /**
    * @param _cache CCSpriteFrameCache
    * @param _fullName ͼȫ
    * @return  CCSprite ʵ
    */
    CCSprite* getTextureDisplay(CCSpriteFrameCache* _cache, const char* _fullName);
    /**
    * ɽӿ
    */
    CCSprite* createBoneDisplay(const char* _boneName);

    CCSprite* createArmatureDisplay(const char* _armatureName);

public:
	CC_SYNTHESIZE(CCNode *,					mDisplay,					Display);
	CC_SYNTHESIZE(CCARmatureAnimation *,	mAnimation,					Animation);

	CC_SYNTHESIZE(CCBoneDisplayFactory		*, mBoneDisplayFactory,		BoneDisplayFactory);
	CC_SYNTHESIZE(CCArmatureDisplayFactory	*, mArmaureDisplayFactory,	ArmaureDisplayFactory);

	CC_SYNTHESIZE_RETAIN( CCSpriteBatchNode	*, mDisPlayBatchNode,		DisPlayBatchNode);

	CC_SYNTHESIZE_READONLY(std::string, mName, Name);
protected:
    
    
    bool							mIsRadian;
    // <const char*, CCBone*>
    CCDictionary					*mBoneDic;
	// <CCBone*>
    CCArray							*mBoneList;

	const char*						mEachImageSuffix;

	CCSpriteFrameCache				*cache;

	
};

