Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- namespace Gamiron7 {
- struct JsonSize {
- [JsonProperty( "w" )]
- public int W { get; set; }
- [JsonProperty( "h" )]
- public int H { get; set; }
- }
- struct JsonRect {
- [JsonProperty( "x" )]
- public int X { get; set; }
- [JsonProperty( "y" )]
- public int Y { get; set; }
- [JsonProperty( "w" )]
- public int W { get; set; }
- [JsonProperty( "h" )]
- public int H { get; set; }
- }
- struct AtlasFrame {
- [JsonProperty("filename")]
- public string FileName { get; set; }
- [JsonProperty("frame")]
- public JsonRect Frame { get; set; }
- [JsonProperty( "rotated" )]
- public bool Rotated { get; set; }
- [JsonProperty( "trimmed" )]
- public bool Trimmed { get; set; }
- [JsonProperty( "spriteSourceSize" )]
- public JsonRect SpriteSourceSize { get; set; }
- [JsonProperty( "sourceSize" )]
- public JsonSize SourceSize { get; set; }
- }
- class TextureAtlas {
- [JsonProperty( "frames" )]
- public IList<AtlasFrame> Frames { get; set; }
- public AtlasFrame GetFrame( string name ) {
- foreach ( var f in Frames ) {
- if ( f.FileName == name ) {
- return f;
- }
- }
- throw new Exception( "There is no frame named " + name + " in this atlas!");
- }
- public AtlasFrame this[string frame] {
- get {
- return GetFrame( frame );
- }
- }
- public static TextureAtlas LoadFromFile( string fileName ) {
- return JsonConvert.DeserializeObject<TextureAtlas>( File.ReadAllText( fileName ) );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement