Skip to content

Commit

Permalink
Merge pull request #790 from NickyWeber/bugfix/#736_selecting_resourc…
Browse files Browse the repository at this point in the history
…e_marks_them_as_dirty

Bugfix/#736 selecting resource marks them as dirty
  • Loading branch information
vlidholt committed Aug 21, 2014
2 parents 84b19d3 + 27dbfbe commit 0194424
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 381 deletions.
20 changes: 10 additions & 10 deletions SpriteBuilder/SpriteBuilder Tests/CCBPublisher_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ - (void)testCustomScalingFactorsForImages
[self createPNGAtPath:@"baa.spritebuilder/Packages/foo.sbpack/resources-tablethd/rocket.png" width:3 height:17];

_projectSettings.resourceAutoScaleFactor = 4;
[_projectSettings setValue:[NSNumber numberWithInt:1] forRelPath:@"rocket.png" andKey:@"scaleFrom"];
[_projectSettings setProperty:[NSNumber numberWithInt:1] forRelPath:@"rocket.png" andKey:@"scaleFrom"];

[_publisher addPublishingTarget:_targetIOS];
[_publisher start];
Expand All @@ -243,9 +243,9 @@ - (void)testDifferentOutputFormatsForIOSAndAndroid
_projectSettings.publishEnabledAndroid = YES;
_projectSettings.resourceAutoScaleFactor = 4;

[_projectSettings setValue:@(kFCImageFormatJPG_High) forRelPath:@"rocket.png" andKey:@"format_ios"];
[_projectSettings setValue:@(kFCImageFormatJPG_High) forRelPath:@"rocket.png" andKey:@"format_android"];
[_projectSettings setValue:@(kFCSoundFormatMP4) forRelPath:@"blank.wav" andKey:@"format_ios_sound"];
[_projectSettings setProperty:@(kFCImageFormatJPG_High) forRelPath:@"rocket.png" andKey:@"format_ios"];
[_projectSettings setProperty:@(kFCImageFormatJPG_High) forRelPath:@"rocket.png" andKey:@"format_android"];
[_projectSettings setProperty:@(kFCSoundFormatMP4) forRelPath:@"blank.wav" andKey:@"format_ios_sound"];

[_publisher addPublishingTarget:_targetIOS];
[_publisher addPublishingTarget:_targetAndroid];
Expand Down Expand Up @@ -280,7 +280,7 @@ - (void)testSpriteSheets
[self createPNGAtPath:@"baa.spritebuilder/Packages/foo.sbpack/sheet/resources-auto/sword.png" width:4 height:12 color:[NSColor yellowColor]];

_projectSettings.resourceAutoScaleFactor = 4;
[_projectSettings setValue:@(YES) forRelPath:@"sheet" andKey:@"isSmartSpriteSheet"];
[_projectSettings setProperty:@(YES) forRelPath:@"sheet" andKey:@"isSmartSpriteSheet"];

[_publisher addPublishingTarget:_targetIOS];
[_publisher start];
Expand Down Expand Up @@ -317,11 +317,11 @@ - (void)testSpriteSheetOutputPVRRGBA88888AndPVRTC
_projectSettings.publishResolution_ios_tablet = NO;
_projectSettings.publishResolution_ios_tablethd = NO;

[_projectSettings setValue:@(YES) forRelPath:@"pvr" andKey:@"isSmartSpriteSheet"];
[_projectSettings setValue:@(kFCImageFormatPVR_RGBA8888) forRelPath:@"pvr" andKey:@"format_ios"];
[_projectSettings setProperty:@(YES) forRelPath:@"pvr" andKey:@"isSmartSpriteSheet"];
[_projectSettings setProperty:@(kFCImageFormatPVR_RGBA8888) forRelPath:@"pvr" andKey:@"format_ios"];

[_projectSettings setValue:@(YES) forRelPath:@"pvrtc" andKey:@"isSmartSpriteSheet"];
[_projectSettings setValue:@(kFCImageFormatPVRTC_4BPP) forRelPath:@"pvrtc" andKey:@"format_ios"];
[_projectSettings setProperty:@(YES) forRelPath:@"pvrtc" andKey:@"isSmartSpriteSheet"];
[_projectSettings setProperty:@(kFCImageFormatPVRTC_4BPP) forRelPath:@"pvrtc" andKey:@"format_ios"];

_targetIOS.resolutions = [_projectSettings publishingResolutionsForOSType:kCCBPublisherOSTypeIOS];
[_publisher addPublishingTarget:_targetIOS];
Expand All @@ -344,7 +344,7 @@ - (void)testSpriteSheetOutputPVRRGBA88888AndPVRTC
- (void)testRepublishingWithoutCleaningCache
{
[self createPNGAtPath:@"baa.spritebuilder/Packages/foo.sbpack/sheet/resources-auto/rock.png" width:4 height:4 color:[NSColor redColor]];
[_projectSettings setValue:@(YES) forRelPath:@"sheet" andKey:@"isSmartSpriteSheet"];
[_projectSettings setProperty:@(YES) forRelPath:@"sheet" andKey:@"isSmartSpriteSheet"];
_targetIOS.resolutions = @[@"tablet"];

[_publisher addPublishingTarget:_targetIOS];
Expand Down
52 changes: 41 additions & 11 deletions SpriteBuilder/SpriteBuilder Tests/ProjectSettings_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ - (void)testInitWithDictionary

XCTAssertTrue(project.excludedFromPackageMigration);

NSNumber *scaleFrom = [project valueForRelPath:@"ccbResources/ccbSliderBgNormal.png" andKey:@"scaleFrom"];
NSNumber *scaleFrom = [project propertyForRelPath:@"ccbResources/ccbSliderBgNormal.png" andKey:@"scaleFrom"];
XCTAssertTrue([scaleFrom isEqualToNumber:@(2)]);
}

Expand Down Expand Up @@ -393,7 +393,7 @@ - (void)testResourcePropertiesAndPersistency
ProjectSettings *projectSettings = [[ProjectSettings alloc] init];
projectSettings.projectPath = fullPath;

[projectSettings setValue:@(kCCBPublishFormatSound_ios_mp4) forRelPath:@"foo/ping.wav" andKey:@"format_ios_sound"];
[projectSettings setProperty:@(kCCBPublishFormatSound_ios_mp4) forRelPath:@"foo/ping.wav" andKey:@"format_ios_sound"];

XCTAssertTrue([projectSettings store], @"Failed to persist project at path \"%@\"", projectSettings.projectPath);

Expand All @@ -402,7 +402,7 @@ - (void)testResourcePropertiesAndPersistency
projectSettings = [[ProjectSettings alloc] initWithSerialization:projectDict];
projectSettings.projectPath = fullPath;

NSNumber *value = [projectSettings valueForRelPath:@"foo/ping.wav" andKey:@"format_ios_sound"];
NSNumber *value = [projectSettings propertyForRelPath:@"foo/ping.wav" andKey:@"format_ios_sound"];
XCTAssertEqual([value integerValue], (NSInteger)kCCBPublishFormatSound_ios_mp4);
}

Expand Down Expand Up @@ -441,7 +441,7 @@ - (void)testConvenienceMethodForAudioQualityOfResources
NSInteger quality = [_projectSettings soundQualityForRelPath:@"foo" osType:kCCBPublisherOSTypeAndroid];
XCTAssertEqual(quality, NSNotFound);

[_projectSettings setValue:@(7) forRelPath:@"baa" andKey:@"format_android_sound_quality"];
[_projectSettings setProperty:@(7) forRelPath:@"baa" andKey:@"format_android_sound_quality"];
int quality2 = [_projectSettings soundQualityForRelPath:@"baa" osType:kCCBPublisherOSTypeAndroid];
XCTAssertEqual(quality2, 7);
}
Expand All @@ -457,8 +457,9 @@ - (void)testConvenienceMethodForAudioQuality

- (void)testMarkAsDirty
{
RMResource *resource = [[RMResource alloc] init];
resource.filePath = [self fullPathForFile:@"project/Packages/package1.sbpack/foo.png"];
RMResource *res1 = [[RMResource alloc] initWithFilePath:[self fullPathForFile:@"project/Packages/package1.sbpack/foo.png"]];
RMResource *res2 = [[RMResource alloc] initWithFilePath:[self fullPathForFile:@"project/Packages/package1.sbpack/baa.png"]];
RMResource *res3 = [[RMResource alloc] initWithFilePath:[self fullPathForFile:@"project/Packages/package1.sbpack/123.png"]];

ResourceManager *resourceManager = [ResourceManager sharedManager];
[resourceManager setActiveDirectoriesWithFullReset:@[
Expand All @@ -468,18 +469,47 @@ - (void)testMarkAsDirty
[_projectSettings addResourcePath:@"project/Packages/package1.sbpack" error:nil];
[_projectSettings clearAllDirtyMarkers];

XCTAssertFalse([_projectSettings isDirtyResource:resource]);

[_projectSettings setValue:@(1) forResource:resource andKey:@"format_ios"];
// Test clear all dirty markers
[_projectSettings markAsDirtyResource:res1];
[_projectSettings markAsDirtyResource:res2];
[_projectSettings markAsDirtyResource:res3];

XCTAssertTrue([_projectSettings isDirtyResource:resource]);
[_projectSettings clearAllDirtyMarkers];

XCTAssertFalse([_projectSettings isDirtyResource:res1]);
XCTAssertFalse([_projectSettings isDirtyResource:res2]);
XCTAssertFalse([_projectSettings isDirtyResource:res3]);


// Setting a new value should mark the resource as dirty
XCTAssertFalse([_projectSettings isDirtyResource:res1]);

[_projectSettings setProperty:@(1) forResource:res1 andKey:@"format_ios"];

XCTAssertTrue([_projectSettings isDirtyResource:res1]);


// Removing a property should mark the resource as dirty
[_projectSettings clearAllDirtyMarkers];

[_projectSettings removeObjectForResource:resource andKey:@"format_ios"];
[_projectSettings removePropertyForResource:res1 andKey:@"format_ios"];

XCTAssertTrue([_projectSettings isDirtyResource:res1]);


// Setting same value twice should not mark resource as dirty
[_projectSettings clearAllDirtyMarkers];

[_projectSettings setProperty:@(1) forResource:res1 andKey:@"format_ios"];

[_projectSettings clearAllDirtyMarkers];

XCTAssertFalse([_projectSettings isDirtyResource:res1]);

[_projectSettings setProperty:@(1) forResource:res1 andKey:@"format_ios"];

XCTAssertTrue([_projectSettings isDirtyResource:resource]);
XCTAssertFalse([_projectSettings isDirtyResource:res1]);
}


Expand Down
2 changes: 1 addition & 1 deletion SpriteBuilder/ccBuilder/CCBDirectoryPublisher.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ - (BOOL)publishDirectory:(NSString *)publishDirectory subPath:(NSString *)subPat
NSString *outDir = [_outputDir stringByAppendingPathComponent:subPath];
NSFileManager *fileManager = [NSFileManager defaultManager];

BOOL isGeneratedSpriteSheet = [[_projectSettings valueForRelPath:subPath andKey:@"isSmartSpriteSheet"] boolValue];
BOOL isGeneratedSpriteSheet = [[_projectSettings propertyForRelPath:subPath andKey:@"isSmartSpriteSheet"] boolValue];
if (!isGeneratedSpriteSheet)
{
[_queue addOperationWithBlock:^
Expand Down
4 changes: 2 additions & 2 deletions SpriteBuilder/ccBuilder/ProjectSettings+Convenience.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ - (NSInteger)soundQualityForRelPath:(NSString *)relPath osType:(CCBPublisherOSTy
? @"format_ios_sound_quality"
: @"format_android_sound_quality";

int result = [[self valueForRelPath:relPath andKey:key] intValue];
int result = [[self propertyForRelPath:relPath andKey:key] intValue];
if (!result)
{
return NSNotFound;
Expand Down Expand Up @@ -51,7 +51,7 @@ - (int)soundFormatForRelPath:(NSString *)relPath osType:(CCBPublisherOSType)osTy
return 0;
}

int formatRaw = [[self valueForRelPath:relPath andKey:key] intValue];
int formatRaw = [[self propertyForRelPath:relPath andKey:key] intValue];

NSNumber *result = [map objectForKey:@(formatRaw)];

Expand Down
68 changes: 13 additions & 55 deletions SpriteBuilder/ccBuilder/ProjectSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,48 +50,6 @@ typedef NS_ENUM(int8_t, CCBTargetEngine)
@class CCBWarnings;

@interface ProjectSettings : NSObject
{
NSString* projectPath;

NSString* publishDirectory;
NSString* publishDirectoryAndroid;

BOOL publishEnabledIOS;
BOOL publishEnabledAndroid;

BOOL publishResolution_ios_phone;
BOOL publishResolution_ios_phonehd;
BOOL publishResolution_ios_tablet;
BOOL publishResolution_ios_tablethd;
BOOL publishResolution_android_phone;
BOOL publishResolution_android_phonehd;
BOOL publishResolution_android_tablet;
BOOL publishResolution_android_tablethd;

int publishAudioQuality_ios;
int publishAudioQuality_android;

BOOL isSafariExist;
BOOL isChromeExist;
BOOL isFirefoxExist;

BOOL publishToZipFile;
BOOL onlyPublishCCBs;
NSString* exporter;
NSMutableArray* availableExporters;
BOOL deviceOrientationPortrait;
BOOL deviceOrientationUpsideDown;
BOOL deviceOrientationLandscapeLeft;
BOOL deviceOrientationLandscapeRight;
int resourceAutoScaleFactor;

NSString* versionStr;
BOOL needRepublish;

CCBWarnings* lastWarnings;

BOOL storing;
}

// Full path to the project file, e.g. /foo/baa.spritebuilder/baa.ccbproj
@property (nonatomic, copy) NSString* projectPath;
Expand Down Expand Up @@ -120,10 +78,6 @@ typedef NS_ENUM(int8_t, CCBTargetEngine)
@property (nonatomic,assign) int publishAudioQuality_ios;
@property (nonatomic,assign) int publishAudioQuality_android;

@property (nonatomic,assign) BOOL isSafariExist;
@property (nonatomic,assign) BOOL isChromeExist;
@property (nonatomic,assign) BOOL isFirefoxExist;

@property (nonatomic, assign) BOOL publishToZipFile;
@property (nonatomic, assign) BOOL onlyPublishCCBs;
@property (nonatomic, readonly) NSArray* absoluteResourcePaths;
Expand Down Expand Up @@ -161,28 +115,32 @@ typedef NS_ENUM(int8_t, CCBTargetEngine)
- (BOOL) store;
- (id) serialize;


// *** Smart Sprite Sheets ***
- (void) makeSmartSpriteSheet:(RMResource*) res;
- (void) removeSmartSpriteSheet:(RMResource*) res;
- (NSArray*) smartSpriteSheetDirectories;

// *** Setting and reading file properties ***
- (void) setValue:(id) val forResource:(RMResource*) res andKey:(id) key;
- (void) setValue:(id)val forRelPath:(NSString *)relPath andKey:(id)key;
- (id) valueForResource:(RMResource*) res andKey:(id) key;
- (id) valueForRelPath:(NSString*) relPath andKey:(id) key;
- (void) removeObjectForResource:(RMResource*) res andKey:(id) key;
- (void) removeObjectForRelPath:(NSString*) relPath andKey:(id) key;
- (BOOL) isDirtyResource:(RMResource*) res;
- (BOOL) isDirtyRelPath:(NSString*) relPath;
// Will mark the resource as dirty if old value is not equal to new value
- (void)setProperty:(id)newValue forResource:(RMResource *)res andKey:(id <NSCopying>)key;
// Will mark the resource as dirty if old value is not equal to new value
- (void)setProperty:(id)newValue forRelPath:(NSString *)relPath andKey:(id <NSCopying>)key;
- (id)propertyForResource:(RMResource *)res andKey:(id <NSCopying>)key;
- (id)propertyForRelPath:(NSString *)relPath andKey:(id <NSCopying>)key;
// Will mark the resource as dirty
- (void)removePropertyForResource:(RMResource *)res andKey:(id <NSCopying>)key;
// Will mark the resource as dirty
- (void)removePropertyForRelPath:(NSString *)relPath andKey:(id <NSCopying>)key;

// *** Dirty markers ***
- (BOOL) isDirtyResource:(RMResource*) res;
- (BOOL) isDirtyRelPath:(NSString*) relPath;
- (void) markAsDirtyResource:(RMResource*) res;
- (void) markAsDirtyRelPath:(NSString*) relPath;
- (void) clearAllDirtyMarkers;
- (void)flagFilesDirtyWithWarnings:(CCBWarnings *)warnings;


// *** Handling moved and deleted resources ***
- (void) removedResourceAt:(NSString*) relPath;
- (void) movedResourceFrom:(NSString*) relPathOld to:(NSString*) relPathNew;
Expand Down
Loading

0 comments on commit 0194424

Please sign in to comment.