Skip to content

Commit

Permalink
registering a dependency on tileset files
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammin committed Aug 16, 2023
1 parent 13c97b4 commit 6fd8a44
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
33 changes: 33 additions & 0 deletions Assets/LDtkUnity/Editor/ScriptedImporter/LDtkJsonDigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal static class LDtkJsonDigger

public static bool GetTilesetTextureRelPaths(string projectPath, ref HashSet<string> result) =>
DigIntoJson(projectPath, GetTilesetRelPathsReader, ref result);
public static bool GetTilesetDefNames(string projectPath, ref HashSet<string> result) =>
DigIntoJson(projectPath, GetTilesetDefNamesReader, ref result);
public static bool GetUsedEntities(string path, ref HashSet<string> result) =>
DigIntoJson(path, GetUsedEntitiesReader, ref result);
public static bool GetUsedIntGridValues(string path, ref HashSet<string> result) =>
Expand Down Expand Up @@ -168,6 +170,37 @@ private static bool GetTilesetRelPathsReader(ref JsonReader reader, ref HashSet<
}
return false;
}
private static bool GetTilesetDefNamesReader(ref JsonReader reader, ref HashSet<string> textures)
{
while (reader.Read())
{
if (!reader.ReadIsPropertyName("tilesets"))
{
continue;
}

while (reader.CanRead())
{
int depth = 0;
while (reader.IsInArray(ref depth))
{
if (reader.GetCurrentJsonToken() != JsonToken.String)
{
reader.ReadNext();
continue;
}

if (reader.ReadString() == "identifier" && reader.ReadIsNameSeparator())
{
string identifier = reader.ReadString();
textures.Add(identifier);
}
}
return true;
}
}
return false;
}

private static bool GetUsedEntitiesReader(ref JsonReader reader, ref HashSet<string> entities)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,33 @@ public static string[] GatherProjectDependencies(string projectPath)
return Array.Empty<string>();
}

bool isExternalLevels = false;
if (!LDtkJsonDigger.GetIsExternalLevels(projectPath, ref isExternalLevels))
string[] projectLines = LDtkDependencyUtil.LoadMetaLinesAtPath(projectPath);
if (LDtkDependencyUtil.ShouldDependOnNothing(projectLines))
{
LDtkDebug.LogError("Issue getting external levels");
return Array.Empty<string>();
}

string[] projectLines = LDtkDependencyUtil.LoadMetaLinesAtPath(projectPath);
if (LDtkDependencyUtil.ShouldDependOnNothing(projectLines))
bool isExternalLevels = false;
if (!LDtkJsonDigger.GetIsExternalLevels(projectPath, ref isExternalLevels))
{
LDtkDebug.LogError("Issue getting external levels");
return Array.Empty<string>();
}

HashSet<string> paths = new HashSet<string>();

//todo Create & depend on the tileset definition files!



HashSet<string> tilesetDefNames = new HashSet<string>();
LDtkJsonDigger.GetTilesetDefNames(projectPath, ref tilesetDefNames);

foreach (string defName in tilesetDefNames)
{
string tilesetPath = LDtkProjectImporter.TilesetImporterPath(projectPath, defName);
paths.Add(tilesetPath);
}

/*HashSet<string> texturePaths = new HashSet<string>();
if (LDtkJsonDigger.GetTilesetTextureRelPaths(projectPath, ref texturePaths))
{
Expand Down
13 changes: 13 additions & 0 deletions Assets/Tests/EditMode/Tests/TestJsonDigging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,18 @@ public static void GetTilesetRelPaths(string path)
Assert.IsTrue(success, "not successful");
Debug.Log($"GetTilesetRelPaths was {result.Count}: {string.Join(", ", result)}");
}
[Test]
[TestCaseSource(nameof(Projects))]
public static void GetTilesetDefNames(string path)
{
HashSet<string> result = new HashSet<string>();

LDtkProfiler.BeginSample($"{nameof(TestJsonDigging)}/{nameof(GetTilesetDefNames)}/{path}");
bool success = LDtkJsonDigger.GetTilesetDefNames(path, ref result);
LDtkProfiler.EndSample();

Assert.IsTrue(success, "not successful");
Debug.Log($"GetTilesetDefNames was {result.Count}: {string.Join(", ", result)}");
}
}
}

0 comments on commit 6fd8a44

Please sign in to comment.