Files
Christopher Whitley 3a5269cfea Reorganization (#909)
* Removed MonoGame.Extended.Animations
This project was just a shell that referenced MonoGame.Extended.csproj. It added no additional functionality.

* Rework BitmapFonts for new project organization.

* Cleanup namespaces

* Cleanup namespaces

* Move MonoGame.Extended.Collision into base project

* Moved MonoGame.Extended.Entities into base project

* Moved MonoGame.Extended.Graphics into base project

* Moved MonoGame.Extended.Graphics into base project

* Moved MonoGame.Extended.Input into base project

* Moved MonoGame.Extended.Particles into base project

* Moved MonoGame.Extended.Tiled into base project

* Moved MonoGame.Extended.Tiled into base project

* Moved MonoGame.Extended.Tweening into base project

* Removing SpriteFactory support
This will be added back in at a later date once the SpriteFactory application has been updated

* Update TexturePacker content import support

* Only needs to reference base project now

* Moved to Serialization namespace

* Moved  Json serialization to Serialization.Json namespace

* Moved TexturePacker content DTOs to the Content namespace

* Renamed to Texture2DRegion.Extensions.cs

* Cleaned up namespace

* Moved ReadTiledMapProperties into the ContentReaderExtensions

* Created an Extended content manager

* Moved Tweening tests to base test project

* Moved Tiled test to base test project

* Moved Entities Tests to base test project

* Moved Entities tests to base test project

* Moved Collisions tests to base test project

* Moved Pipeline Tiled test to Pipeline tests project

* Use `var` instead of full type name

* Add Tiled namespace

* Correct `Metadata` property name to new `Meta` property name

* Cleanup namespace

* Add effects namespace

* Add Content namespace

* Update using statements to new namespaces

* Move Pipeline Tiled tests to Pipeline test project

* Use correct namespace

* Use `var` instead of typing out nested types

* Remove unused namespaces

* Update to new namespaces

* Remove unused namespaces

* Update to new namespaces

* Remove dependency on Particles csproj

* Update included content on build

* Add embedded resources

* Merge multi csproj structure into single csproj structure

* TexturePackerPoint properties should be `double` not `int`

* Update csproj

* Use dotnet tool to rebuild effects

* Move effect compilation to targets file
This will ensure the effects are always built

* Fix workflow to build effects on linux

* Set wine path

* Export instead of using actions env section

* Revert back to manual effect compile until automation can be solved on GitHub Ubuntu runner
2024-07-06 23:46:20 -04:00

152 lines
5.5 KiB
C#

using System;
using System.Globalization;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using MonoGame.Extended.Content.Tiled;
using MonoGame.Extended.Tiled;
namespace MonoGame.Extended.Content.Pipeline.Tiled
{
[ContentTypeWriter]
public class TiledMapTilesetWriter : ContentTypeWriter<TiledMapTilesetContentItem>
{
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return typeof(TiledMapTilesetReader).AssemblyQualifiedName;
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return typeof(TiledMapTileset).AssemblyQualifiedName;
}
protected override void Write(ContentWriter writer, TiledMapTilesetContentItem contentItem)
{
try
{
WriteTileset(writer, contentItem.Data, contentItem);
}
catch (Exception ex)
{
ContentLogger.Logger.LogImportantMessage(ex.StackTrace);
throw;
}
}
public static void WriteTileset(ContentWriter writer, TiledMapTilesetContent tileset, IExternalReferenceRepository externalReferenceRepository)
{
var externalReference = externalReferenceRepository.GetExternalReference<Texture2DContent>(tileset.Image?.Source);
writer.WriteExternalReference(externalReference);
writer.Write(tileset.Class ?? tileset.Type ?? string.Empty);
writer.Write(tileset.TileWidth);
writer.Write(tileset.TileHeight);
writer.Write(tileset.TileCount);
writer.Write(tileset.Spacing);
writer.Write(tileset.Margin);
writer.Write(tileset.Columns);
writer.Write(tileset.Tiles.Count);
foreach (var tilesetTile in tileset.Tiles)
WriteTilesetTile(writer, tilesetTile, externalReferenceRepository);
writer.WriteTiledMapProperties(tileset.Properties);
}
private static void WriteTilesetTile(ContentWriter writer, TiledMapTilesetTileContent tilesetTile,
IExternalReferenceRepository externalReferenceRepository)
{
var externalReference = externalReferenceRepository.GetExternalReference<Texture2DContent>(tilesetTile.Image?.Source);
writer.WriteExternalReference(externalReference);
writer.Write(tilesetTile.LocalIdentifier);
writer.Write(tilesetTile.Type);
writer.Write(tilesetTile.Frames.Count);
writer.Write(tilesetTile.Objects.Count);
foreach (var @object in tilesetTile.Objects)
WriteObject(writer, @object);
foreach (var frame in tilesetTile.Frames)
{
writer.Write(frame.TileIdentifier);
writer.Write(frame.Duration);
}
writer.WriteTiledMapProperties(tilesetTile.Properties);
}
private static void WriteObject(ContentWriter writer, TiledMapObjectContent @object)
{
var type = GetObjectType(@object);
writer.Write((byte)type);
writer.Write(@object.Identifier);
writer.Write(@object.Name ?? string.Empty);
writer.Write(@object.Class ?? @object.Type ?? string.Empty);
writer.Write(@object.X);
writer.Write(@object.Y);
writer.Write(@object.Width);
writer.Write(@object.Height);
writer.Write(@object.Rotation);
writer.Write(@object.Visible);
writer.WriteTiledMapProperties(@object.Properties);
switch (type)
{
case TiledMapObjectType.Rectangle:
case TiledMapObjectType.Ellipse:
break;
case TiledMapObjectType.Tile:
writer.Write(@object.GlobalIdentifier);
break;
case TiledMapObjectType.Polygon:
WritePolyPoints(writer, @object.Polygon.Points);
break;
case TiledMapObjectType.Polyline:
WritePolyPoints(writer, @object.Polyline.Points);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
// ReSharper disable once SuggestBaseTypeForParameter
private static void WritePolyPoints(ContentWriter writer, string @string)
{
var stringPoints = @string.Split(' ');
writer.Write(stringPoints.Length);
foreach (var stringPoint in stringPoints)
{
var xy = stringPoint.Split(',');
var x = float.Parse(xy[0], CultureInfo.InvariantCulture.NumberFormat);
writer.Write(x);
var y = float.Parse(xy[1], CultureInfo.InvariantCulture.NumberFormat);
writer.Write(y);
}
}
public static TiledMapObjectType GetObjectType(TiledMapObjectContent content)
{
if (content.GlobalIdentifier > 0)
return TiledMapObjectType.Tile;
if (content.Ellipse != null)
return TiledMapObjectType.Ellipse;
if (content.Polygon != null)
return TiledMapObjectType.Polygon;
// ReSharper disable once ConvertIfStatementToReturnStatement
if (content.Polyline != null)
return TiledMapObjectType.Polyline;
return TiledMapObjectType.Rectangle;
}
}
}