<commit_before>//
//  CommonScene.swift
//  SpriteKitAutoLayout
//
//  Created by <NAME> on 17/12/2014.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//


class CommonScene: SKScene {

    let BackButtonName = "backButton"

    func addBackButton() {
        let backButton = SKSpriteNode(imageNamed: "back")
        backButton.name = BackButtonName
        backButton.autoLayoutEnabled = true
        addChild(backButton)

        // back button
        let nodesDic = self.nodesDic()

        var format = "H:|[\(BackButtonName)(80)]"
        var constraints = NSLayoutConstraint.constraintsWithVisualFormat(format, options: .DirectionLeadingToTrailing, metrics: nil, views: nodesDic)
        self.addConstraints(constraints)
        format = "V:[\(BackButtonName)(80)]|"
        constraints = NSLayoutConstraint.constraintsWithVisualFormat(format, options: .DirectionLeadingToTrailing, metrics: nil, views: nodesDic)
        self.addConstraints(constraints)
    }

    override func didChangeSize(oldSize: CGSize) {
        layoutNodes()
    }

    #if os(iOS)
    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        let touch = touches.allObjects.first! as UITouch
        let touchLocation = touch.locationInNode(self)
        handleTouchBeganAtLocation(touchLocation)
    }
    #else
    override func mouseDown(theEvent: NSEvent) {
        var touchLocation = theEvent.locationInNode(self)
        handleTouchBeganAtLocation(CGPoint(x: touchLocation.x, y: CGRectGetHeight(self.frame) - touchLocation.y))
    }
    #endif

    func handleTouchBeganAtLocation(location: CGPoint) {
        // override in subclasses
    }

    func touchedBack(location: CGPoint) -> Bool {
        return (CGRectContainsPoint(childNodeWithName(BackButtonName)!.frame, location))
    }

    func goBack() {
        let skView = self.view! as SKView
        var scene = MainScene(size: view!.frame.size)
        scene.scaleMode = .ResizeFill
        skView.presentScene(scene)
    }
}<commit_msg>Flip touch coordinates only when required<commit_after>//
//  CommonScene.swift
//  SpriteKitAutoLayout
//
//  Created by <NAME> on 17/12/2014.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//


class CommonScene: SKScene {

    let BackButtonName = "backButton"

    func addBackButton() {
        let backButton = SKSpriteNode(imageNamed: "back")
        backButton.name = BackButtonName
        backButton.autoLayoutEnabled = true
        addChild(backButton)

        // back button
        let nodesDic = self.nodesDic()

        var format = "H:|[\(BackButtonName)(80)]"
        var constraints = NSLayoutConstraint.constraintsWithVisualFormat(format, options: .DirectionLeadingToTrailing, metrics: nil, views: nodesDic)
        self.addConstraints(constraints)
        format = "V:[\(BackButtonName)(80)]|"
        constraints = NSLayoutConstraint.constraintsWithVisualFormat(format, options: .DirectionLeadingToTrailing, metrics: nil, views: nodesDic)
        self.addConstraints(constraints)
    }

    override func didChangeSize(oldSize: CGSize) {
        layoutNodes()
    }

    #if os(iOS)
    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        let touch = touches.allObjects.first! as UITouch
        let touchLocation = touch.locationInNode(self)
        handleTouchBeganAtLocation(touchLocation)
    }
    #else
    override func mouseDown(theEvent: NSEvent) {
        var touchLocation = theEvent.locationInNode(self)
        if view!.flipped {
            touchLocation.y = CGRectGetHeight(frame) - touchLocation.y
        }
        handleTouchBeganAtLocation(touchLocation)
    }
    #endif

    func handleTouchBeganAtLocation(location: CGPoint) {
        // override in subclasses
    }

    func touchedBack(location: CGPoint) -> Bool {
        return (CGRectContainsPoint(childNodeWithName(BackButtonName)!.frame, location))
    }

    func goBack() {
        let skView = self.view! as SKView
        var scene = MainScene(size: view!.frame.size)
        scene.scaleMode = .ResizeFill
        skView.presentScene(scene)
    }
}
{'fraction_non_alphanumeric': 0.09878048780487805, 'fraction_numerical': 0.007804878048780488, 'mean_word_length': 2.9892996108949417, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7368645', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1184, 'n_words': 256}