Skip to content

CATTY-471 Move Scripts #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Catty/Defines/LanguageTranslationDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/Catty/Defines/LanguageTranslationDefinesSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "")
Expand Down
3 changes: 3 additions & 0 deletions src/Catty/Resources/Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading