diff --git a/src/Catty/DataModel/Bricks/Look/SetBackgroundByIndexBrick.swift b/src/Catty/DataModel/Bricks/Look/SetBackgroundByIndexBrick.swift index dd0e89f046..5ef4e99741 100644 --- a/src/Catty/DataModel/Bricks/Look/SetBackgroundByIndexBrick.swift +++ b/src/Catty/DataModel/Bricks/Look/SetBackgroundByIndexBrick.swift @@ -24,9 +24,10 @@ @objcMembers class SetBackgroundByIndexBrick: Brick, BrickProtocol, BrickFormulaProtocol { - var backgroundIndex: Formula? + var backgroundIndex: Formula override required init() { + self.backgroundIndex = Formula(integer: 1) super.init() } @@ -39,7 +40,7 @@ } override func getRequiredResources() -> Int { - backgroundIndex?.getRequiredResources() ?? ResourceType.noResources.rawValue + backgroundIndex.getRequiredResources() } override func brickCell() -> BrickCellProtocol.Type! { @@ -55,7 +56,7 @@ } func getFormulas() -> [Formula]! { - [backgroundIndex!] + [backgroundIndex] } override func setDefaultValuesFor(_ spriteObject: SpriteObject!) { diff --git a/src/Catty/DataModel/Bricks/Look/SetLookByIndexBrick.swift b/src/Catty/DataModel/Bricks/Look/SetLookByIndexBrick.swift index 3969604848..3351f9eab5 100644 --- a/src/Catty/DataModel/Bricks/Look/SetLookByIndexBrick.swift +++ b/src/Catty/DataModel/Bricks/Look/SetLookByIndexBrick.swift @@ -24,9 +24,10 @@ @objcMembers class SetLookByIndexBrick: Brick, BrickProtocol, BrickFormulaProtocol { - var lookIndex: Formula? + var lookIndex: Formula override required init() { + self.lookIndex = Formula(integer: kBackgroundObjects) super.init() } @@ -55,7 +56,7 @@ } func getFormulas() -> [Formula]! { - [lookIndex!] + [lookIndex] } override func setDefaultValuesFor(_ spriteObject: SpriteObject!) { diff --git a/src/Catty/PlayerEngine/Instructions/Look/SetBackgroundByIndexBrick+Instruction.swift b/src/Catty/PlayerEngine/Instructions/Look/SetBackgroundByIndexBrick+Instruction.swift index 67d5a8df53..dbbe60f9be 100644 --- a/src/Catty/PlayerEngine/Instructions/Look/SetBackgroundByIndexBrick+Instruction.swift +++ b/src/Catty/PlayerEngine/Instructions/Look/SetBackgroundByIndexBrick+Instruction.swift @@ -33,8 +33,7 @@ let spriteNode = object.spriteNode else { fatalError("This should never happen!") } return { - guard let backgroundIndex = self.backgroundIndex else { return } - let index = formulaInterpreter.interpretInteger(backgroundIndex, for: object) + let index = formulaInterpreter.interpretInteger(self.backgroundIndex, for: object) guard let look = spriteNode.look(for: index) else { return } var image = imageCache.cachedImage(forPath: self.path(for: look)) diff --git a/src/Catty/PlayerEngine/Instructions/Look/SetLookByIndexBrick+Instruction.swift b/src/Catty/PlayerEngine/Instructions/Look/SetLookByIndexBrick+Instruction.swift index 2230ca51e0..97385ebf3e 100644 --- a/src/Catty/PlayerEngine/Instructions/Look/SetLookByIndexBrick+Instruction.swift +++ b/src/Catty/PlayerEngine/Instructions/Look/SetLookByIndexBrick+Instruction.swift @@ -28,12 +28,11 @@ extension SetLookByIndexBrick: CBInstructionProtocol { func actionBlock(_ formulaInterpreter: FormulaInterpreterProtocol) -> () -> Void { guard let object = self.script?.object, - let spriteNode = object.spriteNode, - let formula = self.lookIndex + let spriteNode = object.spriteNode else { fatalError("This should never happen!") } return { - let lookIndex = formulaInterpreter.interpretInteger(formula, for: object) + let lookIndex = formulaInterpreter.interpretInteger(self.lookIndex, for: object) guard let lookAtIndex = spriteNode.look(for: lookIndex) else { return } let cache = RuntimeImageCache.shared() diff --git a/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetBackgroundByIndexBrick+CBXMLHandler.swift b/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetBackgroundByIndexBrick+CBXMLHandler.swift index 33d9581ab6..9885cd0f14 100644 --- a/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetBackgroundByIndexBrick+CBXMLHandler.swift +++ b/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetBackgroundByIndexBrick+CBXMLHandler.swift @@ -42,7 +42,7 @@ extension SetBackgroundByIndexBrick: CBXMLNodeProtocol { func xmlElement(with context: CBXMLSerializerContext) -> GDataXMLElement? { let brick = super.xmlElement(for: "SetBackgroundByIndexBrick", with: context) let formulaList = GDataXMLElement(name: "formulaList", context: context) - let formula = self.backgroundIndex?.xmlElement(with: context) + let formula = self.backgroundIndex.xmlElement(with: context) formula?.addAttribute(GDataXMLElement(name: "category", stringValue: "BACKGROUND_INDEX", context: nil)) formulaList?.addChild(formula, context: context) brick?.addChild(formulaList, context: context) diff --git a/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetLookByIndexBrick+CBXMLHandler.swift b/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetLookByIndexBrick+CBXMLHandler.swift index acf50344a8..544af6dd66 100644 --- a/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetLookByIndexBrick+CBXMLHandler.swift +++ b/src/Catty/XML/XMLHandler/Bricks/LookBricks/SetLookByIndexBrick+CBXMLHandler.swift @@ -26,14 +26,14 @@ extension SetLookByIndexBrick: CBXMLNodeProtocol { CBXMLParserHelper.validate(xmlElement, forNumberOfChildNodes: 1, andFormulaListWithTotalNumberOfFormulas: 1) let formula = CBXMLParserHelper.formula(in: xmlElement, forCategoryName: "LOOK_INDEX", with: context) let brick = self.init() - brick.lookIndex = formula + brick.setFormula(formula, forLineNumber: 0, andParameterNumber: 0) return brick } func xmlElement(with context: CBXMLSerializerContext) -> GDataXMLElement? { let brick = super.xmlElement(for: "SetLookByIndexBrick", with: context) let formulaList = GDataXMLElement(name: "formulaList", context: context) - let formula = self.lookIndex?.xmlElement(with: context) + let formula = self.lookIndex.xmlElement(with: context) formula?.addAttribute(GDataXMLElement(name: "category", stringValue: "LOOK_INDEX", context: nil)) formulaList?.addChild(formula, context: context) brick?.addChild(formulaList, context: context)