Skip to content

Commit 63e4c9a

Browse files
Merge branch 'dev' into dev-zstd
2 parents 2ac1807 + fa6947e commit 63e4c9a

22 files changed

+495
-16
lines changed

.github/workflows/master-pr.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,38 @@ jobs:
99
steps:
1010
- name: Checkout PR branch
1111
uses: actions/checkout@v3
12-
12+
1313
- name: Get version from PR branch
1414
id: pr_version
1515
run: |
16-
PR_VERSION=$(grep '<Version>' **/*.csproj | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
16+
PR_VERSION=$(find . -name '*.csproj' -exec grep '<Version>' {} \; | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
1717
echo "PR_VERSION=$PR_VERSION" >> $GITHUB_ENV
1818
19-
- name: Checkout master branch
20-
run: |
21-
git fetch origin master
22-
git checkout origin/master
19+
- name: Checkout master branch to separate directory
20+
uses: actions/checkout@v3
21+
with:
22+
ref: master
23+
path: master_branch
2324

2425
- name: Get version from master branch
2526
id: master_version
2627
run: |
27-
MASTER_VERSION=$(grep '<Version>' **/*.csproj | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
28+
MASTER_VERSION=$(find master_branch -name '*.csproj' -exec grep '<Version>' {} \; | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
2829
echo "MASTER_VERSION=$MASTER_VERSION" >> $GITHUB_ENV
2930
31+
- name: Debug $GITHUB_ENV
32+
run: |
33+
echo "PR_VERSION: $PR_VERSION"
34+
echo "MASTER_VERSION: $MASTER_VERSION"
35+
3036
- name: Compare versions
3137
run: |
32-
if [ "$(printf '%s\n' "$PR_VERSION" "$MASTER_VERSION" | sort -V | head -n1)" = "$PR_VERSION" ] && [ "$PR_VERSION" != "$MASTER_VERSION" ]; then
38+
if [ -z "$PR_VERSION" ] || [ -z "$MASTER_VERSION" ]; then
39+
echo "One of the version variables is empty."
40+
exit 1
41+
fi
42+
43+
if [ "$(printf '%s\n' "$MASTER_VERSION" "$PR_VERSION" | sort -V | tail -n1)" != "$PR_VERSION" ] || [ "$PR_VERSION" = "$MASTER_VERSION" ]; then
3344
echo "Version in PR is not higher than master."
3445
exit 1
3546
else
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
namespace DotTiled.Tests;
2+
3+
public partial class TestData
4+
{
5+
public static Map MapDuplicateObjectIdBug(string ext) => new Map
6+
{
7+
Class = "",
8+
Orientation = MapOrientation.Orthogonal,
9+
Width = 64,
10+
Height = 64,
11+
TileWidth = 16,
12+
TileHeight = 16,
13+
Infinite = true,
14+
ParallaxOriginX = 0,
15+
ParallaxOriginY = 0,
16+
RenderOrder = RenderOrder.RightDown,
17+
CompressionLevel = -1,
18+
BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 },
19+
Version = "1.10",
20+
TiledVersion = "1.11.2",
21+
NextLayerID = 2,
22+
NextObjectID = 3,
23+
Tilesets = [
24+
new Tileset
25+
{
26+
FirstGID = 1,
27+
Source = ext == "tmx" ? "tiles.tsx" : "tiles.tsj",
28+
Version = "1.10",
29+
TiledVersion = "1.11.2",
30+
Name = "Tiles",
31+
TileWidth = 16,
32+
TileHeight = 16,
33+
TileCount = 4,
34+
Columns = 2,
35+
Grid = new Grid
36+
{
37+
Orientation = GridOrientation.Orthogonal,
38+
Width = 32,
39+
Height = 32
40+
},
41+
Image = new Image
42+
{
43+
Source = "tiles.png",
44+
Width = 32,
45+
Height = 32,
46+
Format = ImageFormat.Png
47+
}
48+
}
49+
],
50+
Layers = [
51+
new TileLayer
52+
{
53+
ID = 1,
54+
Name = "Tile Layer 1",
55+
Width = ext == "tmx" ? 64 : 16,
56+
Height = ext == "tmx" ? 64 : 16,
57+
Data = new Data
58+
{
59+
Encoding = DataEncoding.Csv,
60+
Chunks = new Optional<Chunk[]>([
61+
new Chunk
62+
{
63+
X = 0,
64+
Y = 0,
65+
Width = 16,
66+
Height = 16,
67+
GlobalTileIDs = [
68+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
69+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
70+
1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,
71+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
72+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
73+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
74+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
75+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
76+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
77+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
78+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
79+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
80+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
81+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
82+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
83+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
84+
],
85+
FlippingFlags = GetAllNoneFlippingFlags(16 * 16)
86+
}
87+
])
88+
}
89+
},
90+
new ObjectLayer
91+
{
92+
ID = 3,
93+
Name = "Object Layer 1",
94+
Objects = [
95+
new TileObject
96+
{
97+
ID = 1,
98+
Template = ext == "tmx" ? "template.tx" : "template.tj",
99+
X = 80,
100+
Y = 144,
101+
102+
GID = 4,
103+
Width = 16,
104+
Height = 16,
105+
},
106+
new TileObject
107+
{
108+
ID = 2,
109+
Template = ext == "tmx" ? "template.tx" : "template.tj",
110+
X = 48,
111+
Y = 144,
112+
113+
GID = 4,
114+
Width = 16,
115+
Height = 16,
116+
}
117+
]
118+
}
119+
]
120+
};
121+
122+
private static FlippingFlags[] GetAllNoneFlippingFlags(int count)
123+
{
124+
var flippingFlags = new FlippingFlags[count];
125+
for (int i = 0; i < count; i++)
126+
{
127+
flippingFlags[i] = FlippingFlags.None;
128+
}
129+
return flippingFlags;
130+
}
131+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{ "compressionlevel":-1,
2+
"height":64,
3+
"infinite":true,
4+
"layers":[
5+
{
6+
"chunks":[
7+
{
8+
"data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
9+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
10+
1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
11+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
12+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
13+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
14+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
15+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
16+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
17+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
18+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
19+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
20+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
21+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
23+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
24+
"height":16,
25+
"width":16,
26+
"x":0,
27+
"y":0
28+
}],
29+
"height":16,
30+
"id":1,
31+
"name":"Tile Layer 1",
32+
"opacity":1,
33+
"startx":0,
34+
"starty":0,
35+
"type":"tilelayer",
36+
"visible":true,
37+
"width":16,
38+
"x":0,
39+
"y":0
40+
},
41+
{
42+
"draworder":"topdown",
43+
"id":3,
44+
"name":"Object Layer 1",
45+
"objects":[
46+
{
47+
"id":1,
48+
"template":"template.tj",
49+
"x":80,
50+
"y":144
51+
},
52+
{
53+
"id":2,
54+
"template":"template.tj",
55+
"x":48,
56+
"y":144
57+
}],
58+
"opacity":1,
59+
"type":"objectgroup",
60+
"visible":true,
61+
"x":0,
62+
"y":0
63+
}],
64+
"nextlayerid":2,
65+
"nextobjectid":3,
66+
"orientation":"orthogonal",
67+
"renderorder":"right-down",
68+
"tiledversion":"1.11.2",
69+
"tileheight":16,
70+
"tilesets":[
71+
{
72+
"firstgid":1,
73+
"source":"tiles.tsj"
74+
}],
75+
"tilewidth":16,
76+
"type":"map",
77+
"version":"1.10",
78+
"width":64
79+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="16" tileheight="16" infinite="1" nextlayerid="2" nextobjectid="3">
3+
<tileset firstgid="1" source="tiles.tsx"/>
4+
<layer id="1" name="Tile Layer 1" width="64" height="64">
5+
<data encoding="csv">
6+
<chunk x="0" y="0" width="16" height="16">
7+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
8+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
9+
1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,
10+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
11+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
12+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
13+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
14+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
15+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
16+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
17+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
18+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
19+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
20+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
21+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
22+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
23+
</chunk>
24+
</data>
25+
</layer>
26+
<objectgroup id="3" name="Object Layer 1">
27+
<object id="1" template="template.tx" x="80" y="144"/>
28+
<object id="2" template="template.tx" x="48" y="144"/>
29+
</objectgroup>
30+
</map>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ "object":
2+
{
3+
"gid":4,
4+
"height":16,
5+
"id":2,
6+
"name":"",
7+
"rotation":0,
8+
"type":"",
9+
"visible":true,
10+
"width":16
11+
},
12+
"tileset":
13+
{
14+
"firstgid":1,
15+
"source":"tiles.tsj"
16+
},
17+
"type":"template"
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<template>
3+
<tileset firstgid="1" source="tiles.tsx"/>
4+
<object gid="4" width="16" height="16">
5+
</object>
6+
</template>
156 Bytes
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ "columns":2,
2+
"grid":
3+
{
4+
"height":32,
5+
"orientation":"orthogonal",
6+
"width":32
7+
},
8+
"image":"tiles.png",
9+
"imageheight":32,
10+
"imagewidth":32,
11+
"margin":0,
12+
"name":"Tiles",
13+
"spacing":0,
14+
"tilecount":4,
15+
"tiledversion":"1.11.2",
16+
"tileheight":16,
17+
"tilewidth":16,
18+
"type":"tileset",
19+
"version":"1.10"
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<tileset version="1.10" tiledversion="1.11.2" name="Tiles" tilewidth="16" tileheight="16" tilecount="4" columns="2">
3+
<grid orientation="orthogonal" width="32" height="32"/>
4+
<image source="tiles.png" width="32" height="32"/>
5+
</tileset>

src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,39 @@ public void LoadMap_MapHasClassAndLoaderHasCustomTypeWithSameName_ReturnsMapWith
315315
// Assert
316316
DotTiledAssert.AssertProperties(customClassDefinition.Members, result.Properties);
317317
}
318+
319+
public static IEnumerable<object[]> Maps => TestData.MapTests;
320+
321+
[Theory]
322+
[MemberData(nameof(Maps))]
323+
public void LoadMap_ValidFilesExternalTilesetsAndTemplatesWithCache_ReturnsMapThatEqualsExpected(
324+
string testDataFile,
325+
Func<string, Map> expectedMap,
326+
IReadOnlyCollection<ICustomTypeDefinition> customTypeDefinitions)
327+
{
328+
// Arrange
329+
string[] fileFormats = [".tmx", ".tmj"];
330+
331+
foreach (var fileFormat in fileFormats)
332+
{
333+
var testDataFileWithFormat = testDataFile + fileFormat;
334+
var resourceReader = Substitute.For<IResourceReader>();
335+
resourceReader.Read(Arg.Any<string>()).Returns(callInfo =>
336+
{
337+
var filePath = callInfo.Arg<string>();
338+
return TestData.GetRawStringFor(filePath);
339+
});
340+
341+
var loader = Loader.DefaultWith(
342+
resourceReader: resourceReader,
343+
customTypeDefinitions: customTypeDefinitions);
344+
345+
// Act
346+
var map = loader.LoadMap(testDataFileWithFormat);
347+
348+
// Assert
349+
Assert.NotNull(map);
350+
DotTiledAssert.AssertMap(expectedMap(fileFormat[1..]), map);
351+
}
352+
}
318353
}

0 commit comments

Comments
 (0)