Skip to content

Commit

Permalink
fix: ldtkc files will now read/write object references with a guid to…
Browse files Browse the repository at this point in the history
… deserialize properly and to not dirty source control unnessesarily
  • Loading branch information
Cammin committed Dec 11, 2024
1 parent 4df48a5 commit 010cf9d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 21 deletions.
8 changes: 6 additions & 2 deletions Assets/LDtkUnity/Editor/Utility/Artifacts/LDtkConfigData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;

namespace LDtkUnity.Editor
Expand All @@ -23,7 +24,7 @@ internal struct LDtkConfigData
internal string WriteJson(string projectAssetPath)
{
string writePath = GetPath(projectAssetPath);
string json = JsonUtility.ToJson(this, true);
string json = EditorJsonUtility.ToJson(this, true);
byte[] byteArray = Encoding.UTF8.GetBytes(json);

LDtkPathUtility.TryCreateDirectoryForFile(writePath);
Expand All @@ -41,7 +42,10 @@ internal static LDtkConfigData ReadJson(string assetPath)

byte[] bytes = File.ReadAllBytes(assetPath);
string json = Encoding.UTF8.GetString(bytes);
return JsonUtility.FromJson<LDtkConfigData>(json);

LDtkConfigData data = new LDtkConfigData();
EditorJsonUtility.FromJsonOverwrite(json, data);
return data;
}

internal static string GetPath(string projectAssetPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
{
"_key": "IntGrid_1",
"_asset": {
"instanceID": 22226
"fileID": 11400000,
"guid": "85c839224be7398449b593cedc9d81ca",
"type": 2
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@
{
"_key": "IntGrid_1",
"_asset": {
"instanceID": 29410
"fileID": 11400000,
"guid": "019c844af99991d409a134bcc556b3b1",
"type": 2
}
},
{
"_key": "IntGrid_2",
"_asset": {
"instanceID": 28118
"fileID": 11400000,
"guid": "aee5cec04e488604cb16a7da061946bc",
"type": 2
}
},
{
"_key": "IntGrid_3",
"_asset": {
"instanceID": 24110
"fileID": 11400000,
"guid": "62504a226f3487f49af1e37703e72136",
"type": 2
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
{
"_key": "Collisions_1",
"_asset": {
"instanceID": 25948
"fileID": 11400000,
"guid": "608aedeab5fb3ac48959b083b4ecd7c1",
"type": 2
}
},
{
Expand All @@ -27,37 +29,49 @@
{
"_key": "Item",
"_asset": {
"instanceID": 30982
"fileID": 6381717676898315408,
"guid": "154ba3503afd20d4580ff3f817fd2177",
"type": 3
}
},
{
"_key": "Player",
"_asset": {
"instanceID": 33704
"fileID": 6381717676898315408,
"guid": "2c40888790883084b832d4183474c09a",
"type": 3
}
},
{
"_key": "Exit",
"_asset": {
"instanceID": 31998
"fileID": 6381717676898315408,
"guid": "109ac9123036bb24ca5866d7aa81f4b3",
"type": 3
}
},
{
"_key": "SecretArea",
"_asset": {
"instanceID": 31288
"fileID": 6381717676898315408,
"guid": "455e2726c152eb946bab81090f7c0afa",
"type": 3
}
},
{
"_key": "Teleport",
"_asset": {
"instanceID": 30554
"fileID": 6381717676898315408,
"guid": "9958dbc3bfc14c64ba545adf3467ed50",
"type": 3
}
},
{
"_key": "Ladder",
"_asset": {
"instanceID": 30794
"fileID": 6381717676898315408,
"guid": "4bd923e45ce962547bb6ae2dd76a5984",
"type": 3
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@
{
"_key": "TestAllFields",
"_asset": {
"instanceID": 43784
"fileID": 2518318380925621618,
"guid": "3222c3d6e0104884eb44c4821f66e354",
"type": 3
}
},
{
"_key": "NoFields",
"_asset": {
"instanceID": 43824
"fileID": 2518318380925621618,
"guid": "be7f9038a4c1bc04d9d62adff8d0cab8",
"type": 3
}
},
{
"_key": "TestAllNullable",
"_asset": {
"instanceID": 43832
"fileID": 2518318380925621618,
"guid": "55ee5e096e24b4542bc1968b36e6c019",
"type": 3
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,41 @@
{
"_key": "EntityFieldsTest",
"_asset": {
"instanceID": 70644
"fileID": 8271057754295682963,
"guid": "8edc4af9ae4379948ac2d95a7603e233",
"type": 3
}
},
{
"_key": "Labels",
"_asset": {
"instanceID": 70646
"fileID": 8271057754295682963,
"guid": "651dd273af932094fbe35791264dcfa4",
"type": 3
}
},
{
"_key": "RectRegion",
"_asset": {
"instanceID": 70648
"fileID": 8271057754295682963,
"guid": "e355c9bebb8a0fe458316f819cb5df56",
"type": 3
}
},
{
"_key": "CircleRegion",
"_asset": {
"instanceID": 70650
"fileID": 8271057754295682963,
"guid": "9a9f4260bc1dd5444a09370d4abf42f8",
"type": 3
}
},
{
"_key": "EntityRefTest",
"_asset": {
"instanceID": 70650
"fileID": 8271057754295682963,
"guid": "9a9f4260bc1dd5444a09370d4abf42f8",
"type": 3
}
}
]
Expand Down

0 comments on commit 010cf9d

Please sign in to comment.