Skip to content

Commit

Permalink
caching intgrid groups better. added safety logger when getting the p…
Browse files Browse the repository at this point in the history
…roject artifacts
  • Loading branch information
Cammin committed Sep 24, 2023
1 parent cc700b0 commit 5d059d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected override void Import()
Profiler.EndSample();

Profiler.BeginSample("CacheArtifactsAsset");
_projectImporter.TryCacheArtifactsAsset();
_projectImporter.TryCacheArtifactsAsset(Logger);
Profiler.EndSample();

Profiler.BeginSample("CacheDefs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,8 @@ public Sprite GetBackgroundArtifact(Level level)
Logger.LogError($"Tried retrieving a background from the importer's artifacts, but was null: \"{assetName}\"");
return asset;
}





public void TryCacheArtifactsAsset()
public void TryCacheArtifactsAsset(LDtkDebugInstance logger)
{
if (_backgroundArtifacts != null)
{
Expand All @@ -327,7 +323,7 @@ public void TryCacheArtifactsAsset()
_backgroundArtifacts = AssetDatabase.LoadAssetAtPath<LDtkArtifactAssets>(assetPath);
if (_backgroundArtifacts == 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, this should never happen. Does the sub asset not exist for \"{assetPath}\"?");
}
}
}
Expand Down
22 changes: 18 additions & 4 deletions Assets/LDtkUnity/Runtime/Tools/Bank/LDtkDictionaryUId.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;

namespace LDtkUnity
{
Expand Down Expand Up @@ -42,10 +43,23 @@ private void CacheLayerDefs(LayerDefinition[] layerDefs)
{
TryAdd(layerDefs);

IntGridValueGroupDefinition[] groupDefs = layerDefs.SelectMany(p => p.IntGridValuesGroups).ToArray();
if (!groupDefs.IsNullOrEmpty())
List<IntGridValueGroupDefinition> defs = new List<IntGridValueGroupDefinition>();
foreach (LayerDefinition layerDef in layerDefs)
{
TryAdd(groupDefs);
//if it's an old json value
if (layerDef.IntGridValuesGroups == null)
{
continue;
}
foreach (IntGridValueGroupDefinition group in layerDef.IntGridValuesGroups)
{
defs.Add(group);
}
}

if (!defs.IsNullOrEmpty())
{
TryAdd(defs.ToArray());
}
}
}
Expand Down

0 comments on commit 5d059d7

Please sign in to comment.