mapeditor / tiled

Flexible level editor
https://www.mapeditor.org/
Other
11.21k stars 1.76k forks source link

TMXMapReader - Wrong tileset depending on declaration order #2076

Closed Michael2109 closed 4 years ago

Michael2109 commented 5 years ago

I've been using the TMXMapReader to parse a .tmx file. I've noticed that any ids of 1 in the data is being set as the empty tileset instead of the outdoor tileset.

.tmx

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.1" orientation="orthogonal" renderorder="right-up" width="30" height="30" tilewidth="32" tileheight="32" infinite="0" nextlayerid="5" nextobjectid="131">
 <tileset firstgid="1" source="outdoor.tsx"/>
 <tileset firstgid="2" source="ammo.tsx"/>
 <tileset firstgid="3" source="healing.tsx"/>
 <tileset firstgid="4" source="decontamination.tsx"/>
 <tileset firstgid="5" source="generator.tsx"/>
 <tileset firstgid="6" source="research.tsx"/>
 <tileset firstgid="7" source="empty.tsx"/>
 <layer id="4" name="Tile Layer 1" width="30" height="30">
  <data encoding="csv">
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
</data>
 </layer>
</map>

Outdoor tileset

<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.2" tiledversion="1.2.1" name="outdoor" tilewidth="32" tileheight="32" tilecount="1" columns="1">
 <image source="../images/tiles/rooms/outdoor.png" width="32" height="32"/>
</tileset>

Empty tileset

<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.2" tiledversion="1.2.1" name="empty" tilewidth="32" tileheight="32" tilecount="1" columns="1">
 <image source="../images/tiles/rooms/empty.png" width="32" height="32"/>
</tileset>

Currently I can fix it by switching the order of the tileset declarations.

Fixed .tmx

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.1" orientation="orthogonal" renderorder="right-up" width="30" height="30" tilewidth="32" tileheight="32" infinite="0" nextlayerid="5" nextobjectid="131">
 <tileset firstgid="7" source="empty.tsx"/>
 <tileset firstgid="2" source="ammo.tsx"/>
 <tileset firstgid="3" source="healing.tsx"/>
 <tileset firstgid="4" source="decontamination.tsx"/>
 <tileset firstgid="5" source="generator.tsx"/>
 <tileset firstgid="6" source="research.tsx"/>
 <tileset firstgid="1" source="outdoor.tsx"/>
 <layer id="4" name="Tile Layer 1" width="30" height="30">
  <data encoding="csv">
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,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1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,5,5,5,5,5,6,6,6,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,5,5,5,5,5,6,6,6,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,5,5,5,5,5,6,6,6,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,6,6,6,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
</data>
 </layer>
</map>

What could be causing this?

bjorn commented 5 years ago

Hmm, I don't see how this can happen. Would it be possible to upload an archive with all the relevant files, to make the problem easier to reproduce?

bjorn commented 5 years ago

You do mean the TMXMapReader at https://github.com/bjorn/tiled/tree/master/util/java/libtiled-java/src/main/java/org/mapeditor/io, right?

Michael2109 commented 5 years ago

TMXMapReader in org.mapeditor.

My gradle:

// https://mvnrepository.com/artifact/org.mapeditor/libtiled
compile group: 'org.mapeditor', name: 'libtiled', version: '0.17'

Sorry this was a while before I had to change to the LibGDX tiled parser so I can't give any more code. To reproduce you should just need to create all of the 7 tilesets (like the examples above) and parse it. It should have the empty tileset instead of the outdoor tilesets.

bjorn commented 5 years ago

I think this bug was already fixed in change 14a9ffa9e0b5731cd968107cfa4810a742c529e9, but probably that fix isn't in the MVN repository yet.

@mikepthomas Could you help with pushing a new release of libtiled there? I'm sorry but I'm still clueless about how to get that updated. Ideally it would trigger from AppVeyor or Travis CI on release tags...

mikepthomas commented 5 years ago

Could you help with pushing a new release of libtiled there?

Sure I have pushed a copy of the latest master branch to Nexus SNAPSHOTS, you can get hold of it using the following in your Maven POM:

<repositories>
    <repository>
        <id>sonatype-oss</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.mapeditor</groupId>
        <artifactId>libtiled</artifactId>
        <version>1.0.2-SNAPSHOT</version>
        <type>jar</type>
    </dependency>
    ...
</dependencies>

or for gradle:

repositories {
    mavenCentral()
    maven {
      url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

dependencies {
    implementation 'org.mapeditor:libtiled:1.0.2-SNAPSHOT'
}

Once you're happy with the build let me know and Ill trigger the process of pushing it to Maven Central.

Ideally it would trigger from AppVeyor or Travis CI on release tags...

Yes this would be great, however to get approval to push to Central the assets need to be signed with a PGP key, at the moment I am using my personal one... ~I don't know if you are able to set up GPG on AppVeyor or Travis as you would need to store the private key secuely in some way.~ It looks like it is possible to do with Travis, the process is a bit involved, https://www.phillip-kruger.com/post/continuous_integration_to_maven_central/ I could take a look hopefully this weekend if I get some time. @bjorn, you may need to upload the key to travis as I do not have access unfortunately. Hope this helps :)

bjorn commented 5 years ago

@mikepthomas I tried to check the build, but the mvn clean install command if failing me for some reason. Do you know what may be causing this?

bjorn@thor:~/projects/tiled/util/java$ mvn clean install
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] Tiled
[INFO] libtiled
[INFO] tmxviewer
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building Tiled 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ tiled-parent ---
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ tiled-parent ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ tiled-parent ---
[INFO] Installing /home/bjorn/projects/tiled/util/java/pom.xml to /home/bjorn/.m2/repository/org/mapeditor/tiled-parent/1.0-SNAPSHOT/tiled-parent-1.0-SNAPSHOT.pom
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building libtiled 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ libtiled ---
[INFO] Deleting /home/bjorn/projects/tiled/util/java/libtiled-java/target
[INFO] 
[INFO] --- maven-jaxb2-plugin:0.13.2:generate (default) @ libtiled ---
[WARNING] The POM for org.glassfish.jaxb:jaxb-runtime:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.glassfish.jaxb:jaxb-core:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.glassfish.jaxb:txw2:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.glassfish.jaxb:jaxb-xjc:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.glassfish.jaxb:codemodel:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.sun.xml.bind.external:rngom:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.sun.istack:istack-commons-tools:jar:2.21 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Failed to build parent project for com.sun.xml.bind.mvn:jaxb-bundles:pom:2.2.11
[WARNING] Failed to build parent project for com.sun.xml.bind:jaxb-xjc:jar:2.2.11
[WARNING] Invalid POM for com.sun.xml.bind:jaxb-xjc:jar:2.2.11, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Failed to build parent project for com.sun.xml.bind.mvn:jaxb-bundles:pom:2.2.11
[WARNING] Failed to build parent project for com.sun.xml.bind:jaxb-core:jar:2.2.11
[WARNING] Invalid POM for com.sun.xml.bind:jaxb-core:jar:2.2.11, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] Up-to-date check for source resources [[file:/home/bjorn/projects/tiled/util/java/libtiled-java/src/main/resources/map.xsd, file:/home/bjorn/projects/tiled/util/java/libtiled-java/src/main/resources/bindings.xjb, file:/home/bjorn/projects/tiled/util/java/libtiled-java/pom.xml]] and target resources [[]].
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Tiled .............................................. SUCCESS [  0.474 s]
[INFO] libtiled ........................................... FAILURE [  1.142 s]
[INFO] tmxviewer .......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.749 s
[INFO] Finished at: 2019-03-12T10:42:25+01:00
[INFO] Final Memory: 14M/60M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.2:generate (default) on project libtiled: Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.2:generate failed: Prefix '' is already bound to '' -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :libtiled

And maybe some version info helps:

bjorn@thor:~/projects/tiled/util/java/libtiled-java$ mvn --version
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.2, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-46-generic", arch: "amd64", family: "unix"
mikepthomas commented 5 years ago

My guess is the Java version you are using... it should build fine under JDK 1.8, I have yet to try building using versions later than this as jaxb has been deprecated in version 9 https://www.jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond/ the version I used to build the snapshot in OSS is:

$ java -version                                                                                                                                      ✔
openjdk version "1.8.0_202"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_202-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.202-b08, mixed mode)
bjorn commented 5 years ago

My guess is the Java version you are using... it should build fine under JDK 1.8, I have yet to try building using versions later than this as jaxb has been deprecated in version 9

Ah, so that's issue #2048 then. How feasible do you think it is to drop JAXB? Is that a dependency you introduced?

Feel free to push this version to Maven Central in the meantime, since it's at least better than the version currently released there.

mikepthomas commented 5 years ago

It should be able to be added back in to later versions of Java from Maven using:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>

From what I believe it has only been deprecated in the JDK to slim it down as it was originally designed as a Java EE feature for XML based web services. Its currently being used to auto generate some Classes from the XML schema that was made.

mikepthomas commented 5 years ago

Latest version is now available in Maven Central https://search.maven.org/artifact/org.mapeditor/libtiled/1.0.2/jar

bjorn commented 5 years ago

@mikepthomas Thanks! Just out of curiosity, where does the version "1.0.2" come from?

@Michael2109 Can you try whether the bug you reported was fixed when using this version of libtiled?

mikepthomas commented 5 years ago

where does the version "1.0.2" come from?

When I have made changes, I open the Maps in src/test/resources with the latest version of Tiled and re-save them, I also update the xml schema in src/main/resources with any additions in http://doc.mapeditor.org/en/latest/reference/tmx-map-format so it should be able to read maps produced up to that version of Tiled (with some features not implemented). I'd like to update the library more but am struggling to find time atm. I have however, managed to get it building in Java 11, with a few warnings... expect to see a PR coming soon ;)

bjorn commented 4 years ago

Closing this since the bug is likely fixed and we're unlikely to still get a confirmation @Michael2109.