private void Load() { Spriter = LoadContent <Spriter>(scmlPath); if (Spriter.Atlases == null || Spriter.Atlases.Length == 0) { return; } atlases = new Dictionary <int, TexturePackerSheet>(); infos = new Dictionary <TexturePackerSheet, Dictionary <string, ImageInfo> >(); foreach (var atlasRef in Spriter.Atlases) { string path = FormatPath(atlasRef.Name); TexturePackerSheet atlas = LoadContent <TexturePackerSheet>(path); atlases[atlasRef.Id] = atlas; Dictionary <string, ImageInfo> imageInfos = new Dictionary <string, ImageInfo>(); infos[atlas] = imageInfos; foreach (ImageInfo info in atlas.ImageInfos) { imageInfos[info.Name] = info; } } }
private void Load() { string data = File.ReadAllText(content.RootDirectory + "/" + scmlPath + ".scml"); Spriter = SpriterReader.Default.Read(data); if (Spriter.Atlases == null || Spriter.Atlases.Length == 0) { return; } atlases = new Dictionary <int, TexturePackerSheet>(); infos = new Dictionary <TexturePackerSheet, Dictionary <string, ImageInfo> >(); foreach (var atlasRef in Spriter.Atlases) { string path = FormatPath(atlasRef.Name); string atlasData = File.ReadAllText(content.RootDirectory + "/" + path); TexturePackerSheet atlas = TexturePackerSheetReader.Read(atlasData); atlases[atlasRef.Id] = atlas; Dictionary <string, ImageInfo> imageInfos = new Dictionary <string, ImageInfo>(); infos[atlas] = imageInfos; foreach (ImageInfo info in atlas.ImageInfos) { imageInfos[info.Name] = info; } } }
public static TexturePackerSheet Read(string data) { SpriterAtlasJson atlasJson = JsonConvert.DeserializeObject <SpriterAtlasJson>(data, new RectangleConverter()); TexturePackerSheet atlas = new TexturePackerSheet(); atlasJson.Fill(atlas); return(atlas); }
public void Fill(TexturePackerSheet atlas) { atlas.Meta = Meta; atlas.ImageInfos = new List <ImageInfo>(); foreach (var entry in Frames.ImageInfos) { ImageInfo info = entry.Value; info.Name = entry.Key; atlas.ImageInfos.Add(info); } }
private void AddAtlasFolder(SpriterFolder folder, DefaultProviderFactory <ISprite, SoundEffect> factory) { int id = folder.AtlasId; TexturePackerSheet atlas = atlases[id]; Texture2D texture = LoadContent <Texture2D>(FormatPath(atlas.Meta.Image)); Dictionary <string, ImageInfo> imageInfos = infos[atlas]; foreach (SpriterFile file in folder.Files) { ImageInfo info = imageInfos[file.Name]; // "x", "y" = location in spritesheet, "w", "h" = trimmed unrotated image size Size frame = info.Frame; // "w", "h" = original image size Size source = info.SourceSize; // "x", "y" = trimmed offset - pixels trimmed from the top and left Size spriteSource = info.SpriteSourceSize; Rectangle sourceRectangle; bool rotated = false; if (info.Rotated) { sourceRectangle = new Rectangle(frame.X, frame.Y, frame.H, frame.W); rotated = true; } else { sourceRectangle = new Rectangle(frame.X, frame.Y, frame.W, frame.H); } float trimLeft = spriteSource.X; float trimRight = source.W - frame.W - spriteSource.X; float trimTop = spriteSource.Y; float trimBottom = source.H - frame.H - spriteSource.Y; int width = source.W; int height = source.H; TexturePackerSprite sprite = new TexturePackerSprite(texture, sourceRectangle, width, height, rotated, trimLeft, trimRight, trimTop, trimBottom); factory.SetSprite(Spriter, folder, file, sprite); } }
public override TexturePackerSheetWrapper Import(string filename, ContentImporterContext context) { context.Logger.LogMessage("Importing Spriter Atlas file: {0}", filename); string jsonData = File.ReadAllText(filename); TexturePackerSheetWrapper ret = new TexturePackerSheetWrapper(); SpriterAtlasJson atlasJson = JsonConvert.DeserializeObject <SpriterAtlasJson>(jsonData, new RectangleConverter()); TexturePackerSheet atlas = new TexturePackerSheet(); atlasJson.Fill(atlas); XmlSerializer serializer = new XmlSerializer(typeof(TexturePackerSheet)); using (StringWriter sww = new StringWriter()) using (XmlWriter writer = XmlWriter.Create(sww)) { serializer.Serialize(writer, atlas); ret.AtlasData = sww.ToString(); } return(ret); }