Exemple #1
0
void GD_API SendHttpRequest(const gd::String & host, const gd::String & uri, const gd::String & body,
    const gd::String & method, const gd::String & contentType, gd::Variable & responseVar)
{
    // Separate the host and the port number
    auto hostInfo = host.Split(U':');

    if(hostInfo.size() < 2)
        return; //Invalid address (there should be two elements: "http" and "//the.domain.com")

    // Create Http
    sf::Http http;
    http.setHost(hostInfo[0].ToUTF8() + ":" + hostInfo[1].ToUTF8(), hostInfo.size() > 2 ? hostInfo[2].To<unsigned short>() : 0);

    // Create request
    sf::Http::Request request;
    request.setMethod(method == "POST" ? sf::Http::Request::Post : sf::Http::Request::Get);
    request.setField("Content-Type", contentType.empty() ? "application/x-www-form-urlencoded" : contentType.ToUTF8());
    request.setUri(uri.ToUTF8());
    request.setBody(body.ToUTF8());

    // Send request & Get response
    sf::Http::Response response = http.sendRequest(request);

    if (response.getStatus() == sf::Http::Response::Ok)
    {
        responseVar.SetString(gd::String::FromUTF8(response.getBody()));
    }
    //else request failed.
}
void GD_EXTENSION_API CreateSFMLTexture( RuntimeScene & scene, const gd::String & imageName, unsigned int width, unsigned int height, const gd::String & colorStr )
{
    //Get or create the texture in memory
    std::shared_ptr<SFMLTextureWrapper> newTexture;
    if ( !scene.GetImageManager()->HasLoadedSFMLTexture(imageName) )
        newTexture = std::shared_ptr<SFMLTextureWrapper>(new SFMLTextureWrapper);
    else
        newTexture = scene.GetImageManager()->GetSFMLTexture(imageName);

    //Get the color
    sf::Color color;
    bool colorIsOk = false;
    std::vector < gd::String > colors = colorStr.Split(U';');
    if ( colors.size() == 3 )
    {
        colorIsOk = true;
        color = sf::Color(colors[0].To<int>(), colors[1].To<int>(), colors[2].To<int>());
    }

    //Create the SFML image and the SFML texture
    if ( width != 0 && height != 0 && colorIsOk )
        newTexture->image.create(width, height, color);

    newTexture->texture.loadFromImage(newTexture->image); //Do not forget to update the associated texture

    scene.GetImageManager()->SetSFMLTextureAsPermanentlyLoaded(imageName, newTexture); //Otherwise
}
Exemple #3
0
void GD_API DownloadFile( const gd::String & host, const gd::String & uri, const gd::String & outputfilename )
{
    // Separate the host and the port number
    auto hostInfo = host.Split(U':');

    if(hostInfo.size() < 2)
        return; //Invalid address (there should be two elements: "http" and "//the.domain.com")

    // Create Http
    sf::Http http;
    http.setHost(hostInfo[0].ToUTF8() + ":" + hostInfo[1].ToUTF8(), hostInfo.size() > 2 ? hostInfo[2].To<unsigned short>() : 0);

    // Create request
    sf::Http::Request Request;
    Request.setMethod(sf::Http::Request::Get);
    Request.setUri(uri.ToUTF8());

    // Send request & Get response
    sf::Http::Response datas = http.sendRequest(Request);

    ofstream ofile(outputfilename.ToLocale().c_str(), ios_base::binary);
    if ( ofile.is_open() )
    {
        ofile.write(datas.getBody().c_str(),datas.getBody().size());
        ofile.close();

        return;
    }

    cout << "Downloading file : Unable to open output file " << outputfilename;
    return;
}
void GD_API ChangeSceneBackground( RuntimeScene & scene, gd::String newColor )
{
    std::vector < gd::String > colors = newColor.Split(U';');
    if ( colors.size() > 2 ) scene.SetBackgroundColor( colors[0].To<int>(), colors[1].To<int>(), colors[2].To<int>() );

    return;
}
wxTreeItemId InstructionSelectorDialog::GetGroupItem(wxTreeCtrl * treeCtrl, wxTreeItemId parent, gd::String groupStr, bool insertIfNotExist)
{
    std::vector<gd::String> groups = groupStr.Split(U'/');

    for(std::size_t i = 0;i<groups.size();++i)
    {
        if ( groups[i].empty() ) continue;

        wxTreeItemIdValue cookie;
        wxTreeItemId groupItem = treeCtrl->GetFirstChild(parent, cookie);
        size_t latestGroupPos = 0;
        while ( groupItem.IsOk() && treeCtrl->GetItemText(groupItem) != groups[i].ToWxString() )
        {
            if ( treeCtrl->HasChildren(groupItem) ) latestGroupPos++;
            groupItem = treeCtrl->GetNextSibling(groupItem);
        }
        if ( !groupItem.IsOk() && insertIfNotExist)
            groupItem = treeCtrl->InsertItem(parent, latestGroupPos, groups[i], 0);
        else if( !groupItem.IsOk() && !insertIfNotExist)
        {
            return groupItem;
        }

        parent = groupItem;
    }

    return parent;
}
void CompilerMessagesParser::ParseOutput(gd::String rawOutput)
{
    parsedMessages.clear();
    std::vector<gd::String> output = rawOutput.Split(U'\n');

    for (unsigned int i = 0;i<output.size();++i)
    {
        CompilerMessage newMessage;
        std::vector<gd::String> columns = output[i].Split(U':');

        if (columns.size() >= 3)
        {
            newMessage.file = columns[0];
            newMessage.line = columns[1].To<int>();
            newMessage.column = columns[2].To<int>();
        }
        if (!columns.empty()) newMessage.message = columns.back();

        if ( output[i].find("error") < output[i].length() )
            newMessage.messageType = CompilerMessage::error;
        else
            newMessage.messageType = CompilerMessage::simple;

        parsedMessages.push_back(newMessage);
    }
}
Exemple #7
0
void RuntimeTextObject::SetColor(const gd::String& colorStr) {
  std::vector<gd::String> colors = colorStr.Split(U';');

  if (colors.size() < 3) return;  // La couleur est incorrecte

  SetColor(colors[0].To<int>(), colors[1].To<int>(), colors[2].To<int>());
}
Exemple #8
0
void RuntimeLightObject::SetGlobalColor(const gd::String & colorStr)
{
    vector < gd::String > colors = colorStr.Split(U';');

    if ( colors.size() < 3 ) return; //La couleur est incorrecte

    SetGlobalColor(sf::Color( colors[0].To<int>(),colors[1].To<int>(),colors[2].To<int>() ));
}
/**
 * Change the color of the outline
 */
void ShapePainterObjectBase::SetOutlineColor( const gd::String & color )
{
    std::vector < gd::String > colors = color.Split(U';');
    if ( colors.size() < 3 ) return;

    outlineColorR = colors[0].To<int>();
    outlineColorG = colors[1].To<int>();
    outlineColorB = colors[2].To<int>();
}
Exemple #10
0
void RuntimeSpriteObject::SetColor(const gd::String & colorStr)
{
    std::vector < gd::String > colors = colorStr.Split(U';');
    if ( colors.size() < 3 ) return; //Color is not valid

    SetColor(  colors[0].To<int>(),
               colors[1].To<int>(),
               colors[2].To<int>() );
}
void ParticleEmitterBase::SetParticleColor2(const gd::String& color) {
  std::vector<gd::String> colors = color.Split(U';');

  if (colors.size() < 3) return;  // Color is incorrect

  SetParticleRed2(colors[0].To<int>());
  SetParticleGreen2(colors[1].To<int>());
  SetParticleBlue2(colors[2].To<int>());
}
bool RuntimeShapePainterObject::ChangeProperty(std::size_t propertyNb, gd::String newValue)
{
    if ( propertyNb == 0 )
    {
        std::vector < gd::String > colors = newValue.Split(U';');
        if ( colors.size() < 3 ) return false; //Color is not valid

        SetFillColor(colors[0].To<int>(), colors[1].To<int>(), colors[2].To<int>());
    }
    else if ( propertyNb == 1 ) { SetFillOpacity(newValue.To<float>()); }
    else if ( propertyNb == 2 ) { SetOutlineSize(newValue.To<int>()); }
    else if ( propertyNb == 3 )
    {
        std::vector < gd::String > colors = newValue.Split(U';');
        if ( colors.size() < 3 ) return false; //Color is not valid

        SetOutlineColor(colors[0].To<int>(), colors[1].To<int>(), colors[2].To<int>());
    }
    else if ( propertyNb == 4 ) { SetOutlineOpacity(newValue.To<float>()); }

    return true;
}
Exemple #13
0
void RuntimeSpriteObject::MakeColorTransparent( const gd::String & colorStr )
{
    if ( needUpdateCurrentSprite ) UpdateCurrentSprite();

    ptrToCurrentSprite->MakeSpriteOwnsItsImage(); //We want to modify only the image of the object, not all objects which have the same image.
    std::shared_ptr<SFMLTextureWrapper> dest = ptrToCurrentSprite->GetSFMLTexture();

    std::vector < gd::String > colors = colorStr.Split(U';');

    if ( colors.size() < 3 ) return; //La couleur est incorrecte

    //Update texture and pixel perfect collision mask
    dest->image.createMaskFromColor(  sf::Color( colors[0].To<int>(), colors[1].To<int>(), colors[2].To<int>()));
    dest->texture.loadFromImage(dest->image);
}
Exemple #14
0
std::vector<sf::Vector2f> PhysicsBehavior::GetCoordsVectorFromString(const gd::String &str, char32_t coordsSep, char32_t composantSep)
{
    std::vector<sf::Vector2f> coordsVec;

    std::vector<gd::String> coordsDecomposed = str.Split(coordsSep);

    for(std::size_t a = 0; a < coordsDecomposed.size(); a++)
    {
        std::vector<gd::String> coordXY = coordsDecomposed.at(a).Split(composantSep);

        if(coordXY.size() != 2)
            continue;

        sf::Vector2f newCoord(coordXY.at(0).To<float>(), coordXY.at(1).To<float>());
        coordsVec.push_back(newCoord);
    }

    return coordsVec;
}
Exemple #15
0
bool AudioExtension::ChangeProperty(RuntimeScene & scene, std::size_t propertyNb, gd::String newValue)
{
    SoundManager & manager = scene.game->GetSoundManager();

    if ( propertyNb == 0 )
    {
        manager.SetGlobalVolume(newValue.To<float>());
        return true;
    }
    else if ( propertyNb < 1+manager.sounds.size()*3 )
    {
        std::size_t soundNb = ((propertyNb-1)-(propertyNb-1)%3)/3;
        if (soundNb >= manager.sounds.size()) return false;

        if ( propertyNb % 3 == 1)
        {
            return false;
        }
        else if ( propertyNb % 3 == 2)
        {
            std::vector<gd::String> values = newValue.Split(U'/');
            if ( values.size() < 2 ) return false;

            manager.sounds[soundNb]->SetVolume(values[0].To<float>(), manager.GetGlobalVolume());
            manager.sounds[soundNb]->SetPitch(values[1].To<float>());
            return true;
        }
        else
        {
            manager.sounds[soundNb]->SetPlayingOffset(newValue.To<float>());
            return true;
        }

    }
    else if ( propertyNb < 1+manager.sounds.size()*3+manager.musics.size()*3 )
    {
        std::size_t musicNb = ((propertyNb-1-manager.sounds.size()*3)-(propertyNb-1-manager.sounds.size()*3)%3)/3;
        if (musicNb >= manager.musics.size()) return false;

        if ( propertyNb % 3 == 1)
        {
            return false;
        }
        else if ( propertyNb % 3 == 2)
        {
            std::vector<gd::String> values = newValue.Split(U'/');
            if ( values.size() < 2 ) return false;

            manager.musics[musicNb]->SetVolume(values[0].To<float>(), manager.GetGlobalVolume());
            manager.musics[musicNb]->SetPitch(values[1].To<float>());
            return true;
        }
        else
        {
            manager.musics[musicNb]->SetPlayingOffset(newValue.To<float>());
            return true;
        }
    }


    return false;
}