def Process(self, atlas, outputFilename): hppOutputFilename = '{0}.{1}'.format(outputFilename, 'hpp') cppOutputFilename = '{0}.{1}'.format(outputFilename, 'cpp') className = IOUtil.GetFileNameWithoutExtension(outputFilename) hppContent = self.__BuildHPPContent(atlas, className) cppContent = self.__BuildCPPContent(atlas, className) IOUtil.WriteFileIfChanged(hppOutputFilename, hppContent) IOUtil.WriteFileIfChanged(cppOutputFilename, cppContent)
def __init__(self, dict): super(TexturePackerFrame, self).__init__() self.Filename = dict["filename"] self.Frame = TexturePackerRectangle(dict["frame"]) self.Rotated = dict["rotated"] self.Trimmed = dict["trimmed"] self.SpriteSourceSize = TexturePackerRectangle(dict["spriteSourceSize"]) self.SourceSize = TexturePackerSize(dict["sourceSize"]) # self.Pivot = TexturePackerVector2(dict["pivot"]) self.FilenameWithoutExt = IOUtil.GetFileNameWithoutExtension(self.Filename) self.Path = IOUtil.ToUnixStylePath(os.path.dirname(self.Filename)) self.FullFilenameWithoutExt = IOUtil.Join(self.Path, self.FilenameWithoutExt)
def Process(self, atlas, outputFilename): pathInfo = self.__BuildPathDirectory(atlas.Entries) #self.__DebugPaths(atlas.Entries, pathInfo) entryDict = {} for entry in pathInfo[1]: entryDict[entry[2]+entry[1]] = entry list = [] AddHeader(list, 2); # make room for a number of bytes written entry and store the offset where it was written so we can pacth it later offset = len(list) AddUInt32(list, 0); self.__AddPathList(list, pathInfo[0]) AddEncodedUInt32(list, len(atlas.Entries)) for entry in atlas.Entries: rectX = entry.Frame.X - entry.SpriteSourceSize.X rectY = entry.Frame.Y - entry.SpriteSourceSize.Y rectWidth = entry.SourceSize.Width rectHeight = entry.SourceSize.Height self.__AddEntry(list, rectX, rectY, rectWidth, rectHeight, entry.Frame.X, entry.Frame.Y, entry.Frame.Width, entry.Frame.Height, entryDict[entry.FullFilenameWithoutExt]) # Write the number of bytes that were written to the extended header # -4 because we dont count the 'size' entry bytesWritten = len(list) - offset - 4 SetUInt32(list, offset, bytesWritten) content = bytearray(list) outputFilename = '%s.%s' % (outputFilename, 'bta') IOUtil.WriteBinaryFileIfChanged(outputFilename, content)
def Process(self, atlas: TexturePackerAtlas, outputFilename: str) -> None: dstList = [] # type: List[int] AddHeader(dstList, 1) # make room for a number of bytes written entry and store the offset where it was written so we can pacth it later offset = len(dstList) AddUInt32(dstList, 0) AddEncodedUInt32(dstList, len(atlas.Entries)) for entry in atlas.Entries: rectX = entry.Frame.X - entry.SpriteSourceSize.X rectY = entry.Frame.Y - entry.SpriteSourceSize.Y rectWidth = entry.SourceSize.Width rectHeight = entry.SourceSize.Height self.__AddEntry(dstList, rectX, rectY, rectWidth, rectHeight, entry.Frame.X, entry.Frame.Y, entry.Frame.Width, entry.Frame.Height, entry.FullFilenameWithoutExt) # Write the number of bytes that were written to the extended header # -4 because we dont count the 'size' entry bytesWritten = len(dstList) - offset - 4 SetUInt32(dstList, offset, bytesWritten) content = bytearray(dstList) outputFilename = '%s.%s' % (outputFilename, 'bta') IOUtil.WriteBinaryFileIfChanged(outputFilename, content)
def Process(self, atlas: TexturePackerAtlas, outputFilename: str) -> None: pathInfo = self.__BuildPathDirectory(atlas.Entries) self.__DebugPaths(atlas.Entries, pathInfo) entryDict = {} # type: Dict[str, Tuple[int,str,str]] for pathEntry in pathInfo[1]: entryDict[pathEntry[2]+pathEntry[1]] = pathEntry entryList = [] # type: List[int] AddHeader(entryList, 0x1001); # make room for a number of bytes written entry and store the offset where it was written so we can pacth it later offset = len(entryList) AddUInt32(entryList, 0); self.__AddPathList(entryList, pathInfo[0]) AddEncodedUInt32(entryList, len(atlas.Entries)) for entry in atlas.Entries: rectX = entry.Frame.X - entry.SpriteSourceSize.X rectY = entry.Frame.Y - entry.SpriteSourceSize.Y rectWidth = entry.SourceSize.Width rectHeight = entry.SourceSize.Height self.__AddEntry(entryList, rectX, rectY, rectWidth, rectHeight, entry.Frame.X, entry.Frame.Y, entry.Frame.Width, entry.Frame.Height, entryDict[entry.FullFilenameWithoutExt]) # Write the number of bytes that were written to the extended header # -4 because we dont count the 'size' entry bytesWritten = len(entryList) - offset - 4 SetUInt32(entryList, offset, bytesWritten) content = bytearray(entryList) outputFilename = '{0}.{1}'.format(outputFilename, 'bta') IOUtil.WriteBinaryFileIfChanged(outputFilename, content)
def __init__(self, dict): super(TexturePackerAtlas, self).__init__() if not "frames" in dict or not "meta" in dict: raise Exception("Unknown json format") self.Header = TexturePackerHeader(dict["meta"]) self.Entries = ExtractEntries(dict["frames"]) self.Name = IOUtil.GetFileNameWithoutExtension(self.Header.Image)
def __init__(self, jsonDict: Dict[str, Any], defaultDP: int) -> None: super().__init__() self.Filename = jsonDict["filename"] self.Frame = TexturePackerRectangle(jsonDict["frame"]) self.Rotated = jsonDict["rotated"] self.Trimmed = jsonDict["trimmed"] self.SpriteSourceSize = TexturePackerRectangle( jsonDict["spriteSourceSize"]) self.SourceSize = TexturePackerSize(jsonDict["sourceSize"]) # self.Pivot = TexturePackerVector2(jsonDict["pivot"]) self.FilenameWithoutExt = IOUtil.GetFileNameWithoutExtension( self.Filename) self.Path = IOUtil.ToUnixStylePath(os.path.dirname(self.Filename)) self.FullFilenameWithoutExt = IOUtil.Join(self.Path, self.FilenameWithoutExt) self.DP = self.__ParseDPI_Tag(self.FilenameWithoutExt, defaultDP)
def Process(self, atlas: TexturePackerAtlas, outputFilename: str) -> None: enableScale = self.__EnableScaleMod list = [] list.append('using System;') list.append('using System.Collections.Generic;') list.append('using Microsoft.Xna.Framework;') list.append('using MB.Base.Xna;') list.append('') list.append('namespace MB') list.append('{') list.append(' class %sTextureAtlas : ITextureAtlasInfo' % (atlas.Name)) list.append(' {') list.append(' public const string TheTextureName = "%s";' % (atlas.Name)) if enableScale: list.append(' public const int SCALE_X = 1;') list.append(' public const int SCALE_Y = 1;') list.append('') list.append( ' public static readonly Dictionary<string,AtlasTextureInfo> TheTextureInfo = new Dictionary<string,AtlasTextureInfo>()' ) list.append(' {') for entry in atlas.Entries: rectX = entry.Frame.X - entry.SpriteSourceSize.X rectY = entry.Frame.Y - entry.SpriteSourceSize.Y rectWidth = entry.SourceSize.Width rectHeight = entry.SourceSize.Height if not enableScale: list.append( ' { "%s", new AtlasTextureInfo(new Rectangle(%s, %s, %s, %s), new Rectangle(%s, %s, %s, %s)) },' % (entry.FullFilenameWithoutExt, rectX, rectY, rectWidth, rectHeight, entry.Frame.X, entry.Frame.Y, entry.Frame.Width, entry.Frame.Height)) else: list.append( ' { "%s", new AtlasTextureInfo(new Rectangle(%s * SCALE_X, %s * SCALE_Y, %s * SCALE_X, %s * SCALE_Y), new Rectangle(%s * SCALE_X, %s * SCALE_Y, %s * SCALE_X, %s * SCALE_Y)) },' % (entry.FullFilenameWithoutExt, rectX, rectY, rectWidth, rectHeight, entry.Frame.X, entry.Frame.Y, entry.Frame.Width, entry.Frame.Height)) list.append(' };') list.append('') list.append( ' public string TextureName { get { return TheTextureName; } }') list.append( ' public Dictionary<string,AtlasTextureInfo> TextureInfo { get { return TheTextureInfo; } }' ) list.append(' }') list.append('}') content = '\n'.join(list) outputFilename = '{0}.{1}'.format(outputFilename, 'cs') IOUtil.WriteFileIfChanged(outputFilename, content)
def __init__(self, jsonDict: Dict[str, Any], defaultDPI: int) -> None: super().__init__() if not "frames" in jsonDict or not "meta" in jsonDict: raise Exception("Unknown json format") self.Header = TexturePackerHeader(jsonDict["meta"]) self.Entries = ExtractEntries( jsonDict["frames"], defaultDPI) # type: List[TexturePackerFrame] self.Name = IOUtil.GetFileNameWithoutExtension(self.Header.Image)
def Process(self, atlas: TexturePackerAtlas, outputFilename: str) -> None: dateNow = datetime.datetime.now() list = [] list.append('//****************************************************************************************************************************************************') list.append('//* File Description') list.append('//* ----------------') list.append('//*') list.append('//* (c) {0} company_name_here'.format(dateNow.year)) list.append('//****************************************************************************************************************************************************') list.append('') list.append('using MB.Base.MathEx;') list.append('using MB.Graphics2.TextureAtlas;') list.append('using System.Collections.Generic;') list.append('') list.append('namespace MB') list.append('{') list.append(' class {0} : TextureAtlasBase'.format(atlas.Name)) list.append(' {') list.append(' public const string SourceTextureName = "{0}";'.format(atlas.Name)) list.append('') list.append(' public static readonly Dictionary<string, TextureAtlasImageInfo> SourceTextureInfo = new Dictionary<string, TextureAtlasImageInfo>()') list.append(' {') for entry in atlas.Entries: rectX = entry.Frame.X - entry.SpriteSourceSize.X rectY = entry.Frame.Y - entry.SpriteSourceSize.Y rectWidth = entry.SourceSize.Width rectHeight = entry.SourceSize.Height srcDP = entry.DP if srcDP == 160: list.append(' {{ "{0}", new TextureAtlasImageInfo(new Rectangle({1}, {2}, {3}, {4}), new Rectangle({5}, {6}, {7}, {8})) }},'.format(entry.FullFilenameWithoutExt, rectX, rectY, rectWidth, rectHeight, entry.Frame.X, entry.Frame.Y, entry.Frame.Width, entry.Frame.Height)) else: list.append(' {{ "{0}", new TextureAtlasImageInfo(new Rectangle({1}, {2}, {3}, {4}), new Rectangle({5}, {6}, {7}, {8}), {9}) }},'.format(entry.FullFilenameWithoutExt, rectX, rectY, rectWidth, rectHeight, entry.Frame.X, entry.Frame.Y, entry.Frame.Width, entry.Frame.Height, srcDP)) list.append(' };') list.append('') list.append(' public {0}()'.format(atlas.Name)) list.append(' : base(SourceTextureName, SourceTextureInfo)') list.append(' {') list.append(' }') list.append(' }') list.append('}') list.append('') list.append('//****************************************************************************************************************************************************') content = '\n'.join(list) outputFilename = '{0}.{1}'.format(outputFilename, 'cs') IOUtil.WriteFileIfChanged(outputFilename, content)