Ejemplo n.º 1
0
void SaveSpritesDirection(const vector < Sprite > & sprites, gd::SerializerElement & element)
{
    element.ConsiderAsArrayOf("sprite");
    for (unsigned int i = 0;i<sprites.size();++i)
    {
        gd::SerializerElement & spriteElement = element.AddChild("sprite");

        spriteElement.SetAttribute("image", sprites[i].GetImageName());
        SavePointsSprites(sprites[i].GetAllNonDefaultPoints(), spriteElement.AddChild("points"));

        SavePoint(sprites[i].GetOrigin(), spriteElement.AddChild("originPoint"));
        SavePoint(sprites[i].GetCenter(), spriteElement.AddChild("centerPoint"));
        spriteElement.GetChild("centerPoint").SetAttribute("automatic", sprites[i].IsDefaultCenterPoint());

        spriteElement.SetAttribute("hasCustomCollisionMask", !sprites[i].IsCollisionMaskAutomatic());

        gd::SerializerElement & collisionMaskElement = spriteElement.AddChild("customCollisionMask");
        collisionMaskElement.ConsiderAsArrayOf("polygon");
        std::vector<Polygon2d> polygons = sprites[i].GetCollisionMask();
        for (unsigned int j = 0;j<polygons.size();++j)
        {
            gd::SerializerElement & polygonElement = collisionMaskElement.AddChild("polygon");
            polygonElement.ConsiderAsArrayOf("vertice");
            for (unsigned int k = 0;k<polygons[j].vertices.size();++k)
            {
                polygonElement.AddChild("vertice")
                    .SetAttribute("x", polygons[j].vertices[k].x)
                    .SetAttribute("y", polygons[j].vertices[k].y);
            }
        }
    }
}
Ejemplo n.º 2
0
void PathBehavior::SerializePathsTo(gd::SerializerElement & element) const
{
    element.ConsiderAsArrayOf("path");
    for(std::map<gd::String, std::vector<sf::Vector2f> >::const_iterator it = localePaths.begin(); it != localePaths.end(); it++)
    {
        gd::SerializerElement & pathElement = element.AddChild("path");

        pathElement.SetAttribute("name", it->first);
        pathElement.SetAttribute("coords", GetStringFromCoordsVector(it->second, '/', ';'));
    }
}
Ejemplo n.º 3
0
void OpenPointsSprites(vector < Point > & points, const gd::SerializerElement & element)
{
    element.ConsiderAsArrayOf("point", "Point");
    for (unsigned int i = 0; i < element.GetChildrenCount(); ++i)
    {
        Point point("");
        OpenPoint(point, element.GetChild(i));

        points.push_back(point);
    }
}
Ejemplo n.º 4
0
void PathBehavior::UnserializePathsFrom(const gd::SerializerElement & element)
{
    localePaths.clear();

    element.ConsiderAsArrayOf("path", "Path");
    for(std::size_t i = 0;i<element.GetChildrenCount();++i)
    {
        const gd::SerializerElement & pathElement = element.GetChild(i);
        localePaths[pathElement.GetStringAttribute("name")] = GetCoordsVectorFromString(pathElement.GetStringAttribute("coords"), '/', ';');
    }

    if(localePaths.empty())
        localePaths["Object main path"] = std::vector<sf::Vector2f>(1, sf::Vector2f(0,0));
}
Ejemplo n.º 5
0
void SavePointsSprites(const vector < Point > & points, gd::SerializerElement & element)
{
    element.ConsiderAsArrayOf("point");
    for (unsigned int i = 0;i<points.size();++i)
        SavePoint(points[i], element.AddChild("point"));
}