Skip to content

Commit

Permalink
not adding backgrounds if they ended up null in the process
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammin committed Apr 26, 2024
1 parent 65cf6d6 commit db23043
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ private void CreateArtifactAsset(LdtkJson json)
_artifacts._backgrounds = new List<Sprite>(allBackgrounds);
foreach (Sprite bg in allBackgrounds)
{
//it's possible that some could be null if there was an illegal slice
if (bg == null)
{
continue;
}
ImportContext.AddObjectToAsset($"bg_{bg.name}", bg, (Texture2D)LDtkIconUtility.GetUnityIcon("Sprite"));
}
ImportContext.AddObjectToAsset("artifacts", _artifacts, (Texture2D)LDtkIconUtility.GetUnityIcon("Image"));
Expand Down Expand Up @@ -330,7 +335,7 @@ public void TryCacheArtifactsAsset(LDtkDebugInstance logger)
_artifacts = AssetDatabase.LoadAssetAtPath<LDtkArtifactAssets>(assetPath);
if (_artifacts == null)
{
logger.LogError($"Artifacts was null during the import, this should never happen. Does the sub asset not exist for \"{assetPath}\"?");
logger.LogError($"Artifacts was null during the import, likely due to a failed import for the project at \"{assetPath}\". Investigate other problems first.");
}
}
public LDtkArtifactAssets GetArtifactAssets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public Sprite CreateBackground()
Sprite sprite = _slicer.Slice();
if (sprite == null)
{
LDtkDebug.LogError($"Couldn't retrieve a sliced sprite for background for \"{_assetName}\"");
return null;
}
sprite.name = _assetName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ private List<Sprite> MakeAllBackgroundSlices(LdtkJson json)
continue;
}

// todo we cannot preemptively test the image's dimensions. wait until this value is available
//if (!ValidateTextureWithTilesetDef(def, texAsset))
//{
//continue;
//}
if (!ValidateTextureWithTilesetDef(level, bgTex))
{
continue;
}

if (bgTex == null)
{
Expand All @@ -79,5 +78,11 @@ private List<Sprite> MakeAllBackgroundSlices(LdtkJson json)

return backgrounds;
}

private bool ValidateTextureWithTilesetDef(Level level, Texture2D bgTex)
{
// todo we cannot preemptively test the image's dimensions. wait until this value is available
return true;
}
}
}
2 changes: 1 addition & 1 deletion Assets/LDtkUnity/Editor/Utility/LDtkTextureSpriteSlicer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Sprite Slice()

if (!LDtkCoordConverter.IsLegalSpriteSlice(_texture, _srcRect))
{
LDtkDebug.LogError($"Illegal sprite slice: {_srcRect} in {_texture.name}:({_texture.width}, {_texture.height}), Is the pixels per unit value set too big, or is the texture resolution incorrect?", _texture);
LDtkDebug.LogError($"Illegal sprite slice: Attempted a slice of {_srcRect} in the texture {_texture.name}:({_texture.width}, {_texture.height}). Is the pixels per unit value set too big, or is the texture resolution incorrect? Double check that your texture's max size in the import settings is large enough", _texture);
return null;
}

Expand Down

0 comments on commit db23043

Please sign in to comment.