Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

json map opened on startup saves as tmx format #389

Closed
MHendricks opened this Issue · 5 comments

3 participants

@MHendricks

I have a tile map saved to a .json file open when I close tiled. When I re-open tiled and make a change, in this case layer opacity and hit save. When I look at the saved file it appears to be saved out as xml probably the tmx format. To get it to save as the json format I have to use save as and select the json file extension.

Mac build of tiled 0.9.0, Qt 4.8.3.

@stefanbeller

I could not reproduce it here with tagged v0.9.0 in Linux

  • Open exactly one file (tmx)
  • Save as... Select json file format and have extension .json set.
  • Close tiled
  • Check file format: It's actually json
  • Start tiled, map opens up automatically, change opacity.
  • Save (With CTRL + S shortcut)
  • Close tiled.
  • check file format again. It's still json here.
@MHendricks

Looks like its a mac only bug, I tested the current build on windows and that worked properly. I just compiled it on my mac and its still a issue, I havent taken the time to get familiar with the code yet, where would be a good place to look?

@bjorn
Owner

Here's the code that determines the file name of the plugin to write with:

https://github.com/bjorn/tiled/blob/master/src/tiled/mainwindow.cpp#L777

The actual saving is then done in MapDocument::save.

@MHendricks

I think I found the problem. Its the dynamic_cast in MainWindow::openFile. If you replace it with a qobject_cast it seems to fix it. I made this change and it fixed it, but I'm not sure if its the best way to handle it.

@@ -568,9 +568,11 @@ bool MainWindow::openFile(const QString &fileName,
     QString writerPluginFileName;
     PluginManager *pm = PluginManager::instance();
     if (mapReader) {
-        if (dynamic_cast<MapWriterInterface*>(mapReader)) {
-            if (const Plugin *plugin = pm->plugin(mapReader))
+        if (const Plugin *plugin = pm->plugin(mapReader)) {
+            const MapWriterInterface *writer = qobject_cast<MapWriterInterface*>(plugin->instance);
+            if (writer){
                 writerPluginFileName = plugin->fileName;
+            }
         }
     } else {
         mapReader = &tmxMapReader;    
@bjorn
Owner

@MHendricks Hmm, nice find! Indeed, dynamic_cast does not work reliably for libraries loaded at runtime. I guess we've just been lucky that this has been working on Linux and Windows.

Apart from changing the cast the rest of the changes are irrelevant, right? Maybe you want to contribute a minimal patch with your author info on it?

@bjorn bjorn closed this issue from a commit
MHendricks Fixed save in wrong format after opening a file using a plugin
On Mac, opening a file using a plugin was not setting the mapDocument's
writerPluginFileName. This means that it would default to the TMX
format.

Replaced dynamic_cast with qobject_cast.

Closes #389
438e5b5
@bjorn bjorn closed this in 438e5b5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.