TilemapWriter.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #region License
  2. // Copyright 2021 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using Microsoft.Xna.Framework.Content.Pipeline;
  17. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  18. using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
  19. using Microsoft.Xna.Framework.Graphics;
  20. using System;
  21. namespace nkast.Aether.Content.Pipeline.Serialization
  22. {
  23. [ContentTypeWriter]
  24. class TextureAtlasWriter : ContentTypeWriter<TilemapContent>
  25. {
  26. protected override void Write(ContentWriter output, TilemapContent atlas)
  27. {
  28. output.WriteRawObject((Texture2DContent)atlas.TextureAtlas);
  29. output.WriteRawObject((Texture2DContent)atlas.TextureMap);
  30. // write Sprites
  31. output.Write(atlas.DestinationTiles.Count);
  32. foreach(string name in atlas.Tiles.Keys)
  33. {
  34. TileContent sprite = atlas.Tiles[name];
  35. output.Write(name);
  36. output.Write(sprite.DstBounds.X);
  37. output.Write(sprite.DstBounds.Y);
  38. output.Write(sprite.DstBounds.Width);
  39. output.Write(sprite.DstBounds.Height);
  40. }
  41. return;
  42. }
  43. public override string GetRuntimeReader(TargetPlatform targetPlatform)
  44. {
  45. return "nkast.Aether.Graphics.Content.TilemapReader, Aether.Tilemap";
  46. }
  47. }
  48. }