Skip to content

Commit

Permalink
Added initial support for image layers.
Browse files Browse the repository at this point in the history
fixes #1276
  • Loading branch information
vchelaru committed Nov 21, 2023
1 parent 3dc7fac commit 5002b43
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions Tiled/TMXGlueLib/DataTypes/ReducedTileMapInfo.TiledMapSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ private static void CreateFromTiledMapSave(TiledMapSave tiledMapSave, string tmx

firstGid = firstObjectWithTexture?.gid;
}
else
{
//Image layers and any other future layer types in Tiled are not supported at
//this time. Just move onto the next layer and ignore this one.
continue;
}

if (firstGid > 0)
{
Expand Down Expand Up @@ -186,6 +180,14 @@ private static void CreateFromTiledMapSave(TiledMapSave tiledMapSave, string tmx
}
}
}
else if (tiledLayer is MapImageLayer mapImageLayer)
{
if (!string.IsNullOrEmpty(mapImageLayer.ImageObject?.Source))
{
directory = tmxDirectory;
texture = FlatRedBall.IO.FileManager.RemoveDotDotSlash(directory + mapImageLayer.ImageObject.Source);
}
}

int tileWidth = tiledMapSave.tilewidth;
int tileHeight = tiledMapSave.tileheight;
Expand Down Expand Up @@ -217,6 +219,11 @@ private static void CreateFromTiledMapSave(TiledMapSave tiledMapSave, string tmx
{
AddObjectLayerTiles(reducedLayerInfo, tiledLayer, tileSet, tileWidth, tileHeight);
}

else if (tiledLayer is MapImageLayer mapImageLayer)
{
AddImageLayerTiles(reducedLayerInfo, mapImageLayer, tileWidth, tileHeight);
}
}
}

Expand Down Expand Up @@ -347,6 +354,42 @@ private static void AddObjectLayerTiles(ReducedLayerInfo reducedLayerInfo, Abstr
}
}

private static void AddImageLayerTiles(ReducedLayerInfo reducedLayerInfo, MapImageLayer mapImageLayer, int tileWidth, int tileHeight)
{
///////////////////////Early Out/////////////////////////
if (mapImageLayer.ImageObject == null)
{
return;
}
///////////////////////End Early Out/////////////////////////

ReducedQuadInfo quad = new DataTypes.ReducedQuadInfo();

quad.LeftQuadCoordinate = 0;
quad.BottomQuadCoordinate = (float)-mapImageLayer.ImageObject.Height;

quad.OverridingWidth = mapImageLayer.ImageObject.Width;
quad.OverridingHeight = mapImageLayer.ImageObject.Height;

quad.RotationDegrees = (float)0;

// todo...
quad.FlipFlags = 0;

int leftPixelCoord = 0;
int topPixelCoord = 0;
int rightPixelCoord = (int)mapImageLayer.ImageObject.Width;
int bottomPixelCoord = (int)mapImageLayer.ImageObject.Height;

quad.LeftTexturePixel = (ushort)Math.Min(leftPixelCoord, rightPixelCoord);
quad.TopTexturePixel = (ushort)Math.Min(topPixelCoord, bottomPixelCoord);

quad.Name = mapImageLayer.Name;

reducedLayerInfo?.Quads.Add(quad);

}

private static void CreateFromSpriteEditorScene(TiledMapSave tiledMapSave, float scale, float zOffset, FileReferenceType referenceType, ReducedTileMapInfo toReturn)
{
var ses = tiledMapSave.ToSceneSave(scale, referenceType);
Expand Down

0 comments on commit 5002b43

Please sign in to comment.