@@ -76,9 +76,7 @@ object NewTexturePacker {
7676// println("Tileset: ${file}, images: $images")
7777 }
7878
79- packImages(images, enableRotation = false , enableTrimming = false , padding = padding, trimFileName = true , removeDuplicates = true )
80-
81- return listOf ()
79+ return packImages(images, enableRotation = false , enableTrimming = false , padding = padding, trimFileName = true , removeDuplicates = true )
8280 }
8381
8482 /* *
@@ -133,7 +131,8 @@ object NewTexturePacker {
133131 val mappedImages = if (removeDuplicates) { // mappedImages will contain only unique images if removeDuplicates is true
134132 // Remove duplicate images
135133 val uniqueMap = linkedMapOf<Int , Pair <File , SimpleBitmap >>()
136- for ((file, image) in images) {
134+ for ((fileName, image) in images) {
135+ val file = if (trimFileName) File (fileName.nameWithoutExtension) else fileName
137136 val hash = image.hashCode()
138137 val existing = uniqueMap[hash]
139138 if (existing == null ) {
@@ -144,7 +143,8 @@ object NewTexturePacker {
144143 uniqueMap.values.toList()
145144 } else {
146145 // No duplicate removal, use all images
147- for ((file, _) in images) {
146+ for ((fileName, _) in images) {
147+ val file = if (trimFileName) File (fileName.nameWithoutExtension) else fileName
148148 tileMapping[file] = file
149149 }
150150 images
@@ -164,7 +164,7 @@ object NewTexturePacker {
164164 ))
165165 })
166166
167- // Building info which includes mapping duplicates
167+ // Building info which includes mapping duplicates
168168 val outAtlases = arrayListOf<AtlasInfo >()
169169 // TODO for loop needs to go over tileMapping to map possible duplicate files to the same image area in the atlas
170170 for (bin in packer.bins) {
@@ -173,31 +173,37 @@ object NewTexturePacker {
173173
174174 for (rect in bin.rects) {
175175 val info = rect.raw as Info
176- val fileName = info.file.name
177- // println("$rect :: info=$info")
176+ // val fileName = info.file.name
177+ // Check if this rect (image) is used by any duplicate files
178+ val files = tileMapping.filterValues { it == info.file }.keys
179+ for (file in files) {
178180
179- val chunk = if (rect.rot) info.trimmedImage.flipY().rotate90() else info.trimmedImage
180- out .put(rect.x - padding, rect.y - padding, chunk.extrude(padding))
181- // out.put(rect.x, rect.y, chunk)
181+ val fileName = file.name
182182
183- val obj = LinkedHashMap <String , Any ?>()
183+ val chunk = if (rect.rot) info.trimmedImage.flipY().rotate90() else info.trimmedImage
184+ out .put(rect.x - padding, rect.y - padding, chunk.extrude(padding))
185+ // out.put(rect.x, rect.y, chunk)
184186
185- fun Dimension.toObj (rot : Boolean ): Map <String , Any ?> {
186- val w = if (! rot) width else height
187- val h = if (! rot) height else width
188- return mapOf (" w" to w, " h" to h)
189- }
190- fun Rectangle.toObj (rot : Boolean ): Map <String , Any ?> {
191- return mapOf (" x" to x, " y" to y) + this .size.toObj(rot)
192- }
187+ val obj = LinkedHashMap <String , Any ?>()
193188
194- obj[ " frame " ] = Rectangle (rect.x, rect.y, rect.width, rect.height). toObj(rect. rot)
195- obj[ " rotated " ] = rect. rot
196- obj[ " trimmed " ] = info.trimArea != info.fullArea
197- obj[ " spriteSourceSize " ] = info.trimArea.toObj( false )
198- obj[ " sourceSize " ] = info.fullArea.size.toObj( false )
189+ fun Dimension. toObj (rot : Boolean ): Map < String , Any ?> {
190+ val w = if ( ! rot) width else height
191+ val h = if ( ! rot) height else width
192+ return mapOf ( " w " to w, " h " to h )
193+ }
199194
200- frames[fileName] = obj
195+ fun Rectangle.toObj (rot : Boolean ): Map <String , Any ?> {
196+ return mapOf (" x" to x, " y" to y) + this .size.toObj(rot)
197+ }
198+
199+ obj[" frame" ] = Rectangle (rect.x, rect.y, rect.width, rect.height).toObj(rect.rot)
200+ obj[" rotated" ] = rect.rot
201+ obj[" trimmed" ] = info.trimArea != info.fullArea
202+ obj[" spriteSourceSize" ] = info.trimArea.toObj(false )
203+ obj[" sourceSize" ] = info.fullArea.size.toObj(false )
204+
205+ frames[fileName] = obj
206+ }
201207 }
202208
203209
0 commit comments