Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public sealed class LDtkDefinitionObjectTileset : LDtkDefinitionObject<TilesetDe
[field: Tooltip("Grid-based size")]
[field: SerializeField] public Vector2Int CSize { get; private set; }

[field: Tooltip("Artifacts generated from this tileset that contain tiles and sprites.")]
[field: SerializeField] public LDtkArtifactAssetsTileset Artifacts { get; private set; }

[field: Tooltip("If this value is set, then it means that this atlas uses an internal LDtk atlas image instead of a loaded one.")]
[field: SerializeField] public bool EmbedAtlas { get; private set; }

Expand Down Expand Up @@ -64,6 +67,7 @@ internal override void SetAssetName()
internal override void Populate(LDtkDefinitionObjectsCache cache, TilesetDefinition def)
{
CSize = def.UnityCSize;
Artifacts = cache.GetTilesetArtifacts(def.Uid);
EmbedAtlas = def.EmbedAtlas != null;
Identifier = def.Identifier;
Padding = def.Padding;
Expand All @@ -84,4 +88,4 @@ internal override void Populate(LDtkDefinitionObjectsCache cache, TilesetDefinit
//SavedSelections = def.SavedSelections;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class LDtkDefinitionObjectsCache

//key: tilesetuid, value: rectangle to sprite ref
private Dictionary<int, Dictionary<Rect,Sprite>> _allSprites;
private Dictionary<int, LDtkArtifactAssetsTileset> _tilesetArtifacts;

internal LDtkDefinitionObjectsCache(LDtkDebugInstance logger)
{
Expand Down Expand Up @@ -69,9 +70,15 @@ public void InitializeFromLevel(List<LDtkDefinitionObject> defs, Dictionary<int,

private void InitializeTilesets(Dictionary<int, LDtkArtifactAssetsTileset> tilesets)
{
_allSprites = new Dictionary<int, Dictionary<Rect,Sprite>>(tilesets.Count);
tilesets ??= new Dictionary<int, LDtkArtifactAssetsTileset>();

_tilesetArtifacts = new Dictionary<int, LDtkArtifactAssetsTileset>(tilesets.Count);
_allSprites = new Dictionary<int, Dictionary<Rect, Sprite>>(tilesets.Count);

foreach (var pair in tilesets)
{
_tilesetArtifacts[pair.Key] = pair.Value;

Dictionary<Rect, Sprite> dict;
if (pair.Value != null)
{
Expand All @@ -83,6 +90,7 @@ private void InitializeTilesets(Dictionary<int, LDtkArtifactAssetsTileset> tiles
{
dict = new Dictionary<Rect, Sprite>();
}

_allSprites.Add(pair.Key, dict);
}
}
Expand Down Expand Up @@ -212,7 +220,7 @@ public T GetObject<T>(int uid) where T : ScriptableObject
_logger.LogError($"Failed to get a \"{typeof(T).Name}\" of uid {uid} due to a type mismatch with {obj.GetType().Name}");
return null;
}

/// <summary>
/// Could return null sprite if the tile would only have clear pixels.
/// <seealso cref="LDtkArtifactAssetsTileset.FindAdditionalSpriteForRect"/>
Expand Down Expand Up @@ -252,6 +260,16 @@ public Sprite GetSpriteForTilesetRectangle(TilesetRectangle rectangle)

return sprite;
}

internal LDtkArtifactAssetsTileset GetTilesetArtifacts(int uid)
{
if (_tilesetArtifacts != null && _tilesetArtifacts.TryGetValue(uid, out var artifacts))
{
return artifacts;
}

return null;
}

private void CacheDictToListViaProject()
{
Expand All @@ -274,4 +292,4 @@ private void CacheListToDictViaLevel()
}
}
}
}
}