Skip to content

Commit

Permalink
Catty-471 Move Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
oetzlinger committed Jan 3, 2023
1 parent 757c7c5 commit f1e9f0a
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 244 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ @interface ScriptCollectionViewController() <UICollectionViewDelegate,
@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

Expand Down Expand Up @@ -304,6 +305,14 @@ - (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPat
[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]
Expand Down Expand Up @@ -401,17 +410,24 @@ - (void)collectionView:(UICollectionView*)collectionView
} 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];
} else {
[fromScript.brickList removeObjectAtIndex:fromIndexPath.item - 1];
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];
}
}
if ([toScript.brickList count] == 0) {
[toScript.brickList insertObject:fromBrick atIndex:toIndexPath.item];
}else{
[toScript.brickList insertObject:fromBrick atIndex:toIndexPath.item - 1];
else {
self.object.scriptList[toIndexPath.section] = fromScript;
self.object.scriptList[fromIndexPath.section] = toScript;

}
}
}
Expand All @@ -433,22 +449,28 @@ - (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{
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];
}
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;
script.animateInsertBrick = NO;
}
}else{
} else {
script.animateInsertBrick = NO;
script.animateMoveBrick = NO;
script.animateInsertBrick = NO;
}
[self.object.scene.project saveToDiskWithNotification:NO];
Expand All @@ -473,8 +495,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];
}


Expand All @@ -487,9 +513,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);
}

Expand Down
Loading

0 comments on commit f1e9f0a

Please sign in to comment.