Timeline* Timeline::clone()
{
    Timeline* timeline = Timeline::create();
    timeline->_actionTag = _actionTag;

    CCObject* object = NULL;
    CCARRAY_FOREACH(_frames, object)
    {
        Frame* frame = static_cast<Frame*>(object);
        Frame* newFrame = frame->clone();
        timeline->addFrame(newFrame);
    }
Beispiel #2
0
Timeline* Timeline::clone()
{
    Timeline* timeline = Timeline::create();
    timeline->_actionTag = _actionTag;

    for (auto frame : _frames)
    {
        Frame* newFrame = frame->clone();
        timeline->addFrame(newFrame);
    }

    return timeline;
}
Timeline* ActionTimelineCache::loadTimeline(const rapidjson::Value& json)
{
    Timeline* timeline = nullptr;

    // get frame type 
    const char* frameType = DICTOOL->getStringValue_json(json, FRAME_TYPE);
    if(frameType == nullptr)
        return nullptr;

    if(frameType && _funcs.find(frameType) != _funcs.end())
    {
        timeline = Timeline::create();

        int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG);
        timeline->setActionTag(actionTag);

        FrameCreateFunc func = _funcs.at(frameType);

        int length = DICTOOL->getArrayCount_json(json, FRAMES);
        for (int i = 0; i<length; i++)
        {
            const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, FRAMES, i);

            Frame* frame = nullptr;

            if (func != nullptr)
            {
                frame = func(dic);

                int frameIndex = DICTOOL->getIntValue_json(dic, FRAME_INDEX);
                frame->setFrameIndex(frameIndex);

                bool tween = DICTOOL->getBooleanValue_json(dic, TWEEN, false);
                frame->setTween(tween);
            }

            timeline->addFrame(frame);
        }
    }

    return timeline;
}
Timeline* ActionTimelineCache::loadTimeline(const rapidjson::Value& json)
{
    Timeline* timeline = NULL;

    // get frame type 
    const char* frameType = DICTOOL->getStringValue_json(json, FRAME_TYPE);
	if(frameType == NULL)
		return NULL;

    FrameCreateCallFunc* func = static_cast<FrameCreateCallFunc*>(_funcs->objectForKey(frameType));

    if(frameType && func)
    {
        timeline = Timeline::create();

        int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG);
        timeline->setActionTag(actionTag);


        int length = DICTOOL->getArrayCount_json(json, FRAMES);
        for (int i = 0; i<length; i++)
        {
            const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, FRAMES, i);

            Frame* frame = NULL;
            frame = func->excute(dic);

            int frameIndex = DICTOOL->getIntValue_json(dic, FRAME_INDEX);
            frame->setFrameIndex(frameIndex);

            bool tween = DICTOOL->getBooleanValue_json(dic, TWEEN, false);
            frame->setTween(tween);

            timeline->addFrame(frame);
        }
    }

    return timeline;
}
Timeline* ActionTimelineCache::loadTimelineWithFlatBuffers(const flatbuffers::TimeLine *flatbuffers)
{
    Timeline* timeline = nullptr;
    
    // property
    std::string property = flatbuffers->property()->c_str();
    if(property == "")
        return nullptr;
    
    CCLOG("property = %s", property.c_str());
    
    if(property != "")
    {
        timeline = Timeline::create();
        
        int actionTag = flatbuffers->actionTag();
        timeline->setActionTag(actionTag);
        
        
        auto framesFlatbuf = flatbuffers->frames();
        int length = framesFlatbuf->size();
        for (int i = 0; i < length; i++)
        {
            auto frameFlatbuf = framesFlatbuf->Get(i);
            Frame* frame = nullptr;
            
            if (property == Property_VisibleForFrame)
            {
                auto boolFrame = frameFlatbuf->boolFrame();
                frame = loadVisibleFrameWithFlatBuffers(boolFrame);
            }
            else if (property == Property_Position)
            {
                auto potisionFrame = frameFlatbuf->pointFrame();
                frame = loadPositionFrameWithFlatBuffers(potisionFrame);
            }
            else if (property == Property_Scale)
            {
                auto scaleFrame = frameFlatbuf->scaleFrame();
                frame = loadScaleFrameWithFlatBuffers(scaleFrame);
            }
            else if (property == Property_RotationSkew)
            {
                auto scaleFrame = frameFlatbuf->scaleFrame();
                frame = loadRotationSkewFrameWithFlatBuffers(scaleFrame);
            }
            else if (property == Property_CColor)
            {
                auto colorFrame = frameFlatbuf->colorFrame();
                frame = loadColorFrameWithFlatBuffers(colorFrame);
            }
            else if (property == Property_FrameEvent)
            {
                auto eventFrame = frameFlatbuf->eventFrame();
                frame = loadEventFrameWithFlatBuffers(eventFrame);
            }
            else if (property == Property_FileData)
            {
                auto textureFrame = frameFlatbuf->textureFrame();
                frame = loadTextureFrameWithFlatBuffers(textureFrame);
            }
            else if (property == Property_Alpha)
            {
                auto intFrame = frameFlatbuf->intFrame();
                frame = loadAlphaFrameWithFlatBuffers(intFrame);
            }
            else if (property == Property_AnchorPoint)
            {
                auto scaleFrame = frameFlatbuf->scaleFrame();
                frame = loadAnchorPointFrameWithFlatBuffers(scaleFrame);
            }
            else if (property == Property_ZOrder)
            {
                auto intFrame = frameFlatbuf->intFrame();
                frame = loadZOrderFrameWithFlatBuffers(intFrame);
            }
            else if (property == Property_ActionValue)
            {
                auto innerActionFrame = frameFlatbuf->innerActionFrame();
                frame = loadInnerActionFrameWithFlatBuffers(innerActionFrame);
            }
            
            if (!frame)
            {
                CCLOG("frame is invalid.");
                continue;
            }
            timeline->addFrame(frame);
        }
    }
    
    return timeline;
}
Timeline* ActionTimelineCache::loadTimelineWithFlatBuffers(const flatbuffers::TimeLine *flatbuffers)
{
    Timeline* timeline = nullptr;
    
    // get frame type
    std::string frameType = flatbuffers->frameType()->c_str();
    if(frameType == "")
        return nullptr;
    
    CCLOG("frameType = %s", frameType.c_str());
    
    if(frameType != "")
    {
        timeline = Timeline::create();
        
        int actionTag = flatbuffers->actionTag();
        timeline->setActionTag(actionTag);
        
        
        auto framesFlatbuf = flatbuffers->frames();
        int length = framesFlatbuf->size();
        for (int i = 0; i < length; i++)
        {
            auto frameFlatbuf = framesFlatbuf->Get(i);
            Frame* frame = nullptr;
            
            if (frameType == FrameType_VisibleFrame)
            {
                auto visibleFrame = frameFlatbuf->visibleFrame();
                frame = loadVisibleFrameWithFlatBuffers(visibleFrame);
            }
            else if (frameType == FrameType_ZOrderFrame)
            {
                auto zOrderFrame = frameFlatbuf->zOrderFrame();
                frame = loadZOrderFrameWithFlatBuffers(zOrderFrame);
            }
            else if (frameType == FrameType_RotationSkewFrame)
            {
                auto rotationSkewFrame = frameFlatbuf->rotationSkewFrame();
                frame = loadRotationSkewFrameWithFlatBuffers(rotationSkewFrame);
            }
            else if (frameType == FrameType_EventFrame)
            {
                auto eventFrame = frameFlatbuf->eventFrame();
                frame = loadEventFrameWithFlatBuffers(eventFrame);
            }
            else if (frameType == FrameType_AnchorFrame)
            {
                auto anchorPointFrame = frameFlatbuf->anchorPointFrame();
                frame = loadAnchorPointFrameWithFlatBuffers(anchorPointFrame);
            }
            else if (frameType == FrameType_PositionFrame)
            {
                auto potisionFrame = frameFlatbuf->positionFrame();
                frame = loadPositionFrameWithFlatBuffers(potisionFrame);
            }
            else if (frameType == FrameType_ScaleFrame)
            {
                auto scaleFrame = frameFlatbuf->scaleFrame();
                frame = loadScaleFrameWithFlatBuffers(scaleFrame);
            }
            else if (frameType == FrameType_ColorFrame)
            {
                auto colorFrame = frameFlatbuf->colorFrame();
                frame = loadColorFrameWithFlatBuffers(colorFrame);
            }
            else if (frameType == FrameType_TextureFrame)
            {
                auto textureFrame = frameFlatbuf->textureFrame();
                frame = loadTextureFrameWithFlatBuffers(textureFrame);
            }
            
            timeline->addFrame(frame);
        }
    }
    
    return timeline;
}