-
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
1 parent
757c7c5
commit c5d2db6
Showing
16 changed files
with
384 additions
and
8 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,60 @@ | ||
/** | ||
* Copyright (C) 2010-2022 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(StopScriptBrick) class StopScriptBrick: Brick, BrickProtocol, BrickStaticChoiceProtocol { | ||
static let defaultSelection = StopStyle.thisScript | ||
var question: Formula? | ||
var selection: StopStyle | ||
|
||
override required init() { | ||
self.selection = type(of: self).defaultSelection | ||
super.init() | ||
} | ||
|
||
func category() -> kBrickCategoryType { | ||
kBrickCategoryType.controlBrick | ||
} | ||
|
||
override func description() -> String { | ||
"StopScriptBrick" | ||
} | ||
|
||
override func getRequiredResources() -> Int { | ||
ResourceType.noResources.rawValue | ||
} | ||
|
||
override func brickCell() -> BrickCellProtocol.Type! { | ||
StopScriptBrickCell.self as BrickCellProtocol.Type | ||
} | ||
|
||
func choice(forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) -> String { | ||
selection.localizedString() | ||
} | ||
|
||
func setChoice(_ message: String, forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) { | ||
self.selection = StopStyle.from(localizedString: message) ?? type(of: self).defaultSelection | ||
} | ||
|
||
func possibleChoices(forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) -> [String] { | ||
StopStyle.allCases.map { $0.localizedString() } | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Catty/DataModel/SpriteObject/StopScriptBrick+CBXMLHandler.swift
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,55 @@ | ||
/** | ||
* Copyright (C) 2010-2022 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/. | ||
*/ | ||
|
||
extension StopScriptBrick: CBXMLNodeProtocol { | ||
static func parse(from xmlElement: GDataXMLElement!, with context: CBXMLParserContext!) -> Self! { | ||
CBXMLParserHelper.validate(xmlElement, forNumberOfChildNodes: 1) | ||
let brick = self.init() | ||
|
||
let brickType = xmlElement.attribute(forName: "type") | ||
|
||
if brickType?.stringValue() == "StopScriptBrick" { | ||
if let selection: GDataXMLElement = xmlElement.child(withElementName: "selection") { | ||
if let choiceInt = Int(selection.stringValue()), let selection = StopStyle.from(rawValue: choiceInt) { | ||
brick.selection = selection | ||
} else { | ||
fatalError("No or invalid selectionChoice given...") | ||
} | ||
} else { | ||
fatalError("StopStyleBrick element does not contain a selection child element!") | ||
} | ||
} else { | ||
fatalError("StopStyleBrick is faulty!") | ||
} | ||
|
||
return brick | ||
} | ||
|
||
func xmlElement(with context: CBXMLSerializerContext) -> GDataXMLElement? { | ||
let brick = super.xmlElement(for: "StopScriptBrick", with: context) | ||
let numberString = String(format: "%i", arguments: [self.selection.rawValue]) | ||
let selection = GDataXMLElement(name: "selection", stringValue: numberString, context: context) | ||
|
||
brick?.addChild(selection, context: context) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (C) 2010-2022 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/. | ||
*/ | ||
|
||
enum StopStyle: Int, CaseIterable { | ||
case thisScript = 0 | ||
case allScripts = 1 | ||
case otherScripts = 2 | ||
|
||
//TODO use kLocalizedLeftRight | ||
func localizedString() -> String { | ||
switch self { | ||
case .thisScript: | ||
return "this script" | ||
case .allScripts: | ||
return "all scripts" | ||
case .otherScripts: | ||
return "other scripts of this actor or object" | ||
} | ||
} | ||
|
||
static func from(rawValue: Int) -> StopStyle? { | ||
for style in StopStyle.allCases where style.rawValue == rawValue { | ||
return style | ||
} | ||
return nil | ||
} | ||
|
||
static func from(localizedString: String) -> StopStyle? { | ||
for style in StopStyle.allCases where style.localizedString() == localizedString { | ||
return style | ||
} | ||
return nil | ||
} | ||
} |
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
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
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,38 @@ | ||
/** | ||
* Copyright (C) 2010-2022 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 StopScriptBrick: CBInstructionProtocol { | ||
|
||
@nonobjc func instruction() -> CBInstruction { | ||
CBInstruction.execClosure { context, scheduler in | ||
switch self.selection { | ||
case .thisScript: | ||
scheduler.stopContext(context, continueWaitingBroadcastSenders: false) | ||
case .allScripts: | ||
scheduler.stopAllScripts() | ||
case .otherScripts: | ||
scheduler.stopAllOtherScripts(context) | ||
scheduler.runNextInstructionOfContext(context) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.