-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
728 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* 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 + "Copy " + String(CloneBrick.nameCounter) | ||
CloneBrick.nameCounter += 1 | ||
|
||
guard let scriptList = objectToClone.scriptList as NSMutableArray? as? [Script] else { | ||
//fatalError | ||
debugPrint("!! No script list given in object: \(objectToClone) !!") | ||
return | ||
} | ||
|
||
for script in scriptList { | ||
switch script { | ||
case let startScript as StartScript: | ||
let newStartScript = StartScript() | ||
newStartScript.object = object | ||
newStartScript.brickList = startScript.brickList.mutableCopy() as? NSMutableArray | ||
for brick in newStartScript.brickList { | ||
(brick as! Brick).script = newStartScript as Script | ||
} | ||
object.scriptList.add(newStartScript) | ||
|
||
case let whenScript as WhenScript: | ||
let newWhenScript = WhenScript() | ||
newWhenScript.object = object | ||
newWhenScript.brickList = whenScript.brickList.mutableCopy() as? NSMutableArray | ||
for brick in newWhenScript.brickList { | ||
(brick as! Brick).script = newWhenScript as Script | ||
} | ||
object.scriptList.add(newWhenScript) | ||
|
||
case let whenTouchDownScript as WhenTouchDownScript: | ||
let newWhenTouchDownScript = WhenTouchDownScript() | ||
newWhenTouchDownScript.object = object | ||
newWhenTouchDownScript.brickList = whenTouchDownScript.brickList.mutableCopy() as? NSMutableArray | ||
for brick in newWhenTouchDownScript.brickList { | ||
(brick as! Brick).script = newWhenTouchDownScript as Script | ||
} | ||
object.scriptList.add(newWhenTouchDownScript) | ||
|
||
case let whenBackgroundChangesScript as WhenBackgroundChangesScript: | ||
let newWhenBackgroundChangesScript = WhenBackgroundChangesScript() | ||
newWhenBackgroundChangesScript.object = object | ||
newWhenBackgroundChangesScript.brickList = whenBackgroundChangesScript.brickList.mutableCopy() as? NSMutableArray | ||
for brick in newWhenBackgroundChangesScript.brickList { | ||
(brick as! Brick).script = newWhenBackgroundChangesScript as Script | ||
} | ||
object.scriptList.add(newWhenBackgroundChangesScript) | ||
|
||
case let bcScript as BroadcastScript: | ||
let newBcScript = BroadcastScript() | ||
newBcScript.object = object | ||
newBcScript.brickList = bcScript.brickList.mutableCopy() as? NSMutableArray | ||
for brick in newBcScript.brickList { | ||
(brick as! Brick).script = newBcScript as Script | ||
} | ||
object.scriptList.add(newBcScript) | ||
|
||
case let whenConditionScript as WhenConditionScript: | ||
let newWhenConditionScript = WhenConditionScript() | ||
newWhenConditionScript.object = object | ||
newWhenConditionScript.brickList = whenConditionScript.brickList.mutableCopy() as? NSMutableArray | ||
for brick in newWhenConditionScript.brickList { | ||
(brick as! Brick).script = newWhenConditionScript as Script | ||
} | ||
object.scriptList.add(newWhenConditionScript) | ||
|
||
default: | ||
break | ||
} | ||
} | ||
|
||
object.soundList = objectToClone.soundList.mutableCopy() as? NSMutableArray | ||
object.lookList = objectToClone.lookList.mutableCopy() as? NSMutableArray | ||
|
||
let variables = UserDataContainer.objectVariables(for: objectToClone) | ||
let lists = UserDataContainer.objectLists(for: objectToClone) | ||
|
||
for variable in variables { | ||
let var1 = variable as UserVariable | ||
object.userData.add(var1) | ||
} | ||
for list in lists { | ||
let list1 = list as UserList | ||
object.userData.add(list1) | ||
} | ||
|
||
objectToClone.scene.add(object: object) | ||
let spriteNode = CBSpriteNode(spriteObject: object) | ||
object.spriteNode = spriteNode | ||
|
||
let stage = objectToClone.spriteNode.scene as? Stage | ||
stage?.addChild(object.spriteNode) | ||
object.spriteNode.startAsCopy(objectToClone.spriteNode) | ||
stage?.scheduler.registerSpriteNode(object.spriteNode) | ||
stage?.addCopiedObjecToProject(spriteObject: object) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* 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? | ||
static var nameCounter: Int = 1 | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.