Example #1
0
bool MapDocument::save(const QString &fileName, QString *error)
{
    MapFormat *mapFormat = mWriterFormat;

    TmxMapFormat tmxMapFormat;
    if (!mapFormat)
        mapFormat = &tmxMapFormat;

    if (!mapFormat->write(map(), fileName)) {
        if (error)
            *error = mapFormat->errorString();
        return false;
    }

    undoStack()->setClean();
    setFileName(fileName);
    mLastSaved = QFileInfo(fileName).lastModified();

    // Mark TilesetDocuments for embedded tilesets as saved
    auto documentManager = DocumentManager::instance();
    for (const SharedTileset &tileset : mMap->tilesets()) {
        if (TilesetDocument *tilesetDocument = documentManager->findTilesetDocument(tileset))
            if (tilesetDocument->isEmbedded())
                tilesetDocument->setClean();
    }

    emit saved();
    return true;
}
Example #2
0
static bool MapResource_loadFile (const MapFormat& format, scene::Node& root, const std::string& filename)
{
    TextFileInputStream file(filename);
    if (!file.failed()) {
        format.readGraph(root, file, *g_entityCreator);
        return true;
    } else {
        globalErrorStream() << "ERROR: Could not load file: " << filename << "\n";
        return false;
    }
}
Example #3
0
/**
 * @sa Map_Write
 */
bool MapResource_saveFile (const MapFormat& format, scene::Node& root, GraphTraversalFunc traverse,
                           const std::string& filename)
{
    TextFileOutputStream file(filename);
    if (!file.failed()) {
        ScopeDisableScreenUpdates disableScreenUpdates(os::getFilenameFromPath(filename), _("Saving Map"));
        format.writeGraph(root, traverse, file);
        return true;
    }

    globalErrorStream() << "ERROR: open file for writing failed: " << filename << "\n";
    return false;
}
Example #4
0
bool MapResource_saveFile(const MapFormat& format, scene::Node& root, GraphTraversalFunc traverse, const char* filename)
{
  //ASSERT_MESSAGE(path_is_absolute(filename), "MapResource_saveFile: path is not absolute: " << makeQuoted(filename));
  globalOutputStream() << "Open file " << filename << " for write...";
  TextFileOutputStream file(filename);
  if(!file.failed())
  {
    globalOutputStream() << "success\n";
    ScopeDisableScreenUpdates disableScreenUpdates(path_get_filename_start(filename), "Saving Map");
    format.writeGraph(root, traverse, file);
    return true;
  }

  globalErrorStream() << "failure\n";
  return false;
}
Example #5
0
bool MapResource_loadFile(const MapFormat& format, scene::Node& root, const char* filename)
{
  globalOutputStream() << "Open file " << filename << " for read...";
  TextFileInputStream file(filename);
  if(!file.failed())
  {
    globalOutputStream() << "success\n";
    ScopeDisableScreenUpdates disableScreenUpdates(path_get_filename_start(filename), "Loading Map");
    ASSERT_NOTNULL(g_entityCreator);
    format.readGraph(root, file, *g_entityCreator);
    return true;
  }
  else
  {
    globalErrorStream() << "failure\n";
    return false;
  }
}