Пример #1
0
void XmlMapHandler::Save(std::ostream& file, const Map& map)
{
    wxXmlNode* root = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, "Map");

    const Tileset& tileset = map.GetTileset();
    const std::vector<AnimatedTile>& animated_tiles = tileset.GetAnimatedTiles();

    if (map.HasCollisionLayer())
        WriteCollision(root, map);
    for (const auto& tile : animated_tiles)
        WriteAnimation(root, map, tile);
    for (const auto& background : map.GetBackgrounds())
        WriteBackground(root, map, background);
    for (const auto& layer : map.GetLayers())
        WriteLayer(root, map, layer);
    WriteProperties(root, map);

    wxXmlDocument* doc = new wxXmlDocument();
    doc->SetRoot(root);

    wxOutputStream* fos = new wxFOutputStream(file);
    if (!doc->Save(*fos))
        throw "Failed to save XML file";
    delete fos;
}
Пример #2
0
void XmlMapHandler::WriteProperties(wxXmlNode* root, const Map& map)
{
    VerboseLog("Writing Properties");
    wxXmlNode* properties = new wxXmlNode(root, wxXML_ELEMENT_NODE, "Properties");
    const auto& tileset = map.GetTileset();
    uint32_t tile_width, tile_height;
    tileset.GetTileDimensions(tile_width, tile_height);

    wxXmlNode* tiledimensions = new wxXmlNode(properties, wxXML_ELEMENT_NODE, "TileDimensions");
    new wxXmlNode(tiledimensions, wxXML_TEXT_NODE, "",
                  wxString::Format("%i, %i", tile_width, tile_height));

    wxXmlNode* filename = new wxXmlNode(properties, wxXML_ELEMENT_NODE, "Tileset");
    new wxXmlNode(filename, wxXML_TEXT_NODE, "", tileset.GetFilename());

    wxXmlNode* name = new wxXmlNode(properties, wxXML_ELEMENT_NODE, "Name");
    new wxXmlNode(name, wxXML_TEXT_NODE, "", map.GetName());
    VerboseLog("Done Writing Properties");
}
Пример #3
0
/** MapToImage
  *
  * Converts a map into an ImageMagick Image
  */
int HandlerUtils::MapToImage(const Map& map, Magick::Image& image)
{
    std::vector<Magick::Image> tiles;

    if (HandlerUtils::GetTiles(map, tiles))
        return -1;

    Magick::Color color = Magick::ColorRGB(0, 0, 0);
    color.alpha(0);

    const Tileset& tileset = map.GetTileset();
    uint32_t tile_width, tile_height;
    tileset.GetTileDimensions(tile_width, tile_height);

    int width = map.GetWidth() * tile_width;
    int height = map.GetHeight() * tile_height;

    image.matte(true);
    image.resize(Magick::Geometry(width, height));
    image.backgroundColor(color);
    image.erase();

    try
    {
        for (const auto& layer : map.GetLayers())
        {
            if (HandlerUtils::LayerToImage(map, layer, tiles, image))
                return -1;
        }
    }
    catch (Magick::Exception& error_)
    {
        return -1;
    }

    return 0;
}