Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
1.9 compability mode and restored indentation to 4 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nolemretaW committed Nov 10, 2023
1 parent f3173f3 commit 27de0be
Show file tree
Hide file tree
Showing 15 changed files with 1,899 additions and 1,815 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ root = true
#### Core EditorConfig Options ####

# Indentation and spacing
indent_size = 2
indent_size = 4
indent_style = space
tab_width = 2
tab_width = 4

# New line preferences
end_of_line = crlf
Expand Down
56 changes: 28 additions & 28 deletions TiledCSPlus.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@

class Program
{
public static void Main()
{
//load a tilemap
TiledMap TiledMap = new("assets/tilemap.tmx");

//load a tileset by loading all used tilesets from a directory
Dictionary<int, TiledTileset> Tilesets = TiledMap.GetTiledTilesets("assets/");
//you can load them manually of course, like this
/* foreach (TiledMapTileset tiledMapTileset in TiledMap.Tilesets)
public static void Main()
{
if tileset is not embedded into tilemap
if (!tiledMapTileset.IsTilesetEmbedded)
//load a tilemap
TiledMap TiledMap = new("assets/tilemap.tmx");

//load a tileset by loading all used tilesets from a directory
Dictionary<int, TiledTileset> Tilesets = TiledMap.GetTiledTilesets("assets/");
//you can load them manually of course, like this
/* foreach (TiledMapTileset tiledMapTileset in TiledMap.Tilesets)
{
load a tileset file using tiledMapTileset.Source as a filename...
...using new TiledTileset()
TiledTileset tiledTileset = new TiledTileset(tiledMapTileset.Source);
..or other method that works for you, into a MemoryStream
MemoryStream ms = new MemoryStream(<loaded tileset file>); //file has to be loaded into a byte array
TiledTileset tiledTileset = new TiledTileset(ms);
if tileset is not embedded into tilemap
if (!tiledMapTileset.IsTilesetEmbedded)
{
load a tileset file using tiledMapTileset.Source as a filename...
...using new TiledTileset()
TiledTileset tiledTileset = new TiledTileset(tiledMapTileset.Source);
..or other method that works for you, into a MemoryStream
MemoryStream ms = new MemoryStream(<loaded tileset file>); //file has to be loaded into a byte array
TiledTileset tiledTileset = new TiledTileset(ms);
//then, add into loaded tilesets as usual
Tilesets.Add(tiledMapTileset.FirstGid, tiledTileset);
}
} */
//then, add into loaded tilesets as usual
Tilesets.Add(tiledMapTileset.FirstGid, tiledTileset);
}
} */

//get map tileset which some tile belongs to
TiledMapTileset tileMapTileset = TiledMap.GetTiledMapTileset(TiledMap.Layers[0].Data[0]);
//now that you have tileset laded into Tilesets dictionary, you can get the tileset by
TiledTileset tileTileset = Tilesets[tileMapTileset.FirstGid];
//and now, get the rect for tile's position in the tileset image
_ = TiledMap.GetSourceRect(tileMapTileset, tileTileset, TiledMap.Layers[0].Data[0]);
}
//get map tileset which some tile belongs to
TiledMapTileset tileMapTileset = TiledMap.GetTiledMapTileset(TiledMap.Layers[0].Data[0]);
//now that you have tileset laded into Tilesets dictionary, you can get the tileset by
TiledTileset tileTileset = Tilesets[tileMapTileset.FirstGid];
//and now, get the rect for tile's position in the tileset image
_ = TiledMap.GetSourceRect(tileMapTileset, tileTileset, TiledMap.Layers[0].Data[0]);
}
}
75 changes: 39 additions & 36 deletions TiledCSPlus.Test/TiledCSPlus.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
<None Update="assets\tilemap.tmx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\tileset.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\tileset.tsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TiledCSPlus\TiledCSPlus.csproj" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
<None Update="assets\tileset.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\tileset.tsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\tilemap1.10.tmx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\tilemap1.9.tmx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TiledCSPlus\TiledCSPlus.csproj" />
</ItemGroup>

</Project>
86 changes: 49 additions & 37 deletions TiledCSPlus.Test/TiledMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,58 @@ namespace TiledCSPlus.Test;

public class TiledMapTest
{
private TiledMap? TiledMap;
private Dictionary<int, TiledTileset>? Tilesets;
[SetUp]
public void Setup()
{
TiledMap = new TiledMap("assets/tilemap.tmx");
Tilesets = TiledMap.GetTiledTilesets("assets/");
}
private TiledMap? TiledMap;
private TiledMap? TiledMap19;
private Dictionary<int, TiledTileset>? Tilesets;

[Test]
public void MapMetadata()
{
TiledMap?.TiledVersion.ShouldBe("1.10.2");
TiledMap?.Width.ShouldBe(10);
TiledMap?.Height.ShouldBe(10);
TiledMap?.TileHeight.ShouldBe(16);
TiledMap?.TileWidth.ShouldBe(16);
TiledMap?.Orientation.ShouldBe("orthogonal");
TiledMap?.BackgroundColor.ShouldBe(new Color(1, 2, 3, 4));
}
[SetUp]
public void Setup()
{
TiledMap = new TiledMap("assets/tilemap1.10.tmx");
TiledMap19 = new("assets/tilemap1.9.tmx");
Tilesets = TiledMap.GetTiledTilesets("assets/");
}

[Test]
public void Tileset()
{
TiledMap?.Tilesets[0].FirstGid.ShouldBe(1);
TiledMap?.Tilesets[0].Source.ShouldBe("tileset.tsx");
TiledMap?.Tilesets[0].IsTilesetEmbedded.ShouldBe(false);
TiledMap?.Tilesets[1].FirstGid.ShouldBe(2);
TiledMap?.Tilesets[1].Source.ShouldBe(null);
TiledMap?.Tilesets[1].IsTilesetEmbedded.ShouldBe(true);
[Test]
public void MapMetadata()
{
TiledMap?.TiledVersion.ShouldBe("1.10.2");
TiledMap?.MapVersion.ShouldBe("1.10");
TiledMap?.Width.ShouldBe(10);
TiledMap?.Height.ShouldBe(10);
TiledMap?.TileHeight.ShouldBe(16);
TiledMap?.TileWidth.ShouldBe(16);
TiledMap?.Orientation.ShouldBe("orthogonal");
TiledMap?.BackgroundColor.ShouldBe(new Color(1, 2, 3, 4));
}

Tilesets?[1].Image.Source.ShouldBe("tileset.png");
TiledMap?.EmbeddedTilesets[2].Name.ShouldBe("tileset-embedded");
[Test]
public void Tileset()
{
TiledMap?.Tilesets[0].FirstGid.ShouldBe(1);
TiledMap?.Tilesets[0].Source.ShouldBe("tileset.tsx");
TiledMap?.Tilesets[0].IsTilesetEmbedded.ShouldBe(false);
TiledMap?.Tilesets[1].FirstGid.ShouldBe(2);
TiledMap?.Tilesets[1].Source.ShouldBe(null);
TiledMap?.Tilesets[1].IsTilesetEmbedded.ShouldBe(true);

}
Tilesets?[1].Image.Source.ShouldBe("tileset.png");
Tilesets?[1].TilesetVersion.ShouldBe("1.8");
TiledMap?.EmbeddedTilesets[2].Name.ShouldBe("tileset-embedded110");
}

[Test]
public void Layers()
{
TiledMap?.Layers[0].TintColor.ShouldBe(new Color(255, 254, 253, 252));
TiledMap?.Layers[2].Name.ShouldBe("Image Layer 1");
}
[Test]
public void Layers()
{
TiledMap?.Layers[0].TintColor.ShouldBe(new Color(255, 254, 253, 252));
TiledMap?.Layers[2].Name.ShouldBe("Image Layer 1");
TiledMap?.Layers[1].Objects[0].Class.ShouldBe("test110");
}

[Test]
public void CompabilityWith19()
{
TiledMap19?.MapVersion.ShouldBe("1.9");
TiledMap19?.Layers[1].Objects[0].Class.ShouldBe("test19");
}
}
28 changes: 14 additions & 14 deletions TiledCSPlus.Test/assets/TiledCSPlus_test.tiled-project
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"automappingRulesFile": "",
"commands": [
],
"compatibilityVersion": 1080,
"extensionsPath": "extensions",
"folders": [
"."
],
"properties": [
],
"propertyTypes": [
]
}
{
"automappingRulesFile": "",
"commands": [
],
"compatibilityVersion": 1100,
"extensionsPath": "extensions",
"folders": [
"."
],
"properties": [
],
"propertyTypes": [
]
}
46 changes: 37 additions & 9 deletions TiledCSPlus.Test/assets/TiledCSPlus_test.tiled-session
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"height": 4300,
"width": 2
},
"activeFile": "D:/Projects/csharp/TiledCSPlus/TiledCSPlus.Example/assets/tilemap.tmx",
"activeFile": "tileset.tsx",
"expandedProjectPaths": [
"."
],
Expand All @@ -12,12 +12,23 @@
"": {
"scaleInDock": 1
},
"D:/Projects/csharp/MelonEngine/MelonEngine.Common/data/levels/map01.tmx": {
"scale": 1,
"selectedLayer": 0,
"viewCenter": {
"x": 480,
"y": -0.5
}
},
"D:/Projects/csharp/MelonEngine/MelonEngine.Common/data/sprites/overworld.tsx": {
"scaleInDock": 1
},
"D:/Projects/csharp/TiledCSPlus/TiledCSPlus.Example/assets/tilemap.tmx": {
"scale": 7.43375,
"selectedLayer": 0,
"viewCenter": {
"x": 84.54683033462251,
"y": 79.50227005212713
"x": 79.90583487472676,
"y": 79.83857407096014
}
},
"D:/Projects/csharp/TiledCSPlus/TiledCSPlus.Example/assets/tilemap.tmx#tileset-embedded": {
Expand All @@ -30,8 +41,8 @@
"scale": 4,
"selectedLayer": 0,
"viewCenter": {
"x": 79.875,
"y": 80
"x": 225.375,
"y": 134
}
},
"tilemap.tmx#tileset": {
Expand All @@ -40,6 +51,21 @@
"tilemap.tmx#tileset-embedded": {
"scaleInDock": 1
},
"tilemap1.9.tmx": {
"scale": 3.645625,
"selectedLayer": 1,
"viewCenter": {
"x": 80.09600548602779,
"y": 80.23315618035316
}
},
"tilemap1.9.tmx#tileset-embedded": {
"scaleInDock": 1
},
"tilemap1.9.tmx#tileset-embedded19": {
"scaleInDock": 1,
"scaleInEditor": 1
},
"tileset.tsx": {
"scaleInDock": 1,
"scaleInEditor": 1
Expand All @@ -53,15 +79,17 @@
"map.tileWidth": 16,
"map.width": 10,
"openFiles": [
"tilemap.tmx",
"D:/Projects/csharp/TiledCSPlus/TiledCSPlus.Example/assets/tilemap.tmx",
"D:/Projects/csharp/MelonEngine/MelonEngine.Common/data/levels/map01.tmx",
"tilemap1.9.tmx",
"tileset.tsx"
],
"project": "TiledCSPlus_test.tiled-project",
"recentFiles": [
"tilemap.tmx",
"D:/Projects/csharp/MelonEngine/MelonEngine.Common/data/levels/map01.tmx",
"tilemap1.9.tmx",
"tileset.tsx",
"D:/Projects/csharp/TiledCSPlus/TiledCSPlus.Example/assets/tilemap.tmx"
"D:/Projects/csharp/TiledCSPlus/TiledCSPlus.Example/assets/tilemap.tmx",
"tilemap.tmx"
],
"tileset.embedInMap": true,
"tileset.lastUsedFilter": "Tiled tileset files (*.tsx *.xml)",
Expand Down
17 changes: 17 additions & 0 deletions TiledCSPlus.Test/assets/tilemap1.10.tmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" backgroundcolor="#04010203" nextlayerid="5" nextobjectid="2">
<tileset firstgid="1" source="tileset.tsx"/>
<tileset firstgid="2" name="tileset-embedded110" tilewidth="16" tileheight="16" tilecount="1" columns="1">
<image source="tileset.png" width="16" height="16"/>
</tileset>
<layer id="1" name="Tile Layer 1" width="10" height="10" tintcolor="#fcfffefd">
<data encoding="base64">
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAAAAAQAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAQAAAAEAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
</data>
</layer>
<objectgroup id="2" name="Object Layer 1">
<object id="1" type="test110" x="14.8123" y="15.0866" width="129.196" height="129.196"/>
</objectgroup>
<imagelayer id="3" name="Image Layer 1"/>
<group id="4" name="Group Layer 1"/>
</map>
Loading

0 comments on commit 27de0be

Please sign in to comment.