Skip to content

Commit

Permalink
minor optimize and check for if the relapth in a tileset was empty or…
Browse files Browse the repository at this point in the history
… null
  • Loading branch information
Cammin committed Sep 29, 2023
1 parent 9c8a190 commit 505838e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Assets/LDtkUnity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.0.2
###### September 28, 2023
- Added safety-check if a tileset definition's relPath was null or empty

# 4.0.1
###### September 28, 2023
- Updated json support for [LDtk 1.4](https://ldtk.io/json/#changes;1.4.0)
Expand Down
19 changes: 15 additions & 4 deletions Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private static string[] GatherDependenciesFromSourceFile(string path)
}

//this depends on the texture
//todo add a digger for getting the RelPath
LDtkProfiler.BeginSample($"GatherDependenciesFromSourceFile/{Path.GetFileName(path)}");
string texPath = PathToTexture(path);
texPath = !File.Exists(texPath) ? string.Empty : texPath;
Expand Down Expand Up @@ -408,8 +409,14 @@ private bool DeserializeAndAssign()
return false;
}

if (_json.RelPath.IsNullOrEmpty())
{
Logger.LogError($"The tileset relative path was null or empty! Try fixing the Tileset path in the LDtk editor for \"{assetPath}\"");
return false;
}

Profiler.BeginSample("GetTextureImporter");
string path = PathToTexture(assetPath);
string path = PathToTexture(assetPath, _json);

if (LDtkRelativeGetterTilesetTexture.IsAsepriteAsset(path))
{
Expand Down Expand Up @@ -452,9 +459,13 @@ private bool DeserializeAndAssign()
/// <summary>
/// Only use when needed, it performs a deserialize. look at optimizing if it's expensive
/// </summary>
private static string PathToTexture(string assetPath)
private static string PathToTexture(string assetPath, TilesetDefinition def = null)
{
TilesetDefinition def = FromJson<LDtkTilesetDefinition>(assetPath).Def;
if (def == null)
{
def = FromJson<LDtkTilesetDefinition>(assetPath).Def;
}

if (def.IsEmbedAtlas)
{
string iconsPath = LDtkProjectSettings.InternalIconsTexturePath;
Expand Down Expand Up @@ -553,7 +564,7 @@ private bool HasTextureIssue(TextureImporter textureImporter, TextureImporterPla

private Texture2D LoadTex(bool forceLoad = false)
{
//in case the importer was destroyed via file delete
//this is important: in case the importer was destroyed via file delete
if (this == null)
{
return null;
Expand Down

0 comments on commit 505838e

Please sign in to comment.