diff --git a/SpriteBuilder/SpriteBuilder Tests/CCBPublisher_Tests.m b/SpriteBuilder/SpriteBuilder Tests/CCBPublisher_Tests.m index f08426984..be8126058 100644 --- a/SpriteBuilder/SpriteBuilder Tests/CCBPublisher_Tests.m +++ b/SpriteBuilder/SpriteBuilder Tests/CCBPublisher_Tests.m @@ -262,9 +262,9 @@ - (void)testSpriteSheets // The resolutions tests may be a bit too much here, but there are no // Tupac tests at the moment [self assertFileExists:@"Published-iOS/sheet-2x.plist"]; - [self assertPNGAtPath:@"Published-iOS/sheet-2x.png" hasWidth:32 hasHeight:16]; + [self assertPNGAtPath:@"Published-iOS/sheet-2x.png" hasWidth:16 hasHeight:16]; [self assertFileExists:@"Published-iOS/sheet-4x.plist"]; - [self assertPNGAtPath:@"Published-iOS/sheet-4x.png" hasWidth:32 hasHeight:32]; + [self assertPNGAtPath:@"Published-iOS/sheet-4x.png" hasWidth:32 hasHeight:16]; [self assertFileExists:@"Published-iOS/sheet-1x.plist"]; [self assertPNGAtPath:@"Published-iOS/sheet-1x.png" hasWidth:16 hasHeight:8]; diff --git a/SpriteBuilder/ccBuilder/CCBDirectoryPublisher.m b/SpriteBuilder/ccBuilder/CCBDirectoryPublisher.m index bec8312a7..57107e1b3 100644 --- a/SpriteBuilder/ccBuilder/CCBDirectoryPublisher.m +++ b/SpriteBuilder/ccBuilder/CCBDirectoryPublisher.m @@ -480,13 +480,12 @@ - (PublishSpriteSheetOperation *)createSpriteSheetOperation:(NSString *)publishD statusProgress:_publishingTaskStatusProgress]; NSString *spriteSheetCacheDir = [_projectSettings.tempSpriteSheetCacheDirectory stringByAppendingPathComponent:subPath]; - NSString *resolutionCacheDir = [spriteSheetCacheDir stringByAppendingPathComponent:[NSString stringWithFormat:@"resources-%@", resolution]]; operation.publishDirectory = publishDirectory; operation.publishedPNGFiles = _publishedPNGFiles; operation.srcSpriteSheetDate = srcSpriteSheetDate; operation.resolution = resolution; - operation.srcDirs = @[resolutionCacheDir, spriteSheetCacheDir]; + operation.srcDir = spriteSheetCacheDir; operation.spriteSheetFile = spriteSheetFile; operation.subPath = subPath; operation.osType = _osType; diff --git a/SpriteBuilder/ccBuilder/PublishGeneratedFilesOperation.m b/SpriteBuilder/ccBuilder/PublishGeneratedFilesOperation.m index ecc483e3d..527c11af2 100644 --- a/SpriteBuilder/ccBuilder/PublishGeneratedFilesOperation.m +++ b/SpriteBuilder/ccBuilder/PublishGeneratedFilesOperation.m @@ -98,6 +98,11 @@ - (void)generateFileLookup { [_warnings addWarningWithDescription:@"Could not write fileLookup.plist."]; } + + if (![_fileLookup TEMPwriteMetadataToFileAtomically:[_outputDir stringByAppendingPathComponent:@"metadata.plist"]]) + { + [_warnings addWarningWithDescription:@"Could not write metadata.plist."]; + } } - (NSString *)description diff --git a/SpriteBuilder/ccBuilder/PublishImageOperation.m b/SpriteBuilder/ccBuilder/PublishImageOperation.m index 4caad414a..287d41a63 100644 --- a/SpriteBuilder/ccBuilder/PublishImageOperation.m +++ b/SpriteBuilder/ccBuilder/PublishImageOperation.m @@ -131,6 +131,7 @@ - (void)publishImage dither:_dither compress:_compress isSpriteSheet:_isSpriteSheet + isAutoScaled:NO outputFilename:&dstPathConverted error:&error]) { @@ -183,6 +184,7 @@ - (void)publishImage dither:_dither compress:_compress isSpriteSheet:_isSpriteSheet + isAutoScaled:NO outputFilename:&dstPathConverted error:&error]) { diff --git a/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.h b/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.h index cc2387072..df8b5c56e 100644 --- a/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.h +++ b/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.h @@ -6,6 +6,7 @@ - (void)addRenamingRuleFrom:(NSString *)src to:(NSString *)dst; - (BOOL)writeToFileAtomically:(NSString *)filePath; +- (BOOL)TEMPwriteMetadataToFileAtomically:(NSString *)filePath; - (void)addIntermediateLookupPath:(NSString *)filePath; diff --git a/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.m b/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.m index 911630984..7240522d7 100644 --- a/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.m +++ b/SpriteBuilder/ccBuilder/PublishRenamedFilesLookup.m @@ -50,6 +50,20 @@ - (BOOL)writeToFileAtomically:(NSString *)filePath return [plist writeToFile:filePath atomically:YES]; } +- (BOOL)TEMPwriteMetadataToFileAtomically:(NSString *)filePath +{ + NSMutableDictionary *intermediateLookups = [self loadAndMergeIntermediateLookups]; + [_lookup addEntriesFromDictionary:intermediateLookups]; + + NSMutableDictionary *data = [NSMutableDictionary dictionary]; + for(NSString *alias in _lookup){ + data[alias] = @{@"filename": _lookup[alias]}; + } + + NSDictionary *metadata = @{@"data": data}; + return [metadata writeToFile:filePath atomically:YES]; +} + - (NSMutableDictionary *)loadAndMergeIntermediateLookups { NSMutableDictionary *result = [NSMutableDictionary dictionary]; diff --git a/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.h b/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.h index 8b4f7997e..d9a63c46e 100644 --- a/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.h +++ b/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.h @@ -11,7 +11,7 @@ @property (nonatomic, copy) NSString *spriteSheetFile; @property (nonatomic) CCBPublisherOSType osType; @property (nonatomic, copy) NSString *subPath; -@property (nonatomic, strong) NSArray *srcDirs; +@property (nonatomic, copy) NSString *srcDir; @property (nonatomic, copy) NSNumber *resolution; @property (nonatomic, copy) NSDate *srcSpriteSheetDate; @property (nonatomic, copy) NSString *publishDirectory; diff --git a/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.m b/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.m index bf912f45e..4ab6745a1 100644 --- a/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.m +++ b/SpriteBuilder/ccBuilder/PublishSpriteSheetOperation.m @@ -56,7 +56,7 @@ - (void)assertProperties { NSAssert(_spriteSheetFile != nil, @"spriteSheetFile should not be nil"); NSAssert(_subPath != nil, @"subPath should not be nil"); - NSAssert(_srcDirs != nil, @"srcDirs should not be nil"); + NSAssert(_srcDir != nil, @"srcDir should not be nil"); NSAssert(_resolution != nil, @"resolution should not be nil"); NSAssert(_srcSpriteSheetDate != nil, @"srcSpriteSheetDate should not be nil"); NSAssert(_publishDirectory != nil, @"publishDirectory should not be nil"); @@ -73,7 +73,8 @@ - (void)publishSpriteSheet [self configurePacker]; - NSArray *createdFiles = [_packer createTextureAtlasFromDirectoryPaths:_srcDirs]; + NSString *suffix = [NSString stringWithFormat:@"-%dx", self.resolution.intValue]; + NSArray *createdFiles = [_packer createTextureAtlasFromDirectoryPath:_srcDir withSuffix:suffix]; [self addCreatedPNGFilesToCreatedFilesSet:createdFiles]; @@ -190,8 +191,8 @@ - (void)cancel - (NSString *)description { - return [NSString stringWithFormat:@"file: %@, res: %@, osType: %i, filefull: %@, srcdirs: %@, publishDirectory: %@, date: %@", - [_spriteSheetFile lastPathComponent], _resolution, _osType, _spriteSheetFile, _srcDirs, _publishDirectory, _srcSpriteSheetDate]; + return [NSString stringWithFormat:@"file: %@, res: %@, osType: %i, filefull: %@, srcdir: %@, publishDirectory: %@, date: %@", + [_spriteSheetFile lastPathComponent], _resolution, _osType, _spriteSheetFile, _srcDir, _publishDirectory, _srcSpriteSheetDate]; } diff --git a/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.h b/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.h index 0c4c2e87f..f89971748 100644 --- a/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.h +++ b/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.h @@ -41,6 +41,7 @@ typedef enum { dither:(BOOL)dither compress:(BOOL)compress isSpriteSheet:(BOOL)isSpriteSheet + isAutoScaled:(BOOL)isAutoScaled outputFilename:(NSString**)outputFilename error:(NSError**)error; diff --git a/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.mm b/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.mm index 59fa8565f..862373039 100644 --- a/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.mm +++ b/SpriteBuilder/libs/FCFormatConverter/FCFormatConverter.mm @@ -71,6 +71,7 @@ -(BOOL)convertImageAtPath:(NSString*)srcPath dither:(BOOL)dither compress:(BOOL)compress isSpriteSheet:(BOOL)isSpriteSheet + isAutoScaled:(BOOL)isAutoScaled outputFilename:(NSString**)outputFilename error:(NSError**)error; { @@ -191,7 +192,16 @@ -(BOOL)convertImageAtPath:(NSString*)srcPath hasError = YES; } - + if(isAutoScaled && !hasError && !pvrtexture::GenerateMIPMaps(*pvrTexture, pvrtexture::eResizeLinear)){ + if (error) + { + NSString * errorMessage = [NSString stringWithFormat:@"Failure to generate mipmaps: %@", srcPath]; + NSDictionary * userInfo __attribute__((unused)) =@{NSLocalizedDescriptionKey:errorMessage}; + *error = [NSError errorWithDomain:kErrorDomain code:EPERM userInfo:userInfo]; + } + hasError = YES; + } + if(!hasError && !Transcode(*pvrTexture, pixelType, variableType, ePVRTCSpacelRGB, pvrtexture::ePVRTCBest, dither)) { if (error) @@ -235,7 +245,7 @@ -(BOOL)convertImageAtPath:(NSString*)srcPath // Create compressed file (ccz) self.zipTask = [[NSTask alloc] init]; [_zipTask setCurrentDirectoryPath:dstDir]; - [_zipTask setLaunchPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ccz"]]; + [_zipTask setLaunchPath:@"/usr/bin/gzip"]; NSMutableArray* args = [NSMutableArray arrayWithObjects:dstPath, nil]; [_zipTask setArguments:args]; [_zipTask launch]; @@ -246,7 +256,7 @@ -(BOOL)convertImageAtPath:(NSString*)srcPath [[NSFileManager defaultManager] removeItemAtPath:dstPath error:NULL]; // Update name of texture file - dstPath = [dstPath stringByAppendingPathExtension:@"ccz"]; + dstPath = [dstPath stringByAppendingPathExtension:@"gz"]; } if ([fm fileExistsAtPath:dstPath]) diff --git a/SpriteBuilder/libs/Tupac/Tupac.h b/SpriteBuilder/libs/Tupac/Tupac.h index 15540aace..2fae1285e 100644 --- a/SpriteBuilder/libs/Tupac/Tupac.h +++ b/SpriteBuilder/libs/Tupac/Tupac.h @@ -41,6 +41,7 @@ @property(nonatomic,copy) NSString* directoryPrefix; @property(nonatomic,assign) int maxTextureSize; @property(nonatomic,assign) int padding; +@property(nonatomic,assign) int divisor; @property(nonatomic,assign) BOOL dither; @property(nonatomic,assign) BOOL compress; @property(nonatomic,assign) BOOL trim; @@ -50,8 +51,8 @@ + (NSRect) trimmedRectForImage:(CGImageRef)image; -- (NSArray *)createTextureAtlasFromDirectoryPaths:(NSArray *)dirs; -- (NSArray *)createTextureAtlas; +- (NSArray *)createTextureAtlasFromDirectoryPath:(NSString *)dir withSuffix:(NSString *)suffix; +- (NSArray *)createTextureAtlasTrimSuffix:(NSString *)suffix; - (void)cancel; diff --git a/SpriteBuilder/libs/Tupac/Tupac.mm b/SpriteBuilder/libs/Tupac/Tupac.mm index 533949a15..06c414828 100644 --- a/SpriteBuilder/libs/Tupac/Tupac.mm +++ b/SpriteBuilder/libs/Tupac/Tupac.mm @@ -92,6 +92,7 @@ - (id)init self.outputFormat = TupacOutputFormatCocos2D; self.maxTextureSize = 2048; self.padding = 1; + self.divisor = 1; self.trim = YES; } return self; @@ -200,7 +201,24 @@ + (NSRect) trimmedRectForImage:(CGImageRef)image return NSMakeRect(x, y, wTrimmed, hTrimmed); } -- (NSArray *)createTextureAtlas +static NSString * +TrimSuffix(NSString *filename, NSString *suffix) +{ + NSString *basename = [filename stringByDeletingPathExtension]; + if([basename hasSuffix:suffix]) basename = [basename substringToIndex:basename.length - suffix.length]; + NSString *ext = [filename pathExtension]; + + return [basename stringByAppendingPathExtension:ext]; +} + +// Pad a size and round the result up to a multiple of the divisor +static int +PadSize(int size, int padding, int divisor) +{ + return (size + padding + divisor - 1)/divisor*divisor; +} + +- (NSArray *)createTextureAtlasTrimSuffix:(NSString *)suffix { // Reset the error message if (errorMessage) @@ -312,7 +330,7 @@ - (NSArray *)createTextureAtlas BOOL packingError = NO; while (!packingError && !allFitted) { - MaxRectsBinPack bin(outW, outH); + MaxRectsBinPack bin(outW - self.padding, outH - self.padding); std::vector inRects; @@ -322,8 +340,8 @@ - (NSArray *)createTextureAtlas NSRect trimRect = [imageInfo[@"trimRect"] rectValue]; inRects.push_back(TPRectSize()); - inRects[numImages].width = (int) (trimRect.size.width + self.padding * 2); - inRects[numImages].height = (int) (trimRect.size.height + self.padding * 2); + inRects[numImages].width = PadSize(trimRect.size.width, self.padding, self.divisor); + inRects[numImages].height = PadSize(trimRect.size.height, self.padding, self.divisor); inRects[numImages].idx = numImages; numImages++; @@ -471,6 +489,7 @@ - (NSArray *)createTextureAtlas dither:dither_ compress:compress_ isSpriteSheet:YES + isAutoScaled:NO outputFilename:&textureFileName error:&error]) { @@ -503,7 +522,7 @@ - (NSArray *)createTextureAtlas { // Get info about the image NSString* filename = self.filenames[(NSUInteger) outRects[index].idx]; - NSString* exportFilename = [filename lastPathComponent]; + NSString* exportFilename = TrimSuffix([filename lastPathComponent], suffix); if (directoryPrefix_) exportFilename = [directoryPrefix_ stringByAppendingPathComponent:exportFilename]; NSDictionary* imageInfo = imageInfos[(NSUInteger) outRects[index].idx]; @@ -539,7 +558,7 @@ - (NSArray *)createTextureAtlas @"sourceSize" : NSStringFromSize(NSMakeSize(wSrc, hSrc))}; } - metadata[@"textureFileName"] = textureFileName; + metadata[@"textureFileName"] = TrimSuffix(textureFileName, suffix); metadata[@"format"] = @2; metadata[@"size"] = NSStringFromSize(NSMakeSize(outW, outH)); @@ -573,52 +592,33 @@ - (void)generatePreviewImage:(NSString *)pngFilename } } -- (NSArray *) createTextureAtlasFromDirectoryPaths:(NSArray *)dirs +- (NSArray *) createTextureAtlasFromDirectoryPath:(NSString *)dir withSuffix:(NSString *)suffix; { NSFileManager* fm = [NSFileManager defaultManager]; - // Build a list of all file names from all directories - NSMutableSet* allFiles = [NSMutableSet set]; + // Add all the absolute file names to an array from the correct directories + NSMutableArray* absoluteFilepaths = [NSMutableArray array]; - for (NSString* dir in dirs) - { - NSArray* files = [fm contentsOfDirectoryAtPath:dir error:NULL]; - - if (cancelled_) - { - return nil; - } + NSArray* files = [fm contentsOfDirectoryAtPath:dir error:NULL]; - for (NSString* file in files) - { - NSString *lower = [[file pathExtension] lowercaseString]; - if ([lower isEqualToString:@"png"] || [lower isEqualToString:@"psd"]) - { - [allFiles addObject:[file lastPathComponent]]; - } - } + if (cancelled_) + { + return nil; } - - // Add all the absolute file names to an array from the correct directories - NSMutableArray* absoluteFilepaths = [NSMutableArray array]; - for (NSString* file in allFiles) + + for (NSString* file in files) { - for (NSString* dir in dirs) + NSString *ext = [[file pathExtension] lowercaseString]; + NSString *basename = [file stringByDeletingPathExtension]; + if ([basename hasSuffix:suffix] && ([ext isEqualToString:@"png"] || [ext isEqualToString:@"psd"])) { - NSString* absFilepath = [dir stringByAppendingPathComponent:file]; - - if ([fm fileExistsAtPath:absFilepath]) - { - [absoluteFilepaths addObject:absFilepath]; - //foundFile = YES; - break; - } + [absoluteFilepaths addObject:[dir stringByAppendingPathComponent:file]]; } } // Generate the sprite sheet self.filenames = absoluteFilepaths; - return [self createTextureAtlas]; + return [self createTextureAtlasTrimSuffix:suffix]; } - (void)cancel diff --git a/SpriteBuilder/libs/cocos2d-iphone b/SpriteBuilder/libs/cocos2d-iphone index efe46f7d3..821826a16 160000 --- a/SpriteBuilder/libs/cocos2d-iphone +++ b/SpriteBuilder/libs/cocos2d-iphone @@ -1 +1 @@ -Subproject commit efe46f7d358a6b2f40a959843e9cde308053e0dd +Subproject commit 821826a16e8e4a1b2b2b2938878e062904279d2c