diff --git a/src/Catty/Defines/LanguageTranslationDefines.h b/src/Catty/Defines/LanguageTranslationDefines.h index 54e44ce2a7..5b8d96ad86 100644 --- a/src/Catty/Defines/LanguageTranslationDefines.h +++ b/src/Catty/Defines/LanguageTranslationDefines.h @@ -168,6 +168,7 @@ #define kLocalizedEnableCondition NSLocalizedString(@"Enable condition", nil) #define kLocalizedEditFormula NSLocalizedString(@"Edit formula", nil) #define kLocalizedMoveBrick NSLocalizedString(@"Move brick", nil) +#define kLocalizedMoveScript NSLocalizedString(@"Move script", nil) #define kLocalizedDeleteSounds NSLocalizedString(@"Delete sounds", nil) #define kLocalizedMoveSounds NSLocalizedString(@"Move sounds",nil) #define kLocalizedHideDetails NSLocalizedString(@"Hide details", nil) diff --git a/src/Catty/Defines/LanguageTranslationDefinesSwift.swift b/src/Catty/Defines/LanguageTranslationDefinesSwift.swift index 049baf9283..efdc4b8980 100644 --- a/src/Catty/Defines/LanguageTranslationDefinesSwift.swift +++ b/src/Catty/Defines/LanguageTranslationDefinesSwift.swift @@ -168,6 +168,7 @@ let kLocalizedDisableCondition = NSLocalizedString("Disable condition", comment: let kLocalizedEnableCondition = NSLocalizedString("Enable condition", comment: "") let kLocalizedEditFormula = NSLocalizedString("Edit formula", comment: "") let kLocalizedMoveBrick = NSLocalizedString("Move brick", comment: "") +let kLocalizedMoveScript = NSLocalizedString("Move script", comment: "") let kLocalizedDeleteSounds = NSLocalizedString("Delete sounds", comment: "") let kLocalizedMoveSounds = NSLocalizedString("Move sounds", comment: "") let kLocalizedHideDetails = NSLocalizedString("Hide details", comment: "") diff --git a/src/Catty/Resources/Localization/en.lproj/Localizable.strings b/src/Catty/Resources/Localization/en.lproj/Localizable.strings index 1bc22f70f7..0510e03509 100644 --- a/src/Catty/Resources/Localization/en.lproj/Localizable.strings +++ b/src/Catty/Resources/Localization/en.lproj/Localizable.strings @@ -1303,6 +1303,9 @@ /* No comment provided by engineer. */ "Move Phiro motor forward" = "Move Phiro motor forward"; +/* No comment provided by engineer. */ +"Move script" = "Move script"; + /* No comment provided by engineer. */ "Move sounds" = "Move sounds"; diff --git a/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.h b/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.h index 7fae6c9eb7..7302f97fb7 100644 --- a/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.h +++ b/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.h @@ -27,9 +27,8 @@ @interface BrickMoveManager : NSObject +(id)sharedInstance; - - (BOOL)collectionView:(UICollectionView*)collectionView itemAtIndexPath:(NSIndexPath*)fromIndexPath - canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object; + canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object isBrick:(BOOL)isBrick; -(void)reset; -(void)getReadyForNewBrickMovement; diff --git a/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.m b/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.m index 296f61a019..8a5ee9a0d1 100644 --- a/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.m +++ b/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.m @@ -53,57 +53,61 @@ + (id)sharedInstance { - (BOOL)collectionView:(UICollectionView*)collectionView itemAtIndexPath:(NSIndexPath*)fromIndexPath - canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object + canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object isBrick:(BOOL)isBrick { - Script *fromScript = [object.scriptList objectAtIndex:fromIndexPath.section]; - Brick *fromBrick; - if (fromIndexPath.item == 0) { - fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item]; - } else{ - fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item - 1]; - } - - if (toIndexPath.item != 0) { - Script *script; - if (self.moveToOtherScript) { - script = [object.scriptList objectAtIndex:toIndexPath.section]; - }else{ - script = [object.scriptList objectAtIndex:fromIndexPath.section]; - } - Brick *toBrick; - if (script.brickList.count > toIndexPath.item - 1) { - toBrick = [script.brickList objectAtIndex:toIndexPath.item - 1]; - } else { - return NO; + if (isBrick) { + Script *fromScript = [object.scriptList objectAtIndex:fromIndexPath.section]; + Brick *fromBrick; + if (fromIndexPath.item == 0) { + fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item]; + } else{ + fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item - 1]; } - - if ([toBrick isKindOfClass:[LoopEndBrick class]]) { - LoopEndBrick* loopEndBrick = (LoopEndBrick*) toBrick; - if ([loopEndBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) { - return [self handleMovementToForeverBrick:loopEndBrick fromIndexPath:fromIndexPath toIndexPath:toIndexPath fromBrick:fromBrick andScript:script]; + + if (toIndexPath.item != 0) { + Script *script; + if (self.moveToOtherScript) { + script = [object.scriptList objectAtIndex:toIndexPath.section]; + }else{ + script = [object.scriptList objectAtIndex:fromIndexPath.section]; } - } - if ([fromBrick isKindOfClass:[LoopBeginBrick class]] || [fromBrick isKindOfClass:[LoopEndBrick class]] || [fromBrick isKindOfClass:[IfLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfThenLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfLogicElseBrick class]] || [fromBrick isKindOfClass:[IfLogicEndBrick class]] || [fromBrick isKindOfClass:[IfThenLogicEndBrick class]]){ - return [self checkNestedBrickToIndex:toIndexPath FromIndex:fromIndexPath andFromBrick:fromBrick andObject:object]; - } else { - //From Below - if (toIndexPath.item < fromIndexPath.item) { - if ([toBrick isKindOfClass:[IfLogicElseBrick class]]||[toBrick isKindOfClass:[IfLogicEndBrick class]]||[toBrick isKindOfClass:[LoopEndBrick class]]) { //check if repeat?! - Brick *checkBeforeEndBrick = [script.brickList objectAtIndex:toIndexPath.item - 2]; - if ([checkBeforeEndBrick isKindOfClass:[LoopEndBrick class]]) { - LoopEndBrick *endBrick = (LoopEndBrick*)checkBeforeEndBrick; - if ([endBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) { - return NO; + Brick *toBrick; + if (script.brickList.count > toIndexPath.item - 1) { + toBrick = [script.brickList objectAtIndex:toIndexPath.item - 1]; + } else { + return NO; + } + + if ([toBrick isKindOfClass:[LoopEndBrick class]]) { + LoopEndBrick* loopEndBrick = (LoopEndBrick*) toBrick; + if ([loopEndBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) { + return [self handleMovementToForeverBrick:loopEndBrick fromIndexPath:fromIndexPath toIndexPath:toIndexPath fromBrick:fromBrick andScript:script]; + } + } + if ([fromBrick isKindOfClass:[LoopBeginBrick class]] || [fromBrick isKindOfClass:[LoopEndBrick class]] || [fromBrick isKindOfClass:[IfLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfThenLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfLogicElseBrick class]] || [fromBrick isKindOfClass:[IfLogicEndBrick class]] || [fromBrick isKindOfClass:[IfThenLogicEndBrick class]]){ + return [self checkNestedBrickToIndex:toIndexPath FromIndex:fromIndexPath andFromBrick:fromBrick andObject:object]; + } else { + //From Below + if (toIndexPath.item < fromIndexPath.item) { + if ([toBrick isKindOfClass:[IfLogicElseBrick class]]||[toBrick isKindOfClass:[IfLogicEndBrick class]]||[toBrick isKindOfClass:[LoopEndBrick class]]) { //check if repeat?! + Brick *checkBeforeEndBrick = [script.brickList objectAtIndex:toIndexPath.item - 2]; + if ([checkBeforeEndBrick isKindOfClass:[LoopEndBrick class]]) { + LoopEndBrick *endBrick = (LoopEndBrick*)checkBeforeEndBrick; + if ([endBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) { + return NO; + } } } + } + return (toIndexPath.item != 0); } - - return (toIndexPath.item != 0); + } else { + return [self handleMovementToOtherScriptwithIndexPath:toIndexPath fromBrick:fromBrick andObject:object]; } } else { - return [self handleMovementToOtherScriptwithIndexPath:toIndexPath fromBrick:fromBrick andObject:object]; + return fromIndexPath.section != toIndexPath.section && toIndexPath.item == 0; } } diff --git a/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/ScriptCollectionViewController.m b/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/ScriptCollectionViewController.m index f730d1b791..c0f7ee67a6 100644 --- a/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/ScriptCollectionViewController.m +++ b/src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/ScriptCollectionViewController.m @@ -75,16 +75,17 @@ @interface ScriptCollectionViewController() +UICollectionViewDataSource, +BrickCellDelegate, +iOSComboboxDelegate, +BrickCellDataDelegate, +UIGestureRecognizerDelegate> //@property (nonatomic, strong) NSMutableArray *selectedIndexPositions; // refactor @property (nonatomic, strong) NSIndexPath *variableIndexPath; @property (nonatomic, assign) BOOL isEditingBrickMode; @property (nonatomic, assign) BOOL batchUpdateMutex; +@property (nonatomic, assign) BOOL isBrickMove; @property (nonatomic, strong) FormulaManager *formulaManager; @end @@ -244,7 +245,7 @@ - (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPat : (brick.isDisabled ? kLocalizedEnableBrick : kLocalizedDisableBrick)); actionSheet = [[AlertControllerBuilder actionSheetWithTitle:kLocalizedEditBrick] - addCancelActionWithTitle:kLocalizedCancel handler:nil]; + addCancelActionWithTitle:kLocalizedCancel handler:nil]; [actionSheet addDestructiveActionWithTitle:destructiveTitle handler:^{ [self removeBrickOrScript:scriptOrBrick atIndexPath:indexPath]; @@ -284,38 +285,46 @@ - (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPat Script *script = (Script*)scriptOrBrick; NSString *disableTitle = script.isDisabled ? kLocalizedEnableScript : kLocalizedDisableScript; actionSheet = [[[[AlertControllerBuilder actionSheetWithTitle:kLocalizedEditScript] - addCancelActionWithTitle:kLocalizedCancel handler:nil] - addDestructiveActionWithTitle:kLocalizedDeleteScript handler:^{ - NSInteger numberOfBricksInSection = [self.collectionView numberOfItemsInSection:indexPath.section]; - if (numberOfBricksInSection > 1) { - [[[[[AlertControllerBuilder alertWithTitle:kLocalizedDeleteThisScript - message:kLocalizedThisActionCannotBeUndone] - addCancelActionWithTitle:kLocalizedCancel handler:nil] - addDefaultActionWithTitle:kLocalizedYes handler:^{ - [self removeBrickOrScript:scriptOrBrick atIndexPath:indexPath]; - }] build] - showWithController:self]; - } else { - [self removeBrickOrScript:scriptOrBrick atIndexPath:indexPath]; - } - }] - addDefaultActionWithTitle: disableTitle handler:^{ + addCancelActionWithTitle:kLocalizedCancel handler:nil] + addDestructiveActionWithTitle:kLocalizedDeleteScript handler:^{ + NSInteger numberOfBricksInSection = [self.collectionView numberOfItemsInSection:indexPath.section]; + if (numberOfBricksInSection > 1) { + [[[[[AlertControllerBuilder alertWithTitle:kLocalizedDeleteThisScript + message:kLocalizedThisActionCannotBeUndone] + addCancelActionWithTitle:kLocalizedCancel handler:nil] + addDefaultActionWithTitle:kLocalizedYes handler:^{ + [self removeBrickOrScript:scriptOrBrick atIndexPath:indexPath]; + }] build] + showWithController:self]; + } else { + [self removeBrickOrScript:scriptOrBrick atIndexPath:indexPath]; + } + }] + addDefaultActionWithTitle: disableTitle handler:^{ [self disableOrEnableWithScript:script]; [self reloadData]; [self.object.scene.project saveToDiskWithNotification:YES]; }]; + + [actionSheet addDefaultActionWithTitle:kLocalizedMoveScript handler:^{ + script.animateInsertBrick = YES; + script.animateMoveBrick = YES; + [[BrickInsertManager sharedInstance] setBrickMoveMode:YES]; + [self turnOnInsertingBrickMode]; + [self reloadData]; + }]; } [[[[actionSheet build] - viewDidAppear:^(UIView *view) { - const float kActionSheetBrickCellMarginBottom = 15.0f; - [self disableUserInteractionAndHighlight:brickCell withMarginBottom:view.frame.size.height + kActionSheetBrickCellMarginBottom]; - }] - viewWillDisappear:^{ - if (self.isEditingBrickMode) { - [self enableUserInteractionAndResetHighlight]; - } - }] + viewDidAppear:^(UIView *view) { + const float kActionSheetBrickCellMarginBottom = 15.0f; + [self disableUserInteractionAndHighlight:brickCell withMarginBottom:view.frame.size.height + kActionSheetBrickCellMarginBottom]; + }] + viewWillDisappear:^{ + if (self.isEditingBrickMode) { + [self enableUserInteractionAndResetHighlight]; + } + }] showWithController:self]; } @@ -335,12 +344,12 @@ - (void)deleteAlertView if ([[[BrickSelectionManager sharedInstance] selectedIndexPaths] count] < 4) { title = ([brick isIfLogicBrick] ? kLocalizedDeleteThisCondition - : ([brick isLoopBrick]) ? kLocalizedDeleteThisLoop : kLocalizedDeleteTheseBricks); + : ([brick isLoopBrick]) ? kLocalizedDeleteThisLoop : kLocalizedDeleteTheseBricks); } else { title = ([brick isIfLogicBrick] ? kLocalizedDeleteTheseConditions - : ([brick isLoopBrick]) ? kLocalizedDeleteTheseLoops : kLocalizedDeleteTheseBricks); + : ([brick isLoopBrick]) ? kLocalizedDeleteTheseLoops : kLocalizedDeleteTheseBricks); } } else @@ -365,11 +374,11 @@ - (void)deleteAlertView { NSString *alertTitle = title; [[[[[AlertControllerBuilder alertWithTitle:alertTitle message:kLocalizedThisActionCannotBeUndone] - addCancelActionWithTitle:kLocalizedCancel handler:nil] - addDefaultActionWithTitle:kLocalizedYes handler:^{ - [self deleteSelectedBricks]; - self.allBricksSelected = NO; - }] build] + addCancelActionWithTitle:kLocalizedCancel handler:nil] + addDefaultActionWithTitle:kLocalizedYes handler:^{ + [self deleteSelectedBricks]; + self.allBricksSelected = NO; + }] build] showWithController:self]; } } @@ -383,42 +392,42 @@ - (void)collectionView:(UICollectionView*)collectionView Script *script = [self.object.scriptList objectAtIndex:fromIndexPath.section]; [self.object.scriptList removeObjectAtIndex:fromIndexPath.section]; [self.object.scriptList insertObject:script atIndex:toIndexPath.section]; - return; - } - if (fromIndexPath.section == toIndexPath.section) { + } else if (fromIndexPath.section == toIndexPath.section) { Script *script = [self.object.scriptList objectAtIndex:fromIndexPath.section]; - if (fromIndexPath.item > 0) { - Brick *fromBrick = [script.brickList objectAtIndex:fromIndexPath.item - 1]; - [script.brickList removeObjectAtIndex:fromIndexPath.item - 1]; - if (toIndexPath.item > 0) { - [script.brickList insertObject:fromBrick atIndex:toIndexPath.item - 1]; - } else { - [script.brickList insertObject:fromBrick atIndex:toIndexPath.item+1]; - } - + Brick *fromBrick = [script.brickList objectAtIndex:fromIndexPath.item - 1]; + [script.brickList removeObjectAtIndex:fromIndexPath.item - 1]; + if (toIndexPath.item > 0) { + [script.brickList insertObject:fromBrick atIndex:toIndexPath.item - 1]; + } else { + [script.brickList insertObject:fromBrick atIndex:toIndexPath.item+1]; } } else { Script *toScript = [self.object.scriptList objectAtIndex:toIndexPath.section]; Script *fromScript = [self.object.scriptList objectAtIndex:fromIndexPath.section]; - Brick *fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item - 1]; - fromBrick.script = toScript; - if ([fromScript.brickList count] == 1) { - [fromScript.brickList removeAllObjects]; + if ([fromScript.brickList count] > 0) { + Brick *fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item - 1]; + fromBrick.script = toScript; + if ([fromScript.brickList count] == 1) { + [fromScript.brickList removeAllObjects]; + } else { + [fromScript.brickList removeObjectAtIndex:fromIndexPath.item - 1]; + } + if ([toScript.brickList count] == 0) { + [toScript.brickList insertObject:fromBrick atIndex:toIndexPath.item]; + } else{ + [toScript.brickList insertObject:fromBrick atIndex:toIndexPath.item - 1]; + } } else { - [fromScript.brickList removeObjectAtIndex:fromIndexPath.item - 1]; - } - if ([toScript.brickList count] == 0) { - [toScript.brickList insertObject:fromBrick atIndex:toIndexPath.item]; - }else{ - [toScript.brickList insertObject:fromBrick atIndex:toIndexPath.item - 1]; + self.object.scriptList[toIndexPath.section] = fromScript; + self.object.scriptList[fromIndexPath.section] = toScript; } } } - (void)collectionView:(UICollectionView*)collectionView itemAtIndexPath:(NSIndexPath*)fromIndexPath - didMoveToIndexPath:(NSIndexPath*)toIndexPath + didMoveToIndexPath:(NSIndexPath*)toIndexPath { [[BrickMoveManager sharedInstance] reset]; } @@ -433,22 +442,29 @@ - (void)collectionView:(UICollectionView*)collectionView if ([[BrickInsertManager sharedInstance] isBrickInsertionMode]) { Script *script = [self.object.scriptList objectAtIndex:indexPath.section]; - if (indexPath.item != 0) { - Brick *brick; - if (script.brickList.count >= 1) { - brick = [script.brickList objectAtIndex:indexPath.item - 1]; + if ([script.brickList count] > 0) { + if (indexPath.item != 0) { + Brick *brick; + if (script.brickList.count >= 1) { + brick = [script.brickList objectAtIndex:indexPath.item - 1]; + }else{ + // check i ned warum wenn 0 elemente drinnen sein nehmen wir sich einen raus ? + brick = [script.brickList objectAtIndex:indexPath.item]; + } + if (brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick) { + [[BrickInsertManager sharedInstance] insertBrick:brick IndexPath:indexPath andObject:self.object]; + }else if(!brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick){ + return; + }else { + brick.animateInsertBrick = NO; + brick.animateMoveBrick = NO; + } }else{ - brick = [script.brickList objectAtIndex:indexPath.item]; + script.animateInsertBrick = NO; } - if (brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick) { - [[BrickInsertManager sharedInstance] insertBrick:brick IndexPath:indexPath andObject:self.object]; - }else if(!brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick){ - return; - }else { - brick.animateInsertBrick = NO; - brick.animateMoveBrick = NO; - } - }else{ + } else { + script.animateInsertBrick = NO; + script.animateMoveBrick = NO; script.animateInsertBrick = NO; } [self.object.scene.project saveToDiskWithNotification:NO]; @@ -473,8 +489,12 @@ - (BOOL)collectionView:(UICollectionView*)collectionView itemAtIndexPath:(NSInde if ([[BrickInsertManager sharedInstance] isBrickInsertionMode] && ![[BrickInsertManager sharedInstance] isBrickMoveMode]) { return [[BrickInsertManager sharedInstance] collectionView:self.collectionView itemAtIndexPath:fromIndexPath canInsertToIndexPath:toIndexPath andObject:self.object]; } - - return [[BrickMoveManager sharedInstance] collectionView:self.collectionView itemAtIndexPath:fromIndexPath canMoveToIndexPath:toIndexPath andObject:self.object]; + BrickCell *brickCell = (BrickCell*)[collectionView cellForItemAtIndexPath:fromIndexPath]; + if (brickCell) { + id scriptOrBrick = brickCell.scriptOrBrick; + self.isBrickMove = [scriptOrBrick isKindOfClass:[Brick class]]; + } + return [[BrickMoveManager sharedInstance] collectionView:self.collectionView itemAtIndexPath:fromIndexPath canMoveToIndexPath:toIndexPath andObject:self.object isBrick: self.isBrickMove]; } @@ -487,9 +507,9 @@ - (BOOL)collectionView:(UICollectionView*)collectionView canMoveItemAtIndexPath: if (indexPath.item != 0) { brick = [script.brickList objectAtIndex:indexPath.item - 1]; } - return (script.animateInsertBrick || brick.animateMoveBrick || brick.animateInsertBrick); + return (script.animateMoveBrick || script.animateInsertBrick || brick.animateMoveBrick || brick.animateInsertBrick); } - BOOL editable = ((self.isEditing || indexPath.item == 0) ? NO : YES); + BOOL editable = (self.isEditing ? NO : YES); return ((editable || [[BrickInsertManager sharedInstance] isBrickInsertionMode]) ? YES : editable); } @@ -558,7 +578,7 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView } } }else{ - brickCell.selectButton.selected = NO; + brickCell.selectButton.selected = NO; } brickCell.enabled = (! self.isEditing); if ([[BrickInsertManager sharedInstance] isBrickInsertionMode]) { @@ -606,7 +626,7 @@ - (void)brickCategoryViewController:(BrickCategoryViewController*)brickCategoryV [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:(self.object.scriptList.count - 1)] atScrollPosition:UICollectionViewScrollPositionBottom animated:YES]; - + manager.isInsertingScript = YES; if (self.object.scriptList.count == 1) { [self.object.scene.project saveToDiskWithNotification:YES]; @@ -655,7 +675,7 @@ - (void)brickCategoryViewController:(BrickCategoryViewController*)brickCategoryV if (hasForeverLoop) { [targetScript.brickList insertObject:brick atIndex:index]; } else { - [targetScript.brickList addObject:brick]; + [targetScript.brickList addObject:brick]; } }else{ [targetScript.brickList insertObject:brick atIndex:insertionIndex]; @@ -797,7 +817,7 @@ -(void)turnOnInsertingBrickMode layout.longPressGestureRecognizer.minimumPressDuration = 0.1; [self.navigationItem setHidesBackButton:YES animated:NO]; dispatch_async(dispatch_get_main_queue(), ^{ - self.navigationItem.rightBarButtonItem.enabled = NO; + self.navigationItem.rightBarButtonItem.enabled = NO; }); } @@ -963,201 +983,201 @@ - (void)updateBrickCellData:(id)brickCellData withValue:( [lookBrick setLook:[Util lookWithName:(NSString*)value forObject:self.object] forLineNumber:line andParameterNumber:parameter]; } } else - if ([brickCellData isKindOfClass:[BrickCellBackgroundData class]] && [brick conformsToProtocol:@protocol(BrickLookProtocol)]) { - Brick *lookBrick = (Brick*)brick; - SpriteObject *backgroundObject = self.object.scene.objects.firstObject; - if([(NSString*)value isEqualToString:kLocalizedNewElement]) { - LooksTableViewController *ltvc = [self.storyboard instantiateViewControllerWithIdentifier:kLooksTableViewControllerIdentifier]; - [ltvc setObject:backgroundObject]; - ltvc.showAddLookActionSheetAtStartForScriptEditor = YES; - ltvc.showAddLookActionSheetAtStartForObject = NO; - ltvc.afterSafeBlock = ^(Look* look) { - [lookBrick setLook:look forLineNumber:line andParameterNumber:parameter]; - [self.navigationController popViewControllerAnimated:YES]; - [self enableUserInteractionAndResetHighlight]; - }; - [self.navigationController pushViewController:ltvc animated:YES]; - return; - } else { - [lookBrick setLook:[Util lookWithName:(NSString*)value forObject:backgroundObject] forLineNumber:line andParameterNumber:parameter]; - } - } else - if ([brickCellData isKindOfClass:[BrickCellSoundData class]] && [brick conformsToProtocol:@protocol(BrickSoundProtocol)]) { - Brick *soundBrick = (Brick*)brick; - if([(NSString*)value isEqualToString:kLocalizedNewElement]) { - SoundsTableViewController *ltvc = [self.storyboard instantiateViewControllerWithIdentifier:kSoundsTableViewControllerIdentifier]; - [ltvc setObject:self.object]; - ltvc.showAddSoundActionSheetAtStart = YES; - ltvc.afterSafeBlock = ^(Sound* sound) { - [soundBrick setSound:sound forLineNumber:line andParameterNumber:parameter]; - [self.navigationController popViewControllerAnimated:YES]; - [self enableUserInteractionAndResetHighlight]; - }; - [self.navigationController pushViewController:ltvc animated:YES]; - return; - } else { - [soundBrick setSound:[Util soundWithName:(NSString*)value forObject:self.object] forLineNumber:line andParameterNumber:parameter]; - } - } else - if ([brickCellData isKindOfClass:[BrickCellObjectData class]] && [brick conformsToProtocol:@protocol(BrickObjectProtocol)]) { - Brick *objectBrick = (Brick*)brick; - if([(NSString*)value isEqualToString:kLocalizedNewElement]) { - SceneTableViewController *ptvc = [self.storyboard instantiateViewControllerWithIdentifier:kSceneTableViewControllerIdentifier]; - [ptvc setScene:self.object.scene]; - ptvc.showAddObjectActionSheetAtStart = YES; - ptvc.afterSafeBlock = ^(SpriteObject* object) { - [objectBrick setObject:object forLineNumber:line andParameterNumber:parameter]; - [self.navigationController popToViewController:self animated:YES]; - [self enableUserInteractionAndResetHighlight]; - }; - [self.navigationController pushViewController:ptvc animated:YES]; - return; - } else { - [objectBrick setObject:[Util objectWithName:(NSString*)value forScene:self.object.scene] forLineNumber:line andParameterNumber:parameter]; - } - } else - if ([brickCellData isKindOfClass:[BrickCellFormulaData class]] && [brick conformsToProtocol:@protocol(BrickFormulaProtocol)]) { - [(Brick*)brick setFormula:(Formula*)value forLineNumber:line andParameterNumber:parameter]; - [self.object.scene.project saveToDiskWithNotification:NO]; - [self reloadData]; - return; - } else - if ([brickCellData isKindOfClass:[BrickCellTextData class]] && [brick conformsToProtocol:@protocol(BrickTextProtocol)]) { - [(Brick*)brick setText:(NSString*)value forLineNumber:line andParameterNumber:parameter]; - } else - if ([brickCellData isKindOfClass:[BrickCellStaticChoiceData class]] && [brick conformsToProtocol:@protocol(BrickStaticChoiceProtocol)]) { - [(Brick*)brick setChoice:(NSString*)value forLineNumber:line andParameterNumber:parameter]; - } else - if ([brickCellData isKindOfClass:[BrickCellMessageData class]] && [brick conformsToProtocol:@protocol(BrickMessageProtocol)]) { - [self.object.scene.project.allBroadcastMessages addObject:value]; - Brick *messageBrick = (Brick*)brick; - if([(NSString*)value isEqualToString:kLocalizedNewElement]) { - [Util askUserForUniqueNameAndPerformAction:@selector(addMessageWithName:andCompletion:) - target:self - cancelAction:@selector(enableUserInteractionAndResetHighlight) - withObject:(id) ^(NSString* message){ - [messageBrick setMessage:message forLineNumber:line andParameterNumber:parameter]; - } - promptTitle:kLocalizedNewMessage - promptMessage:[NSString stringWithFormat:@"%@:", kLocalizedMessage] - promptValue:nil - promptPlaceholder:kLocalizedEnterYourMessageHere - minInputLength:kMinNumOfMessageNameCharacters - maxInputLength:kMaxNumOfMessageNameCharacters - invalidInputAlertMessage:kLocalizedMessageAlreadyExistsDescription - existingNames:[Util allMessagesForProject:self.object.scene.project].array]; - [self enableUserInteractionAndResetHighlight]; - return; - } else { - [messageBrick setMessage:(NSString*)value forLineNumber:line andParameterNumber:parameter]; - } - } else - if ([brickCellData isKindOfClass:[BrickCellVariableData class]] && [brick conformsToProtocol:@protocol(BrickVariableProtocol)]) { - if([(NSString*)value isEqualToString:kLocalizedNewElement]) { - CBAssert([brickCellData.brickCell.scriptOrBrick isKindOfClass:[Brick class]]); - - NSIndexPath *path = [self.collectionView indexPathForCell:(UICollectionViewCell*)brickCellData.brickCell]; - - CreateVariableOrListViewController *cvlvc = [[CreateVariableOrListViewController alloc] initWithSpriteObject:self.object shouldCreateList:NO hideCreateList:YES addedCompletion:^(NSString * _Nonnull variableName) { - - UserVariable *var = [UserDataContainer objectOrProjectVariableForObject:self.object andName:(NSString*)variableName]; - - self.variableIndexPath = path; - - BrickCell *brickCell = (BrickCell*)[self.collectionView cellForItemAtIndexPath:self.variableIndexPath]; - Brick *brick = (Brick*)brickCell.scriptOrBrick; - Brick *variableBrick; - - if ([brick conformsToProtocol:@protocol(BrickVariableProtocol)]) { - variableBrick = (Brick*)brick; - } - - if (var) { - [variableBrick setVariable:var forLineNumber:self.variableIndexPath.row andParameterNumber:self.variableIndexPath.section]; - } - - [self enableUserInteractionAndResetHighlight]; - }]; - - - if (@available(iOS 13.0, *)) { - cvlvc.modalInPresentation = true; + if ([brickCellData isKindOfClass:[BrickCellBackgroundData class]] && [brick conformsToProtocol:@protocol(BrickLookProtocol)]) { + Brick *lookBrick = (Brick*)brick; + SpriteObject *backgroundObject = self.object.scene.objects.firstObject; + if([(NSString*)value isEqualToString:kLocalizedNewElement]) { + LooksTableViewController *ltvc = [self.storyboard instantiateViewControllerWithIdentifier:kLooksTableViewControllerIdentifier]; + [ltvc setObject:backgroundObject]; + ltvc.showAddLookActionSheetAtStartForScriptEditor = YES; + ltvc.showAddLookActionSheetAtStartForObject = NO; + ltvc.afterSafeBlock = ^(Look* look) { + [lookBrick setLook:look forLineNumber:line andParameterNumber:parameter]; + [self.navigationController popViewControllerAnimated:YES]; + [self enableUserInteractionAndResetHighlight]; + }; + [self.navigationController pushViewController:ltvc animated:YES]; + return; } else { - cvlvc.modalPresentationStyle = UIModalPresentationFullScreen; + [lookBrick setLook:[Util lookWithName:(NSString*)value forObject:backgroundObject] forLineNumber:line andParameterNumber:parameter]; } - - UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:cvlvc]; - [self presentViewController:navController animated:YES completion:NULL]; - [self enableUserInteractionAndResetHighlight]; - return; - } else { - Brick *variableBrick = (Brick*)brick; - UserVariable *variable = [UserDataContainer objectOrProjectVariableForObject:self.object andName:(NSString*)value]; - if(variable) - [variableBrick setVariable:variable forLineNumber:line andParameterNumber:parameter]; - } - } else - if ([brickCellData isKindOfClass:[BrickCellListData class]] && [brick conformsToProtocol:@protocol(BrickListProtocol)]) { - if([(NSString*)value isEqualToString:kLocalizedNewElement]) { - CBAssert([brickCellData.brickCell.scriptOrBrick isKindOfClass:[Brick class]]); - - NSIndexPath *path = [self.collectionView indexPathForCell:(UICollectionViewCell*)brickCellData.brickCell]; - - CreateVariableOrListViewController *cvlvc = [[CreateVariableOrListViewController alloc] initWithSpriteObject:self.object shouldCreateList:YES hideCreateList:YES addedCompletion:^(NSString * _Nonnull listName) { - - UserList *list = [UserDataContainer objectOrProjectListForObject:self.object andName:(NSString*)listName]; - - self.variableIndexPath = path; - - BrickCell *brickCell = (BrickCell*)[self.collectionView cellForItemAtIndexPath:self.variableIndexPath]; - Brick *brick = (Brick*)brickCell.scriptOrBrick; - Brick *listBrick; - - if ([brick conformsToProtocol:@protocol(BrickListProtocol)]) { - listBrick = (Brick*)brick; - } - - if (list) { - [listBrick setList:list forLineNumber:self.variableIndexPath.row andParameterNumber:self.variableIndexPath.section]; + } else + if ([brickCellData isKindOfClass:[BrickCellSoundData class]] && [brick conformsToProtocol:@protocol(BrickSoundProtocol)]) { + Brick *soundBrick = (Brick*)brick; + if([(NSString*)value isEqualToString:kLocalizedNewElement]) { + SoundsTableViewController *ltvc = [self.storyboard instantiateViewControllerWithIdentifier:kSoundsTableViewControllerIdentifier]; + [ltvc setObject:self.object]; + ltvc.showAddSoundActionSheetAtStart = YES; + ltvc.afterSafeBlock = ^(Sound* sound) { + [soundBrick setSound:sound forLineNumber:line andParameterNumber:parameter]; + [self.navigationController popViewControllerAnimated:YES]; + [self enableUserInteractionAndResetHighlight]; + }; + [self.navigationController pushViewController:ltvc animated:YES]; + return; + } else { + [soundBrick setSound:[Util soundWithName:(NSString*)value forObject:self.object] forLineNumber:line andParameterNumber:parameter]; } + } else + if ([brickCellData isKindOfClass:[BrickCellObjectData class]] && [brick conformsToProtocol:@protocol(BrickObjectProtocol)]) { + Brick *objectBrick = (Brick*)brick; + if([(NSString*)value isEqualToString:kLocalizedNewElement]) { + SceneTableViewController *ptvc = [self.storyboard instantiateViewControllerWithIdentifier:kSceneTableViewControllerIdentifier]; + [ptvc setScene:self.object.scene]; + ptvc.showAddObjectActionSheetAtStart = YES; + ptvc.afterSafeBlock = ^(SpriteObject* object) { + [objectBrick setObject:object forLineNumber:line andParameterNumber:parameter]; + [self.navigationController popToViewController:self animated:YES]; + [self enableUserInteractionAndResetHighlight]; + }; + [self.navigationController pushViewController:ptvc animated:YES]; + return; + } else { + [objectBrick setObject:[Util objectWithName:(NSString*)value forScene:self.object.scene] forLineNumber:line andParameterNumber:parameter]; + } + } else + if ([brickCellData isKindOfClass:[BrickCellFormulaData class]] && [brick conformsToProtocol:@protocol(BrickFormulaProtocol)]) { + [(Brick*)brick setFormula:(Formula*)value forLineNumber:line andParameterNumber:parameter]; + [self.object.scene.project saveToDiskWithNotification:NO]; + [self reloadData]; + return; + } else + if ([brickCellData isKindOfClass:[BrickCellTextData class]] && [brick conformsToProtocol:@protocol(BrickTextProtocol)]) { + [(Brick*)brick setText:(NSString*)value forLineNumber:line andParameterNumber:parameter]; + } else + if ([brickCellData isKindOfClass:[BrickCellStaticChoiceData class]] && [brick conformsToProtocol:@protocol(BrickStaticChoiceProtocol)]) { + [(Brick*)brick setChoice:(NSString*)value forLineNumber:line andParameterNumber:parameter]; + } else + if ([brickCellData isKindOfClass:[BrickCellMessageData class]] && [brick conformsToProtocol:@protocol(BrickMessageProtocol)]) { + [self.object.scene.project.allBroadcastMessages addObject:value]; + Brick *messageBrick = (Brick*)brick; + if([(NSString*)value isEqualToString:kLocalizedNewElement]) { + [Util askUserForUniqueNameAndPerformAction:@selector(addMessageWithName:andCompletion:) + target:self + cancelAction:@selector(enableUserInteractionAndResetHighlight) + withObject:(id) ^(NSString* message){ + [messageBrick setMessage:message forLineNumber:line andParameterNumber:parameter]; + } + promptTitle:kLocalizedNewMessage + promptMessage:[NSString stringWithFormat:@"%@:", kLocalizedMessage] + promptValue:nil + promptPlaceholder:kLocalizedEnterYourMessageHere + minInputLength:kMinNumOfMessageNameCharacters + maxInputLength:kMaxNumOfMessageNameCharacters + invalidInputAlertMessage:kLocalizedMessageAlreadyExistsDescription + existingNames:[Util allMessagesForProject:self.object.scene.project].array]; + [self enableUserInteractionAndResetHighlight]; + return; + } else { + [messageBrick setMessage:(NSString*)value forLineNumber:line andParameterNumber:parameter]; + } + } else + if ([brickCellData isKindOfClass:[BrickCellVariableData class]] && [brick conformsToProtocol:@protocol(BrickVariableProtocol)]) { + if([(NSString*)value isEqualToString:kLocalizedNewElement]) { + CBAssert([brickCellData.brickCell.scriptOrBrick isKindOfClass:[Brick class]]); + + NSIndexPath *path = [self.collectionView indexPathForCell:(UICollectionViewCell*)brickCellData.brickCell]; + + CreateVariableOrListViewController *cvlvc = [[CreateVariableOrListViewController alloc] initWithSpriteObject:self.object shouldCreateList:NO hideCreateList:YES addedCompletion:^(NSString * _Nonnull variableName) { + + UserVariable *var = [UserDataContainer objectOrProjectVariableForObject:self.object andName:(NSString*)variableName]; + + self.variableIndexPath = path; + + BrickCell *brickCell = (BrickCell*)[self.collectionView cellForItemAtIndexPath:self.variableIndexPath]; + Brick *brick = (Brick*)brickCell.scriptOrBrick; + Brick *variableBrick; + + if ([brick conformsToProtocol:@protocol(BrickVariableProtocol)]) { + variableBrick = (Brick*)brick; + } + + if (var) { + [variableBrick setVariable:var forLineNumber:self.variableIndexPath.row andParameterNumber:self.variableIndexPath.section]; + } + + [self enableUserInteractionAndResetHighlight]; + }]; + + + if (@available(iOS 13.0, *)) { + cvlvc.modalInPresentation = true; + } else { + cvlvc.modalPresentationStyle = UIModalPresentationFullScreen; + } - [self enableUserInteractionAndResetHighlight]; - }]; - - - if (@available(iOS 13.0, *)) { - cvlvc.modalInPresentation = true; - } else { - cvlvc.modalPresentationStyle = UIModalPresentationFullScreen; - } - - UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:cvlvc]; - [self presentViewController:navController animated:YES completion:NULL]; - [self enableUserInteractionAndResetHighlight]; - return; - } else { - Brick *listBrick = (Brick*)brick; - UserList *list = [UserDataContainer objectOrProjectListForObject:self.object andName:(NSString*)value]; - if(list) - [listBrick setList:list forLineNumber:line andParameterNumber:parameter]; - } - } else - if ([brickCellData isKindOfClass:[BrickCellPhiroMotorData class]] && [brick conformsToProtocol:@protocol(BrickPhiroMotorProtocol)]) { - Brick *motorBrick = (Brick*)brick; - [motorBrick setMotor:(NSString*)value forLineNumber:line andParameterNumber:parameter]; - } else - if ([brickCellData isKindOfClass:[BrickCellPhiroToneData class]] && [brick conformsToProtocol:@protocol(BrickPhiroToneProtocol)]) { - Brick *toneBrick = (Brick*)brick; - [toneBrick setTone:(NSString*)value forLineNumber:line andParameterNumber:parameter]; - } else - if ([brickCellData isKindOfClass:[BrickCellPhiroLightData class]] && [brick conformsToProtocol:@protocol(BrickPhiroLightProtocol)]) { - Brick *lightBrick = (Brick*)brick; - [lightBrick setLight:(NSString*)value forLineNumber:line andParameterNumber:parameter]; - } else - if ([brickCellData isKindOfClass:[BrickCellPhiroIfSensorData class]] && [brick conformsToProtocol:@protocol(BrickPhiroIfSensorProtocol)]) { - Brick *phiroIfBrick = (Brick*)brick; - [phiroIfBrick setSensor:(NSString*)value forLineNumber:line andParameterNumber:parameter]; - } + UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:cvlvc]; + [self presentViewController:navController animated:YES completion:NULL]; + [self enableUserInteractionAndResetHighlight]; + return; + } else { + Brick *variableBrick = (Brick*)brick; + UserVariable *variable = [UserDataContainer objectOrProjectVariableForObject:self.object andName:(NSString*)value]; + if(variable) + [variableBrick setVariable:variable forLineNumber:line andParameterNumber:parameter]; + } + } else + if ([brickCellData isKindOfClass:[BrickCellListData class]] && [brick conformsToProtocol:@protocol(BrickListProtocol)]) { + if([(NSString*)value isEqualToString:kLocalizedNewElement]) { + CBAssert([brickCellData.brickCell.scriptOrBrick isKindOfClass:[Brick class]]); + + NSIndexPath *path = [self.collectionView indexPathForCell:(UICollectionViewCell*)brickCellData.brickCell]; + + CreateVariableOrListViewController *cvlvc = [[CreateVariableOrListViewController alloc] initWithSpriteObject:self.object shouldCreateList:YES hideCreateList:YES addedCompletion:^(NSString * _Nonnull listName) { + + UserList *list = [UserDataContainer objectOrProjectListForObject:self.object andName:(NSString*)listName]; + + self.variableIndexPath = path; + + BrickCell *brickCell = (BrickCell*)[self.collectionView cellForItemAtIndexPath:self.variableIndexPath]; + Brick *brick = (Brick*)brickCell.scriptOrBrick; + Brick *listBrick; + + if ([brick conformsToProtocol:@protocol(BrickListProtocol)]) { + listBrick = (Brick*)brick; + } + + if (list) { + [listBrick setList:list forLineNumber:self.variableIndexPath.row andParameterNumber:self.variableIndexPath.section]; + } + + [self enableUserInteractionAndResetHighlight]; + }]; + + + if (@available(iOS 13.0, *)) { + cvlvc.modalInPresentation = true; + } else { + cvlvc.modalPresentationStyle = UIModalPresentationFullScreen; + } + + UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:cvlvc]; + [self presentViewController:navController animated:YES completion:NULL]; + [self enableUserInteractionAndResetHighlight]; + return; + } else { + Brick *listBrick = (Brick*)brick; + UserList *list = [UserDataContainer objectOrProjectListForObject:self.object andName:(NSString*)value]; + if(list) + [listBrick setList:list forLineNumber:line andParameterNumber:parameter]; + } + } else + if ([brickCellData isKindOfClass:[BrickCellPhiroMotorData class]] && [brick conformsToProtocol:@protocol(BrickPhiroMotorProtocol)]) { + Brick *motorBrick = (Brick*)brick; + [motorBrick setMotor:(NSString*)value forLineNumber:line andParameterNumber:parameter]; + } else + if ([brickCellData isKindOfClass:[BrickCellPhiroToneData class]] && [brick conformsToProtocol:@protocol(BrickPhiroToneProtocol)]) { + Brick *toneBrick = (Brick*)brick; + [toneBrick setTone:(NSString*)value forLineNumber:line andParameterNumber:parameter]; + } else + if ([brickCellData isKindOfClass:[BrickCellPhiroLightData class]] && [brick conformsToProtocol:@protocol(BrickPhiroLightProtocol)]) { + Brick *lightBrick = (Brick*)brick; + [lightBrick setLight:(NSString*)value forLineNumber:line andParameterNumber:parameter]; + } else + if ([brickCellData isKindOfClass:[BrickCellPhiroIfSensorData class]] && [brick conformsToProtocol:@protocol(BrickPhiroIfSensorProtocol)]) { + Brick *phiroIfBrick = (Brick*)brick; + [phiroIfBrick setSensor:(NSString*)value forLineNumber:line andParameterNumber:parameter]; + } [self.object.scene.project saveToDiskWithNotification:NO]; [self enableUserInteractionAndResetHighlight]; @@ -1199,7 +1219,7 @@ -(void)disableUserInteractionAndHighlight:(BrickCell*)brickCell withMarginBottom self.isEditingBrickMode = YES; self.navigationController.toolbar.userInteractionEnabled = NO; self.navigationController.navigationBar.userInteractionEnabled = NO; - // disable swipe back gesture + // disable swipe back gesture if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; } @@ -1255,21 +1275,21 @@ -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id context) { - if ([[BrickInsertManager sharedInstance] isBrickInsertionMode]) { - NSMutableArray* scriptlist = [self object].scriptList; - for (int section = 0; section < scriptlist.count; section++) { - for (int row = 0; row < scriptlist[section].brickList.count; row++) { - if (scriptlist[section].brickList[row].animateInsertBrick) { - [self.collectionView scrollToItemAtIndexPath: [NSIndexPath indexPathForRow:row inSection:section] - atScrollPosition:UICollectionViewScrollPositionCenteredVertically - animated:NO]; - return; + if ([[BrickInsertManager sharedInstance] isBrickInsertionMode]) { + NSMutableArray* scriptlist = [self object].scriptList; + for (int section = 0; section < scriptlist.count; section++) { + for (int row = 0; row < scriptlist[section].brickList.count; row++) { + if (scriptlist[section].brickList[row].animateInsertBrick) { + [self.collectionView scrollToItemAtIndexPath: [NSIndexPath indexPathForRow:row inSection:section] + atScrollPosition:UICollectionViewScrollPositionCenteredVertically + animated:NO]; + return; } - } - } - } - }]; - } + } + } + } + }]; +} - (void)selectAllRows:(id)sender @@ -1315,23 +1335,23 @@ -(void)exitDeleteMode [UIView animateWithDuration:0.3f delay:0.0f usingSpringWithDamping:0.65f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{ - for (BrickCell *brickCell in self.collectionView.visibleCells) { - brickCell.center = CGPointMake(self.view.center.x, brickCell.center.y); - brickCell.selectButton.alpha = 0.0f; - } - } completion:^(BOOL finished) { - for (BrickCell *brickCell in self.collectionView.visibleCells) { - brickCell.enabled = YES; - brickCell.selectButton.selected = NO; - } - for (Script *script in self.object.scriptList) { - script.isSelected = NO; - for (Brick *brick in script.brickList) { - brick.isSelected = NO; - } - } - [[BrickSelectionManager sharedInstance] reset]; - }]; + for (BrickCell *brickCell in self.collectionView.visibleCells) { + brickCell.center = CGPointMake(self.view.center.x, brickCell.center.y); + brickCell.selectButton.alpha = 0.0f; + } + } completion:^(BOOL finished) { + for (BrickCell *brickCell in self.collectionView.visibleCells) { + brickCell.enabled = YES; + brickCell.selectButton.selected = NO; + } + for (Script *script in self.object.scriptList) { + script.isSelected = NO; + for (Brick *brick in script.brickList) { + brick.isSelected = NO; + } + } + [[BrickSelectionManager sharedInstance] reset]; + }]; self.editing = NO; self.allBricksSelected = NO; } diff --git a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerForeverTests.m b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerForeverTests.m index 48611d8433..5895732250 100644 --- a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerForeverTests.m +++ b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerForeverTests.m @@ -65,9 +65,10 @@ - (void)testMoveForeverBeginBelowEndIntoAnotherForeverNested { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:3 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ForeverBrick inside other ForeverBrick"); } @@ -96,9 +97,10 @@ - (void)testMoveForeverEndToCreateInvalidNestedLoops { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:3 inSection:0]; [[BrickMoveManager sharedInstance] getReadyForNewBrickMovement]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ForeverEnd-Brick inside other ForeverBrick"); } @@ -127,9 +129,10 @@ - (void)testMoveForeverEndToCreateValidNestedLoops { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:4 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ForeverEnd-Brick below other ForeverEnd-Brick"); } @@ -158,9 +161,10 @@ - (void)testMoveForeverBeginToCreateValidNestedLoops { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:1 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ForeverBegin-Brick away to leave something below foreverEnd."); } @@ -202,9 +206,10 @@ - (void)testMoveIfBrickBeginInsideForeverBrickToOutside { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:1 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move IfBrick inside forever-loop above ForeverBrick"); } @@ -261,9 +266,10 @@ - (void)testMoveWaitBrickBelowForeverBrickInsideIfBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:4 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move WaitBrick below forever-loop of if-branch"); } @@ -320,9 +326,10 @@ - (void)testMoveWaitBrickBelowForeverBrickInsideElse { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:7 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move WaitBrick below forever-loop of else-branch"); } @@ -379,9 +386,10 @@ - (void)testMoveWaitBrickBeforeForeverBrickInsideIfBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:2 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick before forever-loop of if-branch"); } @@ -438,9 +446,10 @@ - (void)testMoveWaitBrickBeforeForeverBrickInsideElse { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:5 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick before forever-loop of else-branch"); } @@ -497,9 +506,10 @@ - (void)testMoveWaitBrickFromOneForeverLoopInIfBranchToAnotherInElseBranch { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:6 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick from one ForeverLoop to another"); } @@ -556,9 +566,10 @@ - (void)testMoveWaitBrickFromOneForeverLoopInElseBranchToAnotherInIfBranch { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:3 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick from one ForeverLoop to another"); } @@ -629,9 +640,10 @@ - (void)testMoveWaitBrickFromOneForeverLoopInElseBranchToAnotherInIfBranchAllTog NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:4 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick from one ForeverLoop to another all together in ForeverLoop."); } @@ -707,9 +719,10 @@ - (void)testMoveForeverEndBrickInNestedIfElseStructureToAllPossibleDestinations NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:testedDestination inSection:0]; [[BrickMoveManager sharedInstance] reset]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)testedDestination); } } @@ -719,7 +732,8 @@ - (void)testMoveForeverEndBrickInNestedIfElseStructureToAllPossibleDestinations BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -798,7 +812,8 @@ - (void)testMoveForeverBeginBrickInNestedIfElseStructureToAllPossibleDestination BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)testedDestination); } } @@ -809,7 +824,8 @@ - (void)testMoveForeverBeginBrickInNestedIfElseStructureToAllPossibleDestination BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -827,15 +843,17 @@ - (void) testMoveForeverBricksToOtherEmptyScript { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ForeverBeginBrick to another script"); indexPathFrom = [NSIndexPath indexPathForRow:2 inSection:0]; indexPathTo = [NSIndexPath indexPathForRow:1 inSection:1]; canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move LoopEndBrick to another script"); } diff --git a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerLogicTests.m b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerLogicTests.m index 667107d5b7..babc295816 100644 --- a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerLogicTests.m +++ b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerLogicTests.m @@ -65,9 +65,10 @@ - (void)testMoveForeverBrickInsideIfBranch { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:2 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ForeverBrick inside if-branch of IfLogicBeginBrick"); } @@ -100,7 +101,8 @@ - (void)testMoveForeverBrickInsideElseBranch { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ForeverBrick inside else-branch of IfLogicBeginBrick"); } @@ -153,9 +155,10 @@ - (void)testMoveIfBrickAboveOuterIfBrick { [[BrickMoveManager sharedInstance] setLowerBorder:[NSIndexPath indexPathForRow:3 inSection:0]]; [[BrickMoveManager sharedInstance] setUpperBorder:[NSIndexPath indexPathForRow:1 inSection:0]]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move nested IfLogicBeginBrick above main IfLogicBeginBrick"); } @@ -208,9 +211,10 @@ - (void)testMoveIfLogicBeginBricksInsideElseBranch { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:2 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move nested IfLogicBeginBrick above main IfLogicElseBrick"); } @@ -221,9 +225,10 @@ - (void)testMoveIfLogicBeginBricksInsideElseBranch { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:3 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move main IfLogicElseBrick below nested IfLogicElseBrick"); } } @@ -258,9 +263,10 @@ - (void)testMoveIfBeginBrickInvalidBeforeIfEndBrickOfOtherIfBrick { [[BrickMoveManager sharedInstance] setLowerBorder:[NSIndexPath indexPathForRow:5 inSection:0]]; [[BrickMoveManager sharedInstance] setUpperBorder:[NSIndexPath indexPathForRow:3 inSection:0]]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move IfLogicBeginBrick above IfLogicEndBrick"); } @@ -271,9 +277,10 @@ - (void)testMoveIfBeginBrickInvalidBeforeIfEndBrickOfOtherIfBrick { [[BrickMoveManager sharedInstance] setLowerBorder:[NSIndexPath indexPathForRow:4 inSection:0]]; [[BrickMoveManager sharedInstance] setUpperBorder:[NSIndexPath indexPathForRow:2 inSection:0]]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move IfLogicEndBrick below IfLogicBeginBrick"); } } @@ -333,9 +340,10 @@ - (void)testMoveWaitBrickInsideForeverBrickOfIfLogicBeginBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:3 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick inside ForeverBrick of if-branch"); } @@ -394,9 +402,10 @@ - (void)testMoveWaitBrickAfterForeverLoopOfIfLogicBeginBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:4 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move WaitBrick after LoopEndBrick of ForeverBrick of if-branch"); } @@ -443,9 +452,10 @@ - (void)testMoveWaitBrickFromNestedIfStructureWithForeverLoopsToAnother { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:4 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick from one if-else structure to another"); } @@ -514,9 +524,10 @@ - (void)testMoveWaitBrickFromNestedIfStructureWithForeverLoopsToAnotherIndepende NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:4 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick from one if-else structure to another"); } @@ -584,9 +595,10 @@ - (void)testMoveIfBeginInNestedIfElseStructWithForeverLoopsToInvalidDestination NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:5 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move IfBegin to here!"); } @@ -663,7 +675,8 @@ - (void)testMoveIfBrickInNestedIfElseStructureWithForeverLoopsToAllPossiblePlace BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -744,7 +757,8 @@ - (void)testMoveElseBrickInNestedIfElseStructureWithForeverLoopsToAllPossiblePla BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -825,7 +839,8 @@ - (void)testMoveIfBrickInNestedIfElseStructureWithRepeatLoopsToAllPossiblePlaces BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -836,7 +851,8 @@ - (void)testMoveIfBrickInNestedIfElseStructureWithRepeatLoopsToAllPossiblePlaces BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)validIDX); } @@ -916,7 +932,8 @@ - (void)testMoveElseBrickInNestedIfElseStructureWithRepeatLoopsToAllPossiblePlac BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -928,7 +945,8 @@ - (void)testMoveElseBrickInNestedIfElseStructureWithRepeatLoopsToAllPossiblePlac BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)validIDX1); } @@ -939,7 +957,8 @@ - (void)testMoveElseBrickInNestedIfElseStructureWithRepeatLoopsToAllPossiblePlac BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)validIDX2); } @@ -991,7 +1010,8 @@ - (void)testMoveWaitBrickFromNestedIfThenStructureWithForeverLoopsToAnother { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick from one if-else structure to another"); } @@ -1062,7 +1082,8 @@ - (void)testMoveWaitBrickFromNestedIfThenStructureWithForeverLoopsToAnotherIndep BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move WaitBrick from one if-else structure to another"); } @@ -1132,7 +1153,8 @@ - (void)testMoveIfBeginInNestedIfThenStructWithForeverLoopsToInvalidDestination BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move IfBegin to here!"); } @@ -1209,7 +1231,8 @@ - (void)testMoveIfBrickInNestedIfThenStructureWithForeverLoopsToAllPossiblePlace BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -1290,7 +1313,8 @@ - (void)testMoveElseBrickInNestedIfThenStructureWithForeverLoopsToAllPossiblePla BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -1371,7 +1395,8 @@ - (void)testMoveIfBrickInNestedIfThenStructureWithRepeatLoopsToAllPossiblePlaces BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -1382,7 +1407,8 @@ - (void)testMoveIfBrickInNestedIfThenStructureWithRepeatLoopsToAllPossiblePlaces BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)validIDX); } @@ -1462,7 +1488,8 @@ - (void)testMoveElseBrickInNestedIfThenStructureWithRepeatLoopsToAllPossiblePlac BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)testedDestination); } @@ -1474,7 +1501,8 @@ - (void)testMoveElseBrickInNestedIfThenStructureWithRepeatLoopsToAllPossiblePlac BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)validIDX1); } @@ -1485,7 +1513,8 @@ - (void)testMoveElseBrickInNestedIfThenStructureWithRepeatLoopsToAllPossiblePlac BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu", (unsigned long)validIDX2); } @@ -1506,7 +1535,8 @@ - (void) testMoveIfBricksToOtherEmptyScript { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move IfBeginBrick to another script"); indexPathFrom = [NSIndexPath indexPathForRow:2 inSection:0]; @@ -1514,7 +1544,8 @@ - (void) testMoveIfBricksToOtherEmptyScript { canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ThenBrick to another script"); indexPathFrom = [NSIndexPath indexPathForRow:3 inSection:0]; @@ -1522,7 +1553,8 @@ - (void) testMoveIfBricksToOtherEmptyScript { canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move ElseBrick to another script"); } diff --git a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerRepeatTests.m b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerRepeatTests.m index 3867f08077..d4e0a0c817 100644 --- a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerRepeatTests.m +++ b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerRepeatTests.m @@ -66,9 +66,10 @@ - (void)testMoveNestedRepeatBricks { [[BrickMoveManager sharedInstance] setUpperBorder:[NSIndexPath indexPathForRow:0 inSection:0]]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move RepeatBrick inside other RepeatBrick"); } @@ -110,9 +111,10 @@ - (void)testMoveIfBrickInsideRepeatBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:1 inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move IfBrick inside repeat-loop above RepeatBrick"); } @@ -166,9 +168,10 @@ - (void)testMoveWaitBrickToAllPossibleDestinations { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:destinationIDX inSection:0]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -228,7 +231,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinations { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -239,7 +243,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinations { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)validTarget1); } } @@ -298,7 +303,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinations { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -309,7 +315,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinations { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)validTarget3); } @@ -404,7 +411,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNested { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -414,7 +422,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNested { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -507,7 +516,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNested { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -517,7 +527,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNested { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -610,7 +621,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -620,7 +632,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -640,7 +653,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -650,7 +664,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -670,7 +685,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -680,7 +696,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -697,7 +714,8 @@ - (void)testMoveRepeatEndToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)destinationIDX); } @@ -796,7 +814,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -806,7 +825,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -826,7 +846,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -836,7 +857,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -856,7 +878,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -866,7 +889,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should be not allowed to move to line %lu.", (unsigned long)validTarget1); } @@ -886,7 +910,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)destinationIDX); } } @@ -896,7 +921,8 @@ - (void)testMoveRepeatBeginToAllPossibleDestinationsNestedHigherOrder { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to line %lu.", (unsigned long)validTarget1); } } @@ -914,7 +940,8 @@ - (void) testMoveRepeatBricksToOtherEmptyScript { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move RepeatBeginBrick to another script"); indexPathFrom = [NSIndexPath indexPathForRow:2 inSection:0]; @@ -922,7 +949,8 @@ - (void) testMoveRepeatBricksToOtherEmptyScript { canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView itemAtIndexPath:indexPathFrom canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move LoopEndBrick to another script"); } diff --git a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerTests.m b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerTests.m index 20aa1d89b9..f57276fbe1 100644 --- a/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerTests.m +++ b/src/CattyTests/Bricks/BrickMoveManager/BrickMoveManagerTests.m @@ -68,9 +68,10 @@ - (void)testMoveWaitBehindSetVariableBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:2 inSection:0]; BOOL canMove = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMove, @"Should be allowed to move WaitBrick behind SetVariableBrick"); } @@ -105,18 +106,20 @@ - (void)testMoveWaitBehindForeverBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:2 inSection:0]; BOOL canMoveWaitBrickInsideForeverBrick = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveWaitBrickInsideForeverBrick, @"Should be allowed to move WaitBrick inside ForeverBrick"); } { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:3 inSection:0]; BOOL canMoveWaitBrickBehindForeverBrick = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveWaitBrickBehindForeverBrick, @"Should not be allowed to move WaitBrick behind ForeverBrick"); } @@ -150,9 +153,10 @@ - (void)testMoveWaitBehindRepeatBrick { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:3 inSection:0]; BOOL canMoveWaitBrickBehindRepeatBrick = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveWaitBrickBehindRepeatBrick, @"Should be allowed to move WaitBrick behind RepeatBrick"); } @@ -191,9 +195,10 @@ - (void)testMoveWaitBrickIntoOtherScript { NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:0 inSection:1]; BOOL canMoveWaitInOtherScript = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveWaitInOtherScript, @"Should be allowed to move WaitBrick into other Script"); } @@ -244,18 +249,20 @@ - (void)testMoveForeverBeginBrickWithMultipleScripts if(![indexPathTo isEqual:validTarget] && destinationIDX != indexPathFrom.item ) { [[BrickMoveManager sharedInstance] reset]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to idx %lu in section %lu", (unsigned long)(unsigned long)destinationIDX, (unsigned long)section); } } } [[BrickMoveManager sharedInstance] reset]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:validTarget - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:validTarget + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to idx %lu in section %lu", (unsigned long)validRow, (unsigned long)validSection); } @@ -302,9 +309,10 @@ - (void)testMoveForeverEndBrickWithMultipleScripts NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:destinationIDX inSection:section]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to idx %lu in section %lu", (unsigned long)destinationIDX, (unsigned long)section); } } @@ -358,18 +366,20 @@ - (void)testMoveRepeatBeginBrickWithMultipleScripts if(![indexPathTo isEqual:validTarget] && destinationIDX != indexPathFrom.item) { [[BrickMoveManager sharedInstance] reset]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to idx %lu in section %lu", (unsigned long)destinationIDX, (unsigned long)section); } } } [[BrickMoveManager sharedInstance] reset]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:validTarget - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:validTarget + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to idx %lu in section %lu", (unsigned long)validRow, (unsigned long)validSection); } @@ -421,18 +431,20 @@ - (void)testMoveRepeatEndBrickWithMultipleScripts if(![indexPathTo isEqual:validTarget] && destinationIDX != indexPathFrom.item) { BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertFalse(canMoveToDestination, @"Should not be allowed to move to idx %lu in section %lu", (unsigned long)destinationIDX, (unsigned long)section); } } } BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:validTarget - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:validTarget + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move to idx %lu in section %lu", (unsigned long)validRow, (unsigned long)validSection); } @@ -522,9 +534,10 @@ - (void)testMoveMoveableBricksAround NSIndexPath *indexPathTo = [NSIndexPath indexPathForRow:destinationIDX inSection:destinationSection]; BOOL canMoveToDestination = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView - itemAtIndexPath:indexPathFrom - canMoveToIndexPath:indexPathTo - andObject:self.spriteObject]; + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:YES]; XCTAssertTrue(canMoveToDestination, @"Should be allowed to move from section %lu, row %lu to section %lu, row %lu", (unsigned long)sourceSection, (unsigned long)sourceIDX, (unsigned long)destinationSection, (unsigned long)destinationIDX); } @@ -533,5 +546,134 @@ - (void)testMoveMoveableBricksAround } } +- (void)testMoveStartScriptBehindOtherScript { + + /* Test: + + 0 startedScript ---> + 1 wait + + 0 whenScript <--- + 1 + */ + + [self.viewController.collectionView reloadData]; + + NSUInteger addedSections = 1; + NSUInteger addedBricksStart = 1; + + WaitBrick *waitBrick = [[WaitBrick alloc] init]; + waitBrick.script = self.startScript; + [self.startScript.brickList addObject:waitBrick]; + addedBricksStart++; + + WhenScript *whenScript = [[WhenScript alloc] init]; + whenScript.object = self.spriteObject; + [self.spriteObject.scriptList addObject:whenScript]; + NSUInteger addedBricksWhen = 1; + addedSections++; + + XCTAssertEqual(addedSections, [self.viewController.collectionView numberOfSections]); + XCTAssertEqual(addedBricksStart, [self.viewController.collectionView numberOfItemsInSection:0]); + XCTAssertEqual(addedBricksWhen, [self.viewController.collectionView numberOfItemsInSection:1]); + + NSIndexPath * indexPathFrom = [NSIndexPath indexPathForRow:0 inSection:0]; + NSIndexPath * indexPathTo = [NSIndexPath indexPathForRow:1 inSection:0]; + + BOOL canMoveStartScriptBehindOtherScript = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:NO]; + XCTAssertFalse(canMoveStartScriptBehindOtherScript, @"Should not be allowed to move StartScript"); + + indexPathFrom = [NSIndexPath indexPathForRow:0 inSection:0]; + indexPathTo = [NSIndexPath indexPathForRow:0 inSection:1]; + + canMoveStartScriptBehindOtherScript = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:NO]; + XCTAssertTrue(canMoveStartScriptBehindOtherScript, @"Should be allowed to move StartScript behind the whenScript"); +} + +- (void)testMoveStartScriptBeforeOrBehindOtherScripts { + + /* Test: + + 0 startedScript + 1 wait + + 0 whenScriptA + 1 + + 0 whenScriptB + 1 waitBrickA + 2 setXBrickA + 3 setYBrickA + 4 waitBrickB + 5 placeAtXYA + 6 waitBrickC + */ + + [self.viewController.collectionView reloadData]; + + NSUInteger addedSections = 1; + NSUInteger addedBricksStart = 1; + + WaitBrick *waitBrick = [[WaitBrick alloc] init]; + waitBrick.script = self.startScript; + [self.startScript.brickList addObject:waitBrick]; + addedBricksStart++; + + WhenScript *whenScriptA = [[WhenScript alloc] init]; + whenScriptA.object = self.spriteObject; + [self.spriteObject.scriptList addObject:whenScriptA]; + NSUInteger addedBricksWhen = 1; + addedSections++; + + WhenScript *whenScriptB = [[WhenScript alloc] init]; + whenScriptB.object = self.spriteObject; + [self.spriteObject.scriptList addObject:whenScriptB]; + NSUInteger addedBricksWhenB = 1; + addedSections++; + addedBricksWhenB += [self addWaitSetXSetYWaitPlaceAtWaitBricksToScript:whenScriptB]; + + XCTAssertEqual(addedSections, [self.viewController.collectionView numberOfSections]); + XCTAssertEqual(addedBricksStart, [self.viewController.collectionView numberOfItemsInSection:0]); + XCTAssertEqual(addedBricksWhen, [self.viewController.collectionView numberOfItemsInSection:1]); + + NSIndexPath * indexPathFrom = [NSIndexPath indexPathForRow:0 inSection:0]; + NSIndexPath * indexPathTo = [NSIndexPath indexPathForRow:0 inSection:2]; + + BOOL canMoveStartScriptBehindOtherScripts = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:NO]; + XCTAssertTrue(canMoveStartScriptBehindOtherScripts, @"Should be allowed to move startScript behind whenScriptA and whenScriptB"); + + indexPathFrom = [NSIndexPath indexPathForRow:0 inSection:0]; + indexPathTo = [NSIndexPath indexPathForRow:0 inSection:1]; + + BOOL canMoveWhenScriptABehindWhenScriptB = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:NO]; + XCTAssertTrue(canMoveWhenScriptABehindWhenScriptB, @"Should be allowed to move whenScriptA behind whenScriptB"); + + indexPathFrom = [NSIndexPath indexPathForRow:0 inSection:1]; + indexPathTo = [NSIndexPath indexPathForRow:0 inSection:0]; + + BOOL canMoveWhenScriptABeforeWhenScriptB = [[BrickMoveManager sharedInstance] collectionView:self.viewController.collectionView + itemAtIndexPath:indexPathFrom + canMoveToIndexPath:indexPathTo + andObject:self.spriteObject + isBrick:NO]; + XCTAssertTrue(canMoveWhenScriptABeforeWhenScriptB, @"Should be allowed to move whenScriptA before whenScriptB"); +} + @end diff --git a/src/CattyTests/ViewController/ScriptCollectionViewControllerTests.swift b/src/CattyTests/ViewController/ScriptCollectionViewControllerTests.swift index ce20d7f940..3345282c4f 100644 --- a/src/CattyTests/ViewController/ScriptCollectionViewControllerTests.swift +++ b/src/CattyTests/ViewController/ScriptCollectionViewControllerTests.swift @@ -181,7 +181,7 @@ final class ScriptCollectionViewControllerTests: XCTestCase { let indexPathWhenScript = IndexPath(row: 0, section: 1) whenScript.isAnimatedInsertBrick = true (BrickInsertManager.sharedInstance() as! BrickInsertManager).setBrickInsertionMode(true) - XCTAssertFalse(viewController.collectionView(viewController.collectionView, canMoveItemAt: indexPathStartScript)) + XCTAssertTrue(viewController.collectionView(viewController.collectionView, canMoveItemAt: indexPathStartScript)) (BrickInsertManager.sharedInstance() as! BrickInsertManager).setBrickInsertionMode(true) XCTAssertTrue(viewController.collectionView(viewController.collectionView, canMoveItemAt: indexPathWhenScript)) } diff --git a/src/CattyUITests/Defines/LanguageTranslationDefinesUI.swift b/src/CattyUITests/Defines/LanguageTranslationDefinesUI.swift index 8680305e4e..5d17a9b1ff 100644 --- a/src/CattyUITests/Defines/LanguageTranslationDefinesUI.swift +++ b/src/CattyUITests/Defines/LanguageTranslationDefinesUI.swift @@ -168,6 +168,7 @@ let kLocalizedDisableCondition = NSLocalizedString("Disable condition", bundle: let kLocalizedEnableCondition = NSLocalizedString("Enable condition", bundle: Bundle(for: LanguageTranslation.self), comment: "") let kLocalizedEditFormula = NSLocalizedString("Edit formula", bundle: Bundle(for: LanguageTranslation.self), comment: "") let kLocalizedMoveBrick = NSLocalizedString("Move brick", bundle: Bundle(for: LanguageTranslation.self), comment: "") +let kLocalizedMoveScript = NSLocalizedString("Move script", bundle: Bundle(for: LanguageTranslation.self), comment: "") let kLocalizedDeleteSounds = NSLocalizedString("Delete sounds", bundle: Bundle(for: LanguageTranslation.self), comment: "") let kLocalizedMoveSounds = NSLocalizedString("Move sounds", bundle: Bundle(for: LanguageTranslation.self), comment: "") let kLocalizedHideDetails = NSLocalizedString("Hide details", bundle: Bundle(for: LanguageTranslation.self), comment: "")