-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileset.cs
134 lines (122 loc) · 4.06 KB
/
Tileset.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System.Text.Json;
namespace TiledJson;
public class Tileset
{
public string? BackgroundColor { get; set; }
public string? Class { get; set; }
public int Columns { get; set; }
public string FillMode { get; set; } = "stretch";
public int FirstGid { get; set; }
public Grid? Grid { get; set; }
public string Image { get; set; } = "";
public int ImageHeight { get; set; }
public int ImageWidth { get; set; }
public int Margin { get; set; }
public string Name { get; set; } = "";
public string ObjectAlignment { get; set; } = "unspecified";
public List<Property> Properties { get; set; } = new();
public string Source { get; set; } = "";
// TODO: this needs to be used when returning tile rect
public int Spacing { get; set; }
public List<Terrain>? Terrains { get; set; }
public int TileCount { get; set; }
public string TiledVersion { get; set; } = "";
public int TileHeight { get; set; }
public TileOffset? TileOffset { get; set; }
public string TileRenderSize { get; set; } = "tile";
public List<Tile>? Tiles { get; set; }
public int TileWidth { get; set; }
public Transformations? Transformations { get; set; }
public string? TransparentColor { get; set; }
public string Type { get; set; } = "tileset";
public string Version { get; set; } = "";
public List<WangSet> WangSets { get; set; } = new();
public static Tileset Load(StreamReader fstream)
{
try
{
var tset = JsonSerializer.Deserialize<Tileset>(fstream.ReadToEnd(), new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
if (tset is null)
throw new Exception("Failed to deserialize map");
return tset;
}
catch (JsonException e)
{
throw new Exception($"Failed to deserialize map: {e.Message}");
}
}
}
public class Grid
{
public int Height { get; set; }
public string Orientation { get; set; } = "orthogonal";
public int Width { get; set; }
}
public class TileOffset
{
public int X { get; set; }
public int Y { get; set; }
}
public class Transformations
{
public bool HFlip { get; set; }
public bool VFlip { get; set; }
public bool Rotate { get; set; }
public bool PrefeRunTransformed { get; set; }
}
public class Tile
{
public List<Frame> Animation { get; set; } = new();
public int Id { get; set; }
public string? Image { get; set; }
public int ImageHeight { get; set; }
public int ImageWidth { get; set; }
public int X { get; set; } = 0;
public int Y { get; set; } = 0;
// TODO: should default to image width.. not sure if this is set by tiled
public int Width { get; set; }
public int Height { get; set; }
public Layer? ObjectGroup { get; set; }
public double? Probability { get; set; }
public List<Property> Properties { get; set; } = new();
public List<int>? Terrain { get; set; }
public string? Type { get; set; }
}
public class Frame
{
public int Duration { get; set; }
public int TileId { get; set; }
}
public class Terrain
{
public string Name { get; set; } = "";
public List<Property> Properties { get; set; } = new();
public int Tile { get; set; }
}
public class WangSet
{
public string? Class { get; set; }
public List<WangColor> Colors { get; set; } = new();
public string Name { get; set; } = "";
public List<Property> Properties { get; set; } = new();
public int Tile { get; set; }
public string Type { get; set; } = ""; // corner, edge, mixed
public List<WangTile> WangTiles { get; set; } = new();
}
public class WangColor
{
public string? Class { get; set; }
public string Color { get; set; } = "";
public string Name { get; set; } = "";
public double Probability { get; set; }
public List<Property> Properties { get; set; } = new();
public int Tile { get; set; }
}
public class WangTile
{
public int TileId { get; set; }
public char[] WangId { get; set; } = new char[8]; // wang color indexes
}