Skip to content

Commit

Permalink
unchanging renames and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammin committed May 2, 2024
1 parent 6066fa3 commit 436c2f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ internal sealed partial class LDtkTilesetImporter : LDtkJsonImporter<LDtkTileset
/// Holds onto all the standard grid-sized tiles. This serializes the sprite's changed settings between reimports, like pivot or physics shape.
/// </summary>
[SerializeField] internal List<LDtkSpriteRect> _sprites = new List<LDtkSpriteRect>();

/// <summary>
/// Any sprites that were defined from entity/level fields.
/// It's separate because we don't want to draw them in the sprite editor window, or otherwise make them configurable.
/// Also, because they won't have tilemap assets generated for them anyway, as their size wouldn't fit in the tilemap.
/// </summary>
private List<LDtkSpriteRect> _additionalTiles = new List<LDtkSpriteRect>();

[SerializeField] internal SecondarySpriteTexture[] _secondaryTextures;

private Texture2D _cachedExternalTex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static List<LDtkSpriteRect> UpdateLayers(in List<LDtkSpriteRect> newRect
}

/// <summary>
/// The main rewrite of the meta data.
/// The main rewrite of the meta data, NO additional sprites.
///
/// the sprite editor only modifies existing tiles.
///
Expand All @@ -123,28 +123,29 @@ private static List<LDtkSpriteRect> UpdateLayers(in List<LDtkSpriteRect> newRect
///
/// If the metadata had tiles that the importer no longer makes, remove them.
/// If the importer made some tiles that weren't metadata yet, make them.
/// don't make any modifications from iniside here. the user can configgure what they want later.
///
/// don't make any modifications from inside here. the user can configure what they want later.
///
/// </summary>
/// <param name="srcRects">The rectangles from the deserialized file. they should always overwrite the rects that we had at hand</param>
/// <returns></returns>
private bool ReformatRectMetaData(List<TilesetRectangle> srcRects)
{
bool changed = false;


int jsonTileCount = srcRects.Count;

// trim metas off the end of the list to match the new src count.
// LDtk handles this in the exact same way where if the tile count decreased, then any old tiles are complete
if (_sprites.Count > srcRects.Count)
if (_sprites.Count > jsonTileCount)
{
_sprites.RemoveRange(srcRects.Count, _sprites.Count - srcRects.Count);
_sprites.RemoveRange(jsonTileCount, _sprites.Count - jsonTileCount);
changed = true;
}

//add new blank ones to the end of the sprites list with new src rects
if (_sprites.Count < srcRects.Count)
if (_sprites.Count < jsonTileCount)
{
for (int tileId = _sprites.Count; tileId < srcRects.Count; tileId++)
for (int tileId = _sprites.Count; tileId < jsonTileCount; tileId++)
{
LDtkSpriteRect newRect = new LDtkSpriteRect
{
Expand All @@ -160,7 +161,7 @@ private bool ReformatRectMetaData(List<TilesetRectangle> srcRects)
changed = true;
}

Debug.Assert(_sprites.Count == srcRects.Count, "Sprite counts were not equal!");
Debug.Assert(_sprites.Count == jsonTileCount, "Sprite counts were not equal!");

//force rects to what they should really be.
for (int i = 0; i < _sprites.Count; i++)
Expand Down

0 comments on commit 436c2f7

Please sign in to comment.