Skip to content

Commit

Permalink
CATTY-552 Clone object or actor
Browse files Browse the repository at this point in the history
  • Loading branch information
amelak9 committed Aug 7, 2021
1 parent dce344b commit 734157d
Show file tree
Hide file tree
Showing 20 changed files with 503 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/Catty.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,11 @@
972622DD25F51A8F00ABCC7A /* ChangeBrightnessByNBrick+CBXMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 972622DC25F51A8F00ABCC7A /* ChangeBrightnessByNBrick+CBXMLHandler.swift */; };
972622E225F51B4500ABCC7A /* SetBrightnessBrick+CBXMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 972622E125F51B4500ABCC7A /* SetBrightnessBrick+CBXMLHandler.swift */; };
9728AE9E25DEEE5A00708EB6 /* ProjectDetailStoreViewControllerReportExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9728AE9D25DEEE5A00708EB6 /* ProjectDetailStoreViewControllerReportExtension.swift */; };
973F1D3226B1923F0043108A /* CloneBrick+CBXMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973F1D3126B1923F0043108A /* CloneBrick+CBXMLHandler.swift */; };
9740489026B04FAE0047DEBB /* CloneBrick.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740488F26B04FAE0047DEBB /* CloneBrick.swift */; };
9740489426B052950047DEBB /* CloneBrickCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740489326B052950047DEBB /* CloneBrickCell.swift */; };
9740489626B0547D0047DEBB /* CloneBrick+Instruction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740489526B0547D0047DEBB /* CloneBrick+Instruction.swift */; };
9740489E26B097500047DEBB /* CloneBrickTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740489D26B097500047DEBB /* CloneBrickTests.swift */; };
97417A9B265284400079A2A2 /* SoundsTableViewController+SelectFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97417A9A265284400079A2A2 /* SoundsTableViewController+SelectFile.swift */; };
9767BAFA26668ECD009794E8 /* JoinThreeStringsFunctionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9767BAF926668ECD009794E8 /* JoinThreeStringsFunctionTest.swift */; };
97770B8825E5A88C00F51EFA /* SetBrightnessBrick.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97770B8725E5A88C00F51EFA /* SetBrightnessBrick.swift */; };
Expand Down Expand Up @@ -3336,6 +3341,11 @@
972622DC25F51A8F00ABCC7A /* ChangeBrightnessByNBrick+CBXMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChangeBrightnessByNBrick+CBXMLHandler.swift"; sourceTree = "<group>"; };
972622E125F51B4500ABCC7A /* SetBrightnessBrick+CBXMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SetBrightnessBrick+CBXMLHandler.swift"; sourceTree = "<group>"; };
9728AE9D25DEEE5A00708EB6 /* ProjectDetailStoreViewControllerReportExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectDetailStoreViewControllerReportExtension.swift; sourceTree = "<group>"; };
973F1D3126B1923F0043108A /* CloneBrick+CBXMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "CloneBrick+CBXMLHandler.swift"; path = "CattyTests/Bricks/CloneBrick+CBXMLHandler.swift"; sourceTree = SOURCE_ROOT; };
9740488F26B04FAE0047DEBB /* CloneBrick.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloneBrick.swift; sourceTree = "<group>"; };
9740489326B052950047DEBB /* CloneBrickCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloneBrickCell.swift; sourceTree = "<group>"; };
9740489526B0547D0047DEBB /* CloneBrick+Instruction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CloneBrick+Instruction.swift"; sourceTree = "<group>"; };
9740489D26B097500047DEBB /* CloneBrickTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloneBrickTests.swift; sourceTree = "<group>"; };
97417A9A265284400079A2A2 /* SoundsTableViewController+SelectFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SoundsTableViewController+SelectFile.swift"; sourceTree = "<group>"; };
9767BAF926668ECD009794E8 /* JoinThreeStringsFunctionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinThreeStringsFunctionTest.swift; sourceTree = "<group>"; };
97770B8725E5A88C00F51EFA /* SetBrightnessBrick.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetBrightnessBrick.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3994,6 +4004,7 @@
C286B2695528549DC9B2916D /* af */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.strings; name = af; path = af.lproj/Localizable.strings; sourceTree = "<group>"; };
C42D117BCEADFF7368CA3159 /* bn */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.strings; name = bn; path = bn.lproj/Localizable.strings; sourceTree = "<group>"; };
C85A5C9F267A218F009BA454 /* Functions_0993.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Functions_0993.xml; sourceTree = "<group>"; };
C88FFF5D26B830E100D381D8 /* BrickObjectWithOutBackgroundProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrickObjectWithOutBackgroundProtocol.h; sourceTree = "<group>"; };
C8A0338226064F3C00702911 /* SetTempoToBrick+CBXMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "SetTempoToBrick+CBXMLHandler.swift"; path = "Catty/Views/Custom/CollectionViewCells/BrickCells/Sound/SetTempoToBrick+CBXMLHandler.swift"; sourceTree = SOURCE_ROOT; };
C8CD7DD325E63D0A0018C655 /* BrickCategoryOverviewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrickCategoryOverviewControllerTests.swift; sourceTree = "<group>"; };
C8D010C3264BD2B700896DEB /* JoinThreeStringsFunction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinThreeStringsFunction.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5610,6 +5621,7 @@
9990BB6C1D89D89A0088357A /* BrickStaticChoiceProtocol.h */,
4C1EB20F1AC19B3D0001F431 /* BrickTextProtocol.h */,
4CC0D51F1B01FB73006193C4 /* BrickVariableProtocol.h */,
C88FFF5D26B830E100D381D8 /* BrickObjectWithOutBackgroundProtocol.h */,
);
path = BrickData;
sourceTree = "<group>";
Expand Down Expand Up @@ -5965,6 +5977,7 @@
AA74EEDA1BC057B900D1E954 /* WaitBrick+CBXMLHandler.m */,
BA987D042194DDCF002DAA05 /* WaitUntilBrick+CBXMLHandler.h */,
BA987D032194DDCF002DAA05 /* WaitUntilBrick+CBXMLHandler.m */,
973F1D3126B1923F0043108A /* CloneBrick+CBXMLHandler.swift */,
);
name = Control;
path = ControlBricks;
Expand Down Expand Up @@ -6804,6 +6817,7 @@
971C6F20260526ED00AD4857 /* SetTempoToBrickTests.swift */,
83F8230725EBA9610093DD9A /* SetBackgroundByIndexBrickTests.swift */,
2E8780A72542BCE200816B52 /* WebRequestBrickTests.swift */,
9740489D26B097500047DEBB /* CloneBrickTests.swift */,
);
path = Bricks;
sourceTree = "<group>";
Expand Down Expand Up @@ -9283,6 +9297,7 @@
AA74EE1F1BC053FD00D1E954 /* BroadcastWaitBrick+Instruction.swift */,
AA74EE201BC053FD00D1E954 /* WaitBrick+Instruction.swift */,
BA987D0E2194EA1F002DAA05 /* WaitUntilBrick+Instruction.swift */,
9740489526B0547D0047DEBB /* CloneBrick+Instruction.swift */,
);
name = Control;
sourceTree = "<group>";
Expand Down Expand Up @@ -9416,6 +9431,7 @@
AA74EF951BC05B5F00D1E954 /* WaitBrick.m */,
BA987D072194E158002DAA05 /* WaitUntilBrick.h */,
BA987D062194E157002DAA05 /* WaitUntilBrick.m */,
9740488F26B04FAE0047DEBB /* CloneBrick.swift */,
);
path = Control;
sourceTree = "<group>";
Expand Down Expand Up @@ -9656,6 +9672,7 @@
9EDCD22422886FD90040EFE3 /* WaitBrickCell.swift */,
BA987D0A2194E25A002DAA05 /* WaitUntilBrickCell.h */,
BA987D092194E25A002DAA05 /* WaitUntilBrickCell.m */,
9740489326B052950047DEBB /* CloneBrickCell.swift */,
);
path = Control;
sourceTree = "<group>";
Expand Down Expand Up @@ -11448,6 +11465,7 @@
9E24D7032326E8E600608203 /* TurnLeftBrickTests.swift in Sources */,
E57E6D872540414700E775DF /* SetVolumeToBrickTests.swift in Sources */,
4C968C401F00288500355C0D /* BrickTests.swift in Sources */,
9740489E26B097500047DEBB /* CloneBrickTests.swift in Sources */,
E579F10B253D98B0009107C8 /* PhiroPlayToneBrickTests.swift in Sources */,
E579F114253DCA96009107C8 /* ThinkBubbleBrickTests.swift in Sources */,
4C0F9FD9204BD3D500E71B2D /* RepeatUntilBrickTests.swift in Sources */,
Expand Down Expand Up @@ -11783,6 +11801,7 @@
AA74F0BD1BC05FCE00D1E954 /* PlaceAtBrickCell.m in Sources */,
18390A6924D0576100A07DFD /* StampBrick.swift in Sources */,
CA3E72E81B0C00A500D6B184 /* CBStack.swift in Sources */,
9740489426B052950047DEBB /* CloneBrickCell.swift in Sources */,
AA74EFFE1BC05B5F00D1E954 /* ComeToFrontBrick.m in Sources */,
92FF31051A24DCAA00093DA7 /* WhenScript.m in Sources */,
E564EBE1255D60F5001F0CD0 /* PlayButton.swift in Sources */,
Expand All @@ -11801,17 +11820,20 @@
2D6E3F3B210A0AB700FB8139 /* ChartProjectsStoreViewController.swift in Sources */,
92FF2EA41A24C7D800093DA7 /* Util.m in Sources */,
AA74EFEC1BC05B5F00D1E954 /* ChangeVariableBrick.m in Sources */,
973F1D3226B1923F0043108A /* CloneBrick+CBXMLHandler.swift in Sources */,
92FF31031A24DCAA00093DA7 /* Script.m in Sources */,
4C822693213FBC4400F3D750 /* MultiFingerTouchedFunction.swift in Sources */,
4420ACB1250929AE00951328 /* AskBrick+CBXMLHandler.swift in Sources */,
1882475924C84D9C00B01653 /* SetPenColorBrickCell.swift in Sources */,
4C0F9F9E204BD2B100E71B2D /* SayBubbleBrickCell.m in Sources */,
4C2EE41E1B555B55006DE9B8 /* CBXMLOpenedNestingBricksStack.m in Sources */,
5EFBD5F92145533B003B3CDC /* ProjectDescriptionViewController.swift in Sources */,
9740489626B0547D0047DEBB /* CloneBrick+Instruction.swift in Sources */,
92FF31571A24DEB300093DA7 /* ObjectTableViewController.m in Sources */,
4CE3D68F2107B68600005629 /* FaceDetectionManagerProtocol.swift in Sources */,
929CC0EF1BC39B8C0027DEC0 /* PhiroMotorStopBrickCell.m in Sources */,
4C0F9F64204BD18600E71B2D /* SayForBubbleBrick+CBXMLHandler.m in Sources */,
9740489026B04FAE0047DEBB /* CloneBrick.swift in Sources */,
92FF32BB1A24E2F400093DA7 /* DarkBlueGradientImageCell.m in Sources */,
92FF314E1A24DEB300093DA7 /* LookImageViewController.m in Sources */,
AA74F0A41BC05FCE00D1E954 /* LoopEndBrickCell.m in Sources */,
Expand Down
44 changes: 44 additions & 0 deletions src/Catty/CloneBrick+Instruction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2010-2021 The Catrobat Team
* (http://developer.catrobat.org/credits)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* (http://developer.catrobat.org/license_additional_term)
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

@objc extension CloneBrick: CBInstructionProtocol {

@nonobjc func instruction() -> CBInstruction {
.action { context in SKAction.run(self.actionBlock(context.formulaInterpreter)) }
}

func actionBlock(_ formulaInterpreter: FormulaInterpreterProtocol) -> () -> Void {
guard let objectToClone = self.objectToClone
else { fatalError("This should never happen!") }

return {
let object = SpriteObject()
object.name = objectToClone.name
object.userData = objectToClone.userData
object.scriptList = objectToClone.scriptList
object.soundList = objectToClone.soundList
object.spriteNode = objectToClone.spriteNode
object.lookList = objectToClone.lookList
self.objectToClone?.scene.add(object: object)
}
}
}
78 changes: 78 additions & 0 deletions src/Catty/DataModel/Bricks/Control/CloneBrick.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (C) 2010-2021 The Catrobat Team
* (http://developer.catrobat.org/credits)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* (http://developer.catrobat.org/license_additional_term)
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

@objc(CloneBrick)
@objcMembers class CloneBrick: Brick, BrickObjectWithOutBackgroundProtocol {

var objectToClone: SpriteObject?

override required init() {
super.init()
}

func category() -> kBrickCategoryType {
kBrickCategoryType.eventBrick
}

override class func description() -> String {
"CloneBrick"
}

override func getRequiredResources() -> Int {
ResourceType.noResources.rawValue
}

override func brickCell() -> BrickCellProtocol.Type! {
CloneBrickCell.self as BrickCellProtocol.Type
}

func setObject(_ object: SpriteObject?, forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) {
if let object = object {
objectToClone = object
}
}

func object(forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) -> SpriteObject? {
self.objectToClone
}

override func setDefaultValuesFor(_ spriteObject: SpriteObject!) {
if spriteObject != nil {
objectToClone = spriteObject
} else {
objectToClone = self.script.object
}
}

override func isDisabledForBackground() -> Bool {
true
}

@objc(mutableCopyWithContext:)
override func mutableCopy(with context: CBMutableCopyContext) -> Any {
let brick = CloneBrick()
if self.objectToClone != nil {
brick.objectToClone = self.objectToClone
}
return brick
}
}
1 change: 1 addition & 0 deletions src/Catty/DataModel/Bricks/Motion/PointToBrick.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#import "Brick.h"
#import "BrickObjectProtocol.h"
#import "BrickObjectWithOutBackgroundProtocol.h"

@class SpriteObject;

Expand Down
5 changes: 5 additions & 0 deletions src/Catty/DataModel/Scene/Scene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
self._objects
}

func objectsWithoutBackground() -> [SpriteObject] {
let backgroundObjects = self.numberOfBackgroundObjects()
return [SpriteObject](self._objects[backgroundObjects...])
}

@objc(objectAtIndex:)
func object(at index: Int) -> SpriteObject? {
if index >= 0 && index < self._objects.count {
Expand Down
1 change: 1 addition & 0 deletions src/Catty/Defines/LanguageTranslationDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@
#define kLocalizedEndOfLoop NSLocalizedString(@"End of Loop", nil)
#define kLocalizedWhen NSLocalizedString(@"When", nil)
#define kLocalizedBecomesTrue NSLocalizedString(@"becomes true", nil)
#define kLocalizedCreateCloneOf NSLocalizedString(@"Create clone of", nil)

// motion bricks
#define kLocalizedPlaceAt NSLocalizedString(@"Place at ", 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 @@ -371,6 +371,7 @@ let kLocalizedTimes = NSLocalizedString("times", comment: "")
let kLocalizedEndOfLoop = NSLocalizedString("End of Loop", comment: "")
let kLocalizedWhen = NSLocalizedString("When", comment: "")
let kLocalizedBecomesTrue = NSLocalizedString("becomes true", comment: "")
let kLocalizedCreateCloneOf = NSLocalizedString("Create clone of", comment: "")

// motion bricks
let kLocalizedPlaceAt = NSLocalizedString("Place at ", comment: "")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (C) 2010-2021 The Catrobat Team
* (http://developer.catrobat.org/credits)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* (http://developer.catrobat.org/license_additional_term)
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

#import <Foundation/Foundation.h>

@class Brick;
@class SpriteObject;

@protocol BrickObjectWithOutBackgroundProtocol <BrickProtocol>

- (SpriteObject*)objectForLineNumber:(NSInteger)lineNumber andParameterNumber:(NSInteger)paramNumber;
- (void)setObject:(SpriteObject*)object forLineNumber:(NSInteger)lineNumber andParameterNumber:(NSInteger)paramNumber;

@end
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 @@ -379,6 +379,9 @@
/* No comment provided by engineer. */
"Create account" = "Create account";

/* No comment provided by engineer. */
"Create clone of" = "Create clone of";

/* No comment provided by engineer. */
"Create patterns for stiching machines" = "Create patterns for stiching machines";

Expand Down
1 change: 1 addition & 0 deletions src/Catty/Setup/CatrobatSetup+Bricks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
BroadcastBrick(),
BroadcastWaitBrick(),
WhenBackgroundChangesScript(),
CloneBrick(),
// control bricks
WaitBrick(),
IfThenLogicBeginBrick(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#import "BrickLookProtocol.h"
#import "BrickSoundProtocol.h"
#import "BrickObjectProtocol.h"
#import "BrickObjectWithOutBackgroundProtocol.h"
#import "BrickMessageProtocol.h"
#import "BrickStaticChoiceProtocol.h"
#import "BrickVariableProtocol.h"
Expand Down Expand Up @@ -1109,7 +1110,7 @@ - (void)updateBrickCellData:(id<BrickCellDataProtocol>)brickCellData withValue:(
[soundBrick setSound:[Util soundWithName:(NSString*)value forObject:self.object] forLineNumber:line andParameterNumber:parameter];
}
} else
if ([brickCellData isKindOfClass:[BrickCellObjectData class]] && [brick conformsToProtocol:@protocol(BrickObjectProtocol)]) {
if (([brickCellData isKindOfClass:[BrickCellObjectData class]] && [brick conformsToProtocol:@protocol(BrickObjectProtocol)]) || ([brickCellData isKindOfClass:[BrickCellObjectData class]] && [brick conformsToProtocol:@protocol(BrickObjectWithOutBackgroundProtocol)])) {
Brick<BrickObjectProtocol> *objectBrick = (Brick<BrickObjectProtocol>*)brick;
if([(NSString*)value isEqualToString:kLocalizedNewElement]) {
SceneTableViewController *ptvc = [self.storyboard instantiateViewControllerWithIdentifier:kSceneTableViewControllerIdentifier];
Expand All @@ -1123,7 +1124,10 @@ - (void)updateBrickCellData:(id<BrickCellDataProtocol>)brickCellData withValue:(
[self.navigationController pushViewController:ptvc animated:YES];
return;
} else {
[objectBrick setObject:[Util objectWithName:(NSString*)value forScene:self.object.scene] forLineNumber:line andParameterNumber:parameter];
if ([value isEqualToString:@"yourself"])
[objectBrick setObject:objectBrick.script.object forLineNumber:line andParameterNumber:parameter];
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)]) {
Expand Down
Loading

0 comments on commit 734157d

Please sign in to comment.