Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2933 Set the firstgid property on Tilesets #2934

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ private void buildMap(Document doc) throws Exception {
for (int i = 0; (item = l.item(i)) != null; i++) {
int firstGid = getAttribute(item, "firstgid", 1);
TileSet tileset = unmarshalTileset(item);
tileset.setFirstgid(firstGid);
tilesetPerFirstGid.put(firstGid, tileset);
map.addTileset(tileset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Expand All @@ -34,8 +34,10 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import static org.junit.Assert.*;

import org.junit.Test;

import org.mapeditor.core.Map;
Expand Down Expand Up @@ -80,6 +82,15 @@ public void testReadingSewersMapJar() throws Exception {
checkSewersMap(map);
}

@Test
public void testMultiTileset() throws Exception {
final Map map = new TMXMapReader().readMap(getJarURL("multi-tileset/desert.tmx"));
final List<TileSet> tilesets = map.getTileSets();
assertEquals(2, tilesets.size());
assertEquals(Integer.valueOf(1), tilesets.get(0).getFirstgid());
assertEquals(Integer.valueOf(49), tilesets.get(1).getFirstgid());
}

private void checkSewersMap(final Map map) {
assertEquals(Orientation.ORTHOGONAL, map.getOrientation());
assertEquals(50, map.getWidth());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.2" orientation="orthogonal" renderorder="right-down" width="40" height="40" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" source="desert.tsx"/>
<tileset firstgid="49" source="sewer_tileset.tsx"/>
<layer id="1" name="Ground" width="40" height="40">
<data encoding="base64" compression="zlib">
eJztmNkOgjAQRas8uCWuibhERXHf4NH//zKHWIKZVGgrHUfjw4k0KenxzggT50KIuUPaQAfoOj7HhqvCb8HA61vyS7IaAj4wYuCjogJUAQ95uzhrDEwMmAINoAm0CLJYAisDQod++xy/NXAENh/0y8sv1MyTwm/L0C9GXtjvLB79fyH2wz2H10V54b4sw0/1O9ij/NLrIj+ca1n57dA69THNz3V9sSfmIOuny6kEv5qkLrJ3UR6e5r6U2Zt+HZHNF+l3zaOluU91n42fL7L5ogf0Cxho7lPd57L3qAmEes7h5BkQ+tjMZhReV/mp8+x8fv+EJZ2vi45f4hTLvZR+EUM/3Nfc/Gzq+zxfUPlFBn44S275qWrN2Y8yP5vZjNLvVwgYOHwLOCtu/w3+a/yHC7cXfNqryO8OVde5Bw==
</data>
</layer>
</map>
106 changes: 106 additions & 0 deletions util/java/libtiled-java/src/test/resources/multi-tileset/desert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.2" tiledversion="1.2.3" name="Desert" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="48" columns="8">
<image source="tmw_desert_spacing.png" width="265" height="199"/>
<terraintypes>
<terrain name="Desert" tile="29"/>
<terrain name="Brick" tile="9"/>
<terrain name="Cobblestone" tile="33"/>
<terrain name="Dirt" tile="14"/>
</terraintypes>
<tile id="0" terrain="0,0,0,1"/>
<tile id="1" terrain="0,0,1,1"/>
<tile id="2" terrain="0,0,1,0"/>
<tile id="3" terrain="3,3,3,0"/>
<tile id="4" terrain="3,3,0,3"/>
<tile id="5" terrain="0,0,0,3"/>
<tile id="6" terrain="0,0,3,3"/>
<tile id="7" terrain="0,0,3,0"/>
<tile id="8" terrain="0,1,0,1"/>
<tile id="9" terrain="1,1,1,1"/>
<tile id="10" terrain="1,0,1,0"/>
<tile id="11" terrain="3,0,3,3"/>
<tile id="12" terrain="0,3,3,3"/>
<tile id="13" terrain="0,3,0,3"/>
<tile id="14" terrain="3,3,3,3"/>
<tile id="15" terrain="3,0,3,0"/>
<tile id="16" terrain="0,1,0,0"/>
<tile id="17" terrain="1,1,0,0"/>
<tile id="18" terrain="1,0,0,0"/>
<tile id="19" terrain="1,1,1,0"/>
<tile id="20" terrain="1,1,0,1"/>
<tile id="21" terrain="0,3,0,0"/>
<tile id="22" terrain="3,3,0,0"/>
<tile id="23" terrain="3,0,0,0"/>
<tile id="24" terrain="0,0,0,2"/>
<tile id="25" terrain="0,0,2,2"/>
<tile id="26" terrain="0,0,2,0"/>
<tile id="27" terrain="1,0,1,1"/>
<tile id="28" terrain="0,1,1,1"/>
<tile id="29" terrain="0,0,0,0"/>
<tile id="30" terrain="0,0,0,0" probability="0.01"/>
<tile id="31" terrain="0,0,0,0" probability="0.01"/>
<tile id="32" terrain="0,2,0,2"/>
<tile id="33" terrain="2,2,2,2"/>
<tile id="34" terrain="2,0,2,0"/>
<tile id="35" terrain="2,2,2,0"/>
<tile id="36" terrain="2,2,0,2"/>
<tile id="37" terrain="0,0,0,0" probability="0.01"/>
<tile id="38" terrain="0,0,0,0" probability="0.01"/>
<tile id="39" terrain="0,0,0,0" probability="0.01"/>
<tile id="40" terrain="0,2,0,0"/>
<tile id="41" terrain="2,2,0,0"/>
<tile id="42" terrain="2,0,0,0"/>
<tile id="43" terrain="2,0,2,2"/>
<tile id="44" terrain="0,2,2,2"/>
<tile id="45" terrain="0,0,0,0" probability="0"/>
<tile id="46" terrain="0,0,0,0" probability="0.01"/>
<tile id="47" terrain="0,0,0,0" probability="0.01"/>
<wangsets>
<wangset name="Desert" tile="5">
<wangcornercolor name="Brick" color="#c17d11" tile="9" probability="1"/>
<wangcornercolor name="Cobblestone" color="#8ae234" tile="33" probability="1"/>
<wangcornercolor name="Desert" color="#c4a000" tile="29" probability="1"/>
<wangcornercolor name="Dirt" color="#ff7700" tile="14" probability="1"/>
<wangtile tileid="0" wangid="0x30301030"/>
<wangtile tileid="1" wangid="0x30101030"/>
<wangtile tileid="2" wangid="0x30103030"/>
<wangtile tileid="3" wangid="0x40403040"/>
<wangtile tileid="4" wangid="0x40304040"/>
<wangtile tileid="5" wangid="0x30304030"/>
<wangtile tileid="6" wangid="0x30404030"/>
<wangtile tileid="7" wangid="0x30403030"/>
<wangtile tileid="8" wangid="0x30301010"/>
<wangtile tileid="9" wangid="0x10101010"/>
<wangtile tileid="10" wangid="0x10103030"/>
<wangtile tileid="11" wangid="0x40404030"/>
<wangtile tileid="12" wangid="0x30404040"/>
<wangtile tileid="13" wangid="0x30304040"/>
<wangtile tileid="14" wangid="0x40404040"/>
<wangtile tileid="15" wangid="0x40403030"/>
<wangtile tileid="16" wangid="0x30303010"/>
<wangtile tileid="17" wangid="0x10303010"/>
<wangtile tileid="18" wangid="0x10303030"/>
<wangtile tileid="19" wangid="0x10103010"/>
<wangtile tileid="20" wangid="0x10301010"/>
<wangtile tileid="21" wangid="0x30303040"/>
<wangtile tileid="22" wangid="0x40303040"/>
<wangtile tileid="23" wangid="0x40303030"/>
<wangtile tileid="24" wangid="0x30302030"/>
<wangtile tileid="25" wangid="0x30202030"/>
<wangtile tileid="26" wangid="0x30203030"/>
<wangtile tileid="27" wangid="0x10101030"/>
<wangtile tileid="28" wangid="0x30101010"/>
<wangtile tileid="29" wangid="0x30303030"/>
<wangtile tileid="32" wangid="0x30302020"/>
<wangtile tileid="33" wangid="0x20202020"/>
<wangtile tileid="34" wangid="0x20203030"/>
<wangtile tileid="35" wangid="0x20203020"/>
<wangtile tileid="36" wangid="0x20302020"/>
<wangtile tileid="40" wangid="0x30303020"/>
<wangtile tileid="41" wangid="0x20303020"/>
<wangtile tileid="42" wangid="0x20303030"/>
<wangtile tileid="43" wangid="0x20202030"/>
<wangtile tileid="44" wangid="0x30202020"/>
</wangset>
</wangsets>
</tileset>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.4" tiledversion="1.4.2" name="sewer_tileset" tilewidth="32" tileheight="32" tilecount="36" columns="6">
<image source="sewer_tileset.png" width="192" height="217"/>
</tileset>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.