예제 #1
0
Status SoundManager::loadSound(Layer* soundLayer, int frameNumber, QString strSoundFile)
{
    Q_ASSERT(soundLayer);
    if (soundLayer->type() != Layer::SOUND)
    {
        return Status::ERROR_INVALID_LAYER_TYPE;
    }

    if (frameNumber < 0)
    {
        return Status::ERROR_INVALID_FRAME_NUMBER;
    }

    if (!QFile::exists(strSoundFile))
    {
        return Status::FILE_NOT_FOUND;
    }

    KeyFrame* key = soundLayer->getKeyFrameAt(frameNumber);
    if (key == nullptr)
    {
        key = new SoundClip;
        soundLayer->addKeyFrame(frameNumber, key);
    }

    if (!key->fileName().isEmpty())
    {
        // file path should be empty.
        // we can only load a audio clip to an empty key! 
        return Status::FAIL;
    }

    QString strCopyFile = soundLayer->object()->copyFileToDataFolder(strSoundFile);
    Q_ASSERT(!strCopyFile.isEmpty());

    QString sOriginalName = QFileInfo(strSoundFile).fileName();

    SoundClip* soundClip = dynamic_cast<SoundClip*>(key);
    soundClip->init(strCopyFile);
    soundClip->setSoundClipName(sOriginalName);

    Status st = createMediaPlayer(soundClip);
    if (!st.ok())
    {
        delete soundClip;
        return st;
    }

    return Status::OK;
}
예제 #2
0
Status SoundManager::loadSound( Layer* soundLayer, int frameNumber, QString strSoundFile )
{
    Q_ASSERT( soundLayer );
    if ( soundLayer->type() != Layer::SOUND )
    {
        return Status::ERROR_INVALID_LAYER_TYPE;
    }

    if ( frameNumber < 0 )
    {
        return Status::ERROR_INVALID_FRAME_NUMBER;
    }

    if ( !QFile::exists( strSoundFile ) )
    {
        return Status::FILE_NOT_FOUND;
    }
    
    KeyFrame* key = soundLayer->getKeyFrameAt( frameNumber );
    if ( key == nullptr )
    {
        key = new SoundClip;
    }
    
    if ( !key->fileName().isEmpty() )
    {
        return Status::FAIL;
    }
    
    SoundClip* soundClip = dynamic_cast< SoundClip* >( key );
    soundClip->init( strSoundFile );
    
    Status st = mSoundPlayer->addSound( soundClip );

    if ( !st.ok() )
    {
        delete soundClip;
        return st;
    }
    
    bool bAddOK = soundLayer->addKeyFrame( frameNumber, soundClip );
    if ( !bAddOK )
    {
        delete soundClip;
        return Status::FAIL;
    }

    return Status::OK;
}
예제 #3
0
QJsonObject AnimationToJson::toJsonObject(const KeyFrame &keyFrame)
{
    QJsonObject object;
    object.insert("fileName", QFileInfo(keyFrame.fileName()).fileName());
    object.insert("rect", toJsonObject(keyFrame.rect()));
//    qDebug() << keyFrame.rect() << toJsonObject(keyFrame.rect());
    object.insert("offset", toJsonObject(keyFrame.offset()));

    QJsonObject customPropertiesObject;
    const auto customProperties = keyFrame.customProperties();
    for(auto it = customProperties.begin(); it != customProperties.end(); ++it) {
        customPropertiesObject.insert(it.key(), it.value());
    }
    object.insert("customProperties", customPropertiesObject);

    QJsonArray hitBoxes;
    for (HitBox *hitBox : keyFrame.hitBoxes()) {
        hitBoxes.append(toJsonObject(*hitBox));
    }
    object.insert("hitBoxes", hitBoxes);
    return object;
}