-
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.
CATTY-369 Implement place visually feature
- Loading branch information
Showing
51 changed files
with
1,156 additions
and
675 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
60 changes: 60 additions & 0 deletions
60
src/Catty/DataModel/Bricks/Motion/GlideToBrick+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,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/. | ||
*/ | ||
|
||
extension GlideToBrick: CBXMLNodeProtocol { | ||
static func parse(from xmlElement: GDataXMLElement!, with context: CBXMLParserContext!) -> Self! { | ||
CBXMLParserHelper.validate(xmlElement, forNumberOfChildNodes: 1, andFormulaListWithTotalNumberOfFormulas: 3) | ||
|
||
let glideToBrick = self.init() | ||
if let formulaDuration = CBXMLParserHelper.formula(in: xmlElement, forCategoryName: "DURATION_IN_SECONDS", with: context) { | ||
glideToBrick.durationInSeconds = formulaDuration | ||
} | ||
if let formulaXDestination = CBXMLParserHelper.formula(in: xmlElement, forCategoryName: "X_DESTINATION", with: context) { | ||
glideToBrick.xPosition = formulaXDestination | ||
} | ||
if let formulaYDestination = CBXMLParserHelper.formula(in: xmlElement, forCategoryName: "Y_DESTINATION", with: context) { | ||
glideToBrick.yPosition = formulaYDestination | ||
} | ||
|
||
return glideToBrick | ||
} | ||
|
||
func xmlElement(with context: CBXMLSerializerContext!) -> GDataXMLElement! { | ||
let brick = super.xmlElement(for: "GlideToBrick", with: context) | ||
let formulaList = GDataXMLElement(name: "formulaList", context: context) | ||
|
||
var formula = self.durationInSeconds.xmlElement(with: context) | ||
formula?.addAttribute(GDataXMLElement.attribute(withName: "category", escapedStringValue: "DURATION_IN_SECONDS") as? GDataXMLNode) | ||
formulaList?.addChild(formula, context: context) | ||
|
||
formula = self.yPosition.xmlElement(with: context) | ||
formula?.addAttribute(GDataXMLElement.attribute(withName: "category", escapedStringValue: "Y_DESTINATION") as? GDataXMLNode) | ||
formulaList?.addChild(formula, context: context) | ||
|
||
formula = self.xPosition.xmlElement(with: context) | ||
formula?.addAttribute(GDataXMLElement.attribute(withName: "category", escapedStringValue: "X_DESTINATION") as? GDataXMLNode) | ||
formulaList?.addChild(formula, context: context) | ||
|
||
brick?.addChild(formulaList, context: context) | ||
return brick | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,102 @@ | ||
/** | ||
* 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(GlideToBrick) | ||
@objcMembers class GlideToBrick: Brick, BrickVisualPlacementProtocol { | ||
var durationInSeconds: Formula | ||
var xPosition: Formula | ||
var yPosition: Formula | ||
|
||
override required init() { | ||
self.durationInSeconds = Formula(integer: 1) | ||
self.xPosition = Formula(integer: 100) | ||
self.yPosition = Formula(integer: 200) | ||
super.init() | ||
} | ||
|
||
func category() -> kBrickCategoryType { | ||
kBrickCategoryType.motionBrick | ||
} | ||
|
||
func formula(forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) -> Formula? { | ||
if lineNumber == 0 && paramNumber == 0 { | ||
return self.durationInSeconds | ||
} else if lineNumber == 1 && paramNumber == 0 { | ||
return self.xPosition | ||
} else if lineNumber == 1 && paramNumber == 1 { | ||
return self.yPosition | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func setFormula(_ formula: Formula, forLineNumber lineNumber: Int, andParameterNumber paramNumber: Int) { | ||
if lineNumber == 0 && paramNumber == 0 { | ||
self.durationInSeconds = formula | ||
} else if lineNumber == 1 && paramNumber == 0 { | ||
self.xPosition = formula | ||
} else if lineNumber == 1 && paramNumber == 1 { | ||
self.yPosition = formula | ||
} | ||
} | ||
|
||
func getFormulas() -> [Formula] { | ||
[self.durationInSeconds, self.xPosition, self.yPosition] | ||
} | ||
|
||
func allowsStringFormula() -> Bool { | ||
false | ||
} | ||
|
||
override func setDefaultValuesFor(_ spriteObject: SpriteObject!) { | ||
self.durationInSeconds = Formula(integer: 1) | ||
self.xPosition = Formula(integer: 100) | ||
self.yPosition = Formula(integer: 200) | ||
} | ||
|
||
override func description() -> String! { | ||
"GlideToBrick" | ||
} | ||
|
||
override func isEqual(to brick: Brick!) -> Bool { | ||
if brick is GlideToBrick { | ||
let glideToBrick = brick as! GlideToBrick | ||
return self.durationInSeconds.isEqual(to: glideToBrick.durationInSeconds) && | ||
self.xPosition.isEqual(to: glideToBrick.xPosition) && | ||
self.yPosition.isEqual(to: glideToBrick.yPosition) | ||
} | ||
return false | ||
} | ||
|
||
func isVisualPlacementFormula(_ formula: Formula) -> Bool { | ||
(formula.isEqual(to: xPosition) || formula.isEqual(to: yPosition)) && | ||
doVisualPlacementBrickCellsContainOnlyValues() | ||
} | ||
|
||
func doVisualPlacementBrickCellsContainOnlyValues() -> Bool { | ||
xPosition.formulaTree.isSingleNumberFormula() && yPosition.formulaTree.isSingleNumberFormula() | ||
} | ||
|
||
override func getRequiredResources() -> Int { | ||
durationInSeconds.getRequiredResources() | xPosition.getRequiredResources() | yPosition.getRequiredResources() | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/Catty/DataModel/Bricks/Motion/PlaceAtBrick+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,54 @@ | ||
/** | ||
* 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 PlaceAtBrick: CBXMLNodeProtocol { | ||
static func parse(from xmlElement: GDataXMLElement!, with context: CBXMLParserContext!) -> Self! { | ||
|
||
CBXMLParserHelper.validate(xmlElement, forNumberOfChildNodes: 1, andFormulaListWithTotalNumberOfFormulas: 2) | ||
|
||
let placeAtBrick = self.init() | ||
if let formulaXPosition = CBXMLParserHelper.formula(in: xmlElement, forCategoryName: "X_POSITION", with: context) { | ||
placeAtBrick.xPosition = formulaXPosition | ||
} | ||
if let formulaYPostion = CBXMLParserHelper.formula(in: xmlElement, forCategoryName: "Y_POSITION", with: context) { | ||
placeAtBrick.yPosition = formulaYPostion | ||
} | ||
return placeAtBrick | ||
} | ||
|
||
func xmlElement(with context: CBXMLSerializerContext) -> GDataXMLElement? { | ||
let brick = super.xmlElement(for: "PlaceAtBrick", with: context) | ||
let formulaList = GDataXMLElement(name: "formulaList", context: context) | ||
|
||
var formula = self.yPosition.xmlElement(with: context) | ||
formula?.addAttribute(GDataXMLElement.attribute(withName: "category", escapedStringValue: "Y_POSITION") as? GDataXMLNode) | ||
formulaList?.addChild(formula, context: context) | ||
|
||
formula = self.xPosition.xmlElement(with: context) | ||
formula?.addAttribute(GDataXMLElement.attribute(withName: "category", escapedStringValue: "X_POSITION") as? GDataXMLNode) | ||
formulaList?.addChild(formula, context: context) | ||
|
||
brick?.addChild(formulaList, context: context) | ||
return brick | ||
} | ||
|
||
} |
Oops, something went wrong.