Skip to content

Commit 73040e5

Browse files
committed
feat: Added new type checks for FieldDefinition among other small json data changes
1 parent 7279186 commit 73040e5

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

Assets/LDtkUnity/Runtime/Data/Extensions/Definition/FieldDefinition.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,62 @@ public partial class FieldDefinition : ILDtkUid, ILDtkIdentifier
1212
[IgnoreDataMember] public TilesetDefinition Tileset => TilesetUid == null ? null : LDtkUidBank.GetUidData<TilesetDefinition>(TilesetUid.Value);
1313

1414
[IgnoreDataMember] public Color UnityEditorDisplayColor => EditorDisplayColor.ToColor();
15+
16+
/// <value>
17+
/// Returns if this field (or array element) type is an Int.
18+
/// </value>
19+
[IgnoreDataMember] public bool IsInt => Type == "Int" || Type == "Array<Int>";
20+
21+
/// <value>
22+
/// Returns if this field (or array element) type is a Float.
23+
/// </value>
24+
[IgnoreDataMember] public bool IsFloat => Type == "Float" || Type == "Array<Float>";
25+
26+
/// <value>
27+
/// Returns if this field (or array element) type is a Bool.
28+
/// </value>
29+
[IgnoreDataMember] public bool IsBool => Type == "Bool" || Type == "Array<Bool>";
30+
31+
/// <value>
32+
/// Returns if this field (or array element) type is a String.
33+
/// </value>
34+
[IgnoreDataMember] public bool IsString => Type == "String" || Type == "Array<String>";
35+
36+
/// <value>
37+
/// Returns if this field (or array element) type is MultiLines.
38+
/// </value>
39+
[IgnoreDataMember] public bool IsMultilines => Type == "Multilines" || Type == "Array<Multilines>";
40+
41+
/// <value>
42+
/// Returns if this field (or array element) type is a FilePath.
43+
/// </value>
44+
[IgnoreDataMember] public bool IsFilePath => Type == "FilePath" || Type == "Array<FilePath>";
45+
46+
/// <value>
47+
/// Returns if this field (or array element) type is a Color.
48+
/// </value>
49+
[IgnoreDataMember] public bool IsColor => Type == "Color" || Type == "Array<Color>";
50+
51+
/// <value>
52+
/// Returns if this field (or array element) type is an Enum.
53+
/// </value>
54+
[IgnoreDataMember]
55+
public bool IsEnum => Type.Contains("LocalEnum.") || Type.Contains("ExternEnum.");
56+
57+
/// <value>
58+
/// Returns if this field (or array element) type is a Tile.
59+
/// </value>
60+
[IgnoreDataMember] public bool IsTile => Type == "Tile" || Type == "Array<Tile>";
61+
62+
/// <value>
63+
/// Returns if this field (or array element) type is a EntityRef.
64+
/// </value>
65+
[IgnoreDataMember] public bool IsEntityRef => Type == "EntityRef" || Type == "Array<EntityRef>";
66+
67+
/// <value>
68+
/// Returns if this field (or array element) type is a Point.
69+
/// </value>
70+
[IgnoreDataMember] public bool IsPoint => Type == "Point" || Type == "Array<Point>";
71+
1572
}
1673
}

Assets/LDtkUnity/Runtime/Data/Extensions/Instance/FieldInstance.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public partial class FieldInstance : ILDtkIdentifier
5252
/// Returns if this field (or array element) type is an Enum.
5353
/// </value>
5454
[IgnoreDataMember]
55-
public bool IsEnum => Type.StartsWith("LocalEnum.") || Type.StartsWith("Array<LocalEnum.") ||
56-
Type.StartsWith("ExternEnum.") || Type.StartsWith("Array<ExternEnum.");
55+
public bool IsEnum => Type.Contains("LocalEnum.") || Type.Contains("ExternEnum.");
5756

5857
/// <value>
5958
/// Returns if this field (or array element) type is a Tile.
@@ -74,5 +73,7 @@ public override string ToString()
7473
{
7574
return $"(defUid: {DefUid} | __identifier: {Identifier} | __type: {Type} | __value: {Value})";
7675
}
76+
77+
//todo Tile isn't used anywhere in the importer yet
7778
}
7879
}

Assets/LDtkUnity/Runtime/Data/Schema/Instance/LdtkTocInstanceData.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.Serialization;
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
23

34
namespace LDtkUnity
45
{
@@ -9,7 +10,7 @@ public partial class LdtkTocInstanceData
910
/// enabled. This object typing depends on actual field value types.
1011
/// </summary>
1112
[DataMember(Name = "fields")]
12-
public object Fields { get; set; }
13+
public Dictionary<string, object> Fields { get; set; }
1314

1415
[DataMember(Name = "heiPx")]
1516
public int HeiPx { get; set; }

0 commit comments

Comments
 (0)