Skip to content

Commit 734157d

Browse files
author
amelak9
committed
CATTY-552 Clone object or actor
1 parent dce344b commit 734157d

File tree

20 files changed

+503
-6
lines changed

20 files changed

+503
-6
lines changed

src/Catty.xcodeproj/project.pbxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,11 @@
11911191
972622DD25F51A8F00ABCC7A /* ChangeBrightnessByNBrick+CBXMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 972622DC25F51A8F00ABCC7A /* ChangeBrightnessByNBrick+CBXMLHandler.swift */; };
11921192
972622E225F51B4500ABCC7A /* SetBrightnessBrick+CBXMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 972622E125F51B4500ABCC7A /* SetBrightnessBrick+CBXMLHandler.swift */; };
11931193
9728AE9E25DEEE5A00708EB6 /* ProjectDetailStoreViewControllerReportExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9728AE9D25DEEE5A00708EB6 /* ProjectDetailStoreViewControllerReportExtension.swift */; };
1194+
973F1D3226B1923F0043108A /* CloneBrick+CBXMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973F1D3126B1923F0043108A /* CloneBrick+CBXMLHandler.swift */; };
1195+
9740489026B04FAE0047DEBB /* CloneBrick.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740488F26B04FAE0047DEBB /* CloneBrick.swift */; };
1196+
9740489426B052950047DEBB /* CloneBrickCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740489326B052950047DEBB /* CloneBrickCell.swift */; };
1197+
9740489626B0547D0047DEBB /* CloneBrick+Instruction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740489526B0547D0047DEBB /* CloneBrick+Instruction.swift */; };
1198+
9740489E26B097500047DEBB /* CloneBrickTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9740489D26B097500047DEBB /* CloneBrickTests.swift */; };
11941199
97417A9B265284400079A2A2 /* SoundsTableViewController+SelectFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97417A9A265284400079A2A2 /* SoundsTableViewController+SelectFile.swift */; };
11951200
9767BAFA26668ECD009794E8 /* JoinThreeStringsFunctionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9767BAF926668ECD009794E8 /* JoinThreeStringsFunctionTest.swift */; };
11961201
97770B8825E5A88C00F51EFA /* SetBrightnessBrick.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97770B8725E5A88C00F51EFA /* SetBrightnessBrick.swift */; };
@@ -3336,6 +3341,11 @@
33363341
972622DC25F51A8F00ABCC7A /* ChangeBrightnessByNBrick+CBXMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChangeBrightnessByNBrick+CBXMLHandler.swift"; sourceTree = "<group>"; };
33373342
972622E125F51B4500ABCC7A /* SetBrightnessBrick+CBXMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SetBrightnessBrick+CBXMLHandler.swift"; sourceTree = "<group>"; };
33383343
9728AE9D25DEEE5A00708EB6 /* ProjectDetailStoreViewControllerReportExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectDetailStoreViewControllerReportExtension.swift; sourceTree = "<group>"; };
3344+
973F1D3126B1923F0043108A /* CloneBrick+CBXMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "CloneBrick+CBXMLHandler.swift"; path = "CattyTests/Bricks/CloneBrick+CBXMLHandler.swift"; sourceTree = SOURCE_ROOT; };
3345+
9740488F26B04FAE0047DEBB /* CloneBrick.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloneBrick.swift; sourceTree = "<group>"; };
3346+
9740489326B052950047DEBB /* CloneBrickCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloneBrickCell.swift; sourceTree = "<group>"; };
3347+
9740489526B0547D0047DEBB /* CloneBrick+Instruction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CloneBrick+Instruction.swift"; sourceTree = "<group>"; };
3348+
9740489D26B097500047DEBB /* CloneBrickTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloneBrickTests.swift; sourceTree = "<group>"; };
33393349
97417A9A265284400079A2A2 /* SoundsTableViewController+SelectFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SoundsTableViewController+SelectFile.swift"; sourceTree = "<group>"; };
33403350
9767BAF926668ECD009794E8 /* JoinThreeStringsFunctionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinThreeStringsFunctionTest.swift; sourceTree = "<group>"; };
33413351
97770B8725E5A88C00F51EFA /* SetBrightnessBrick.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetBrightnessBrick.swift; sourceTree = "<group>"; };
@@ -3994,6 +4004,7 @@
39944004
C286B2695528549DC9B2916D /* af */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.strings; name = af; path = af.lproj/Localizable.strings; sourceTree = "<group>"; };
39954005
C42D117BCEADFF7368CA3159 /* bn */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.strings; name = bn; path = bn.lproj/Localizable.strings; sourceTree = "<group>"; };
39964006
C85A5C9F267A218F009BA454 /* Functions_0993.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Functions_0993.xml; sourceTree = "<group>"; };
4007+
C88FFF5D26B830E100D381D8 /* BrickObjectWithOutBackgroundProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrickObjectWithOutBackgroundProtocol.h; sourceTree = "<group>"; };
39974008
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; };
39984009
C8CD7DD325E63D0A0018C655 /* BrickCategoryOverviewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrickCategoryOverviewControllerTests.swift; sourceTree = "<group>"; };
39994010
C8D010C3264BD2B700896DEB /* JoinThreeStringsFunction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinThreeStringsFunction.swift; sourceTree = "<group>"; };
@@ -5610,6 +5621,7 @@
56105621
9990BB6C1D89D89A0088357A /* BrickStaticChoiceProtocol.h */,
56115622
4C1EB20F1AC19B3D0001F431 /* BrickTextProtocol.h */,
56125623
4CC0D51F1B01FB73006193C4 /* BrickVariableProtocol.h */,
5624+
C88FFF5D26B830E100D381D8 /* BrickObjectWithOutBackgroundProtocol.h */,
56135625
);
56145626
path = BrickData;
56155627
sourceTree = "<group>";
@@ -5965,6 +5977,7 @@
59655977
AA74EEDA1BC057B900D1E954 /* WaitBrick+CBXMLHandler.m */,
59665978
BA987D042194DDCF002DAA05 /* WaitUntilBrick+CBXMLHandler.h */,
59675979
BA987D032194DDCF002DAA05 /* WaitUntilBrick+CBXMLHandler.m */,
5980+
973F1D3126B1923F0043108A /* CloneBrick+CBXMLHandler.swift */,
59685981
);
59695982
name = Control;
59705983
path = ControlBricks;
@@ -6804,6 +6817,7 @@
68046817
971C6F20260526ED00AD4857 /* SetTempoToBrickTests.swift */,
68056818
83F8230725EBA9610093DD9A /* SetBackgroundByIndexBrickTests.swift */,
68066819
2E8780A72542BCE200816B52 /* WebRequestBrickTests.swift */,
6820+
9740489D26B097500047DEBB /* CloneBrickTests.swift */,
68076821
);
68086822
path = Bricks;
68096823
sourceTree = "<group>";
@@ -9283,6 +9297,7 @@
92839297
AA74EE1F1BC053FD00D1E954 /* BroadcastWaitBrick+Instruction.swift */,
92849298
AA74EE201BC053FD00D1E954 /* WaitBrick+Instruction.swift */,
92859299
BA987D0E2194EA1F002DAA05 /* WaitUntilBrick+Instruction.swift */,
9300+
9740489526B0547D0047DEBB /* CloneBrick+Instruction.swift */,
92869301
);
92879302
name = Control;
92889303
sourceTree = "<group>";
@@ -9416,6 +9431,7 @@
94169431
AA74EF951BC05B5F00D1E954 /* WaitBrick.m */,
94179432
BA987D072194E158002DAA05 /* WaitUntilBrick.h */,
94189433
BA987D062194E157002DAA05 /* WaitUntilBrick.m */,
9434+
9740488F26B04FAE0047DEBB /* CloneBrick.swift */,
94199435
);
94209436
path = Control;
94219437
sourceTree = "<group>";
@@ -9656,6 +9672,7 @@
96569672
9EDCD22422886FD90040EFE3 /* WaitBrickCell.swift */,
96579673
BA987D0A2194E25A002DAA05 /* WaitUntilBrickCell.h */,
96589674
BA987D092194E25A002DAA05 /* WaitUntilBrickCell.m */,
9675+
9740489326B052950047DEBB /* CloneBrickCell.swift */,
96599676
);
96609677
path = Control;
96619678
sourceTree = "<group>";
@@ -11448,6 +11465,7 @@
1144811465
9E24D7032326E8E600608203 /* TurnLeftBrickTests.swift in Sources */,
1144911466
E57E6D872540414700E775DF /* SetVolumeToBrickTests.swift in Sources */,
1145011467
4C968C401F00288500355C0D /* BrickTests.swift in Sources */,
11468+
9740489E26B097500047DEBB /* CloneBrickTests.swift in Sources */,
1145111469
E579F10B253D98B0009107C8 /* PhiroPlayToneBrickTests.swift in Sources */,
1145211470
E579F114253DCA96009107C8 /* ThinkBubbleBrickTests.swift in Sources */,
1145311471
4C0F9FD9204BD3D500E71B2D /* RepeatUntilBrickTests.swift in Sources */,
@@ -11783,6 +11801,7 @@
1178311801
AA74F0BD1BC05FCE00D1E954 /* PlaceAtBrickCell.m in Sources */,
1178411802
18390A6924D0576100A07DFD /* StampBrick.swift in Sources */,
1178511803
CA3E72E81B0C00A500D6B184 /* CBStack.swift in Sources */,
11804+
9740489426B052950047DEBB /* CloneBrickCell.swift in Sources */,
1178611805
AA74EFFE1BC05B5F00D1E954 /* ComeToFrontBrick.m in Sources */,
1178711806
92FF31051A24DCAA00093DA7 /* WhenScript.m in Sources */,
1178811807
E564EBE1255D60F5001F0CD0 /* PlayButton.swift in Sources */,
@@ -11801,17 +11820,20 @@
1180111820
2D6E3F3B210A0AB700FB8139 /* ChartProjectsStoreViewController.swift in Sources */,
1180211821
92FF2EA41A24C7D800093DA7 /* Util.m in Sources */,
1180311822
AA74EFEC1BC05B5F00D1E954 /* ChangeVariableBrick.m in Sources */,
11823+
973F1D3226B1923F0043108A /* CloneBrick+CBXMLHandler.swift in Sources */,
1180411824
92FF31031A24DCAA00093DA7 /* Script.m in Sources */,
1180511825
4C822693213FBC4400F3D750 /* MultiFingerTouchedFunction.swift in Sources */,
1180611826
4420ACB1250929AE00951328 /* AskBrick+CBXMLHandler.swift in Sources */,
1180711827
1882475924C84D9C00B01653 /* SetPenColorBrickCell.swift in Sources */,
1180811828
4C0F9F9E204BD2B100E71B2D /* SayBubbleBrickCell.m in Sources */,
1180911829
4C2EE41E1B555B55006DE9B8 /* CBXMLOpenedNestingBricksStack.m in Sources */,
1181011830
5EFBD5F92145533B003B3CDC /* ProjectDescriptionViewController.swift in Sources */,
11831+
9740489626B0547D0047DEBB /* CloneBrick+Instruction.swift in Sources */,
1181111832
92FF31571A24DEB300093DA7 /* ObjectTableViewController.m in Sources */,
1181211833
4CE3D68F2107B68600005629 /* FaceDetectionManagerProtocol.swift in Sources */,
1181311834
929CC0EF1BC39B8C0027DEC0 /* PhiroMotorStopBrickCell.m in Sources */,
1181411835
4C0F9F64204BD18600E71B2D /* SayForBubbleBrick+CBXMLHandler.m in Sources */,
11836+
9740489026B04FAE0047DEBB /* CloneBrick.swift in Sources */,
1181511837
92FF32BB1A24E2F400093DA7 /* DarkBlueGradientImageCell.m in Sources */,
1181611838
92FF314E1A24DEB300093DA7 /* LookImageViewController.m in Sources */,
1181711839
AA74F0A41BC05FCE00D1E954 /* LoopEndBrickCell.m in Sources */,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (C) 2010-2021 The Catrobat Team
3+
* (http://developer.catrobat.org/credits)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* An additional term exception under section 7 of the GNU Affero
11+
* General Public License, version 3, is available at
12+
* (http://developer.catrobat.org/license_additional_term)
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see http://www.gnu.org/licenses/.
21+
*/
22+
23+
@objc extension CloneBrick: CBInstructionProtocol {
24+
25+
@nonobjc func instruction() -> CBInstruction {
26+
.action { context in SKAction.run(self.actionBlock(context.formulaInterpreter)) }
27+
}
28+
29+
func actionBlock(_ formulaInterpreter: FormulaInterpreterProtocol) -> () -> Void {
30+
guard let objectToClone = self.objectToClone
31+
else { fatalError("This should never happen!") }
32+
33+
return {
34+
let object = SpriteObject()
35+
object.name = objectToClone.name
36+
object.userData = objectToClone.userData
37+
object.scriptList = objectToClone.scriptList
38+
object.soundList = objectToClone.soundList
39+
object.spriteNode = objectToClone.spriteNode
40+
object.lookList = objectToClone.lookList
41+
self.objectToClone?.scene.add(object: object)
42+
}
43+
}
44+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (C) 2010-2021 The Catrobat Team
3+
* (http://developer.catrobat.org/credits)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* An additional term exception under section 7 of the GNU Affero
11+
* General Public License, version 3, is available at
12+
* (http://developer.catrobat.org/license_additional_term)
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see http://www.gnu.org/licenses/.
21+
*/
22+
23+
@objc(CloneBrick)
24+
@objcMembers class CloneBrick: Brick, BrickObjectWithOutBackgroundProtocol {
25+
26+
var objectToClone: SpriteObject?
27+
28+
override required init() {
29+
super.init()
30+
}
31+
32+
func category() -> kBrickCategoryType {
33+
kBrickCategoryType.eventBrick
34+
}
35+
36+
override class func description() -> String {
37+
"CloneBrick"
38+
}
39+
40+
override func getRequiredResources() -> Int {
41+
ResourceType.noResources.rawValue
42+
}
43+
44+
override func brickCell() -> BrickCellProtocol.Type! {
45+
CloneBrickCell.self as BrickCellProtocol.Type
46+
}
47+
48+
func setObject(_ object: SpriteObject?, forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) {
49+
if let object = object {
50+
objectToClone = object
51+
}
52+
}
53+
54+
func object(forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) -> SpriteObject? {
55+
self.objectToClone
56+
}
57+
58+
override func setDefaultValuesFor(_ spriteObject: SpriteObject!) {
59+
if spriteObject != nil {
60+
objectToClone = spriteObject
61+
} else {
62+
objectToClone = self.script.object
63+
}
64+
}
65+
66+
override func isDisabledForBackground() -> Bool {
67+
true
68+
}
69+
70+
@objc(mutableCopyWithContext:)
71+
override func mutableCopy(with context: CBMutableCopyContext) -> Any {
72+
let brick = CloneBrick()
73+
if self.objectToClone != nil {
74+
brick.objectToClone = self.objectToClone
75+
}
76+
return brick
77+
}
78+
}

src/Catty/DataModel/Bricks/Motion/PointToBrick.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#import "Brick.h"
2525
#import "BrickObjectProtocol.h"
26+
#import "BrickObjectWithOutBackgroundProtocol.h"
2627

2728
@class SpriteObject;
2829

src/Catty/DataModel/Scene/Scene.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
self._objects
7979
}
8080

81+
func objectsWithoutBackground() -> [SpriteObject] {
82+
let backgroundObjects = self.numberOfBackgroundObjects()
83+
return [SpriteObject](self._objects[backgroundObjects...])
84+
}
85+
8186
@objc(objectAtIndex:)
8287
func object(at index: Int) -> SpriteObject? {
8388
if index >= 0 && index < self._objects.count {

src/Catty/Defines/LanguageTranslationDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@
371371
#define kLocalizedEndOfLoop NSLocalizedString(@"End of Loop", nil)
372372
#define kLocalizedWhen NSLocalizedString(@"When", nil)
373373
#define kLocalizedBecomesTrue NSLocalizedString(@"becomes true", nil)
374+
#define kLocalizedCreateCloneOf NSLocalizedString(@"Create clone of", nil)
374375

375376
// motion bricks
376377
#define kLocalizedPlaceAt NSLocalizedString(@"Place at ", nil)

src/Catty/Defines/LanguageTranslationDefinesSwift.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ let kLocalizedTimes = NSLocalizedString("times", comment: "")
371371
let kLocalizedEndOfLoop = NSLocalizedString("End of Loop", comment: "")
372372
let kLocalizedWhen = NSLocalizedString("When", comment: "")
373373
let kLocalizedBecomesTrue = NSLocalizedString("becomes true", comment: "")
374+
let kLocalizedCreateCloneOf = NSLocalizedString("Create clone of", comment: "")
374375

375376
// motion bricks
376377
let kLocalizedPlaceAt = NSLocalizedString("Place at ", comment: "")
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (C) 2010-2021 The Catrobat Team
3+
* (http://developer.catrobat.org/credits)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* An additional term exception under section 7 of the GNU Affero
11+
* General Public License, version 3, is available at
12+
* (http://developer.catrobat.org/license_additional_term)
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see http://www.gnu.org/licenses/.
21+
*/
22+
23+
#import <Foundation/Foundation.h>
24+
25+
@class Brick;
26+
@class SpriteObject;
27+
28+
@protocol BrickObjectWithOutBackgroundProtocol <BrickProtocol>
29+
30+
- (SpriteObject*)objectForLineNumber:(NSInteger)lineNumber andParameterNumber:(NSInteger)paramNumber;
31+
- (void)setObject:(SpriteObject*)object forLineNumber:(NSInteger)lineNumber andParameterNumber:(NSInteger)paramNumber;
32+
33+
@end

src/Catty/Resources/Localization/en.lproj/Localizable.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@
379379
/* No comment provided by engineer. */
380380
"Create account" = "Create account";
381381

382+
/* No comment provided by engineer. */
383+
"Create clone of" = "Create clone of";
384+
382385
/* No comment provided by engineer. */
383386
"Create patterns for stiching machines" = "Create patterns for stiching machines";
384387

src/Catty/Setup/CatrobatSetup+Bricks.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
BroadcastBrick(),
3434
BroadcastWaitBrick(),
3535
WhenBackgroundChangesScript(),
36+
CloneBrick(),
3637
// control bricks
3738
WaitBrick(),
3839
IfThenLogicBeginBrick(),

0 commit comments

Comments
 (0)