TextureAtlasWriter.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #region License
  2. // Copyright 2016 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 System;
  17. using Microsoft.Xna.Framework.Content.Pipeline;
  18. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  19. using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
  20. using Microsoft.Xna.Framework.Graphics;
  21. namespace nkast.Aether.Content.Pipeline.Serialization
  22. {
  23. [ContentTypeWriter]
  24. class TextureAtlasWriter : ContentTypeWriter<TextureAtlasContent>
  25. {
  26. protected override void Write(ContentWriter output, TextureAtlasContent atlas)
  27. {
  28. output.WriteRawObject((Texture2DContent)atlas.Texture);
  29. // write Sprites
  30. output.Write(atlas.DestinationSprites.Count);
  31. foreach(string name in atlas.Sprites.Keys)
  32. {
  33. SpriteContent sprite = atlas.Sprites[name];
  34. output.Write(name);
  35. output.Write(sprite.Bounds.X);
  36. output.Write(sprite.Bounds.Y);
  37. output.Write(sprite.Bounds.Width);
  38. output.Write(sprite.Bounds.Height);
  39. }
  40. return;
  41. }
  42. public override string GetRuntimeReader(TargetPlatform targetPlatform)
  43. {
  44. return "nkast.Aether.Graphics.Content.TextureAtlasReader, Aether.Atlas";
  45. }
  46. }
  47. }