<commit_before>//
//  GameScene.swift
//  SOPA
//
//  Created by <NAME> on 21.10.17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import SpriteKit
import GameplayKit

class GameScene: SKScene {
    var level: Level
    let gameFieldNode = SKNode()
    let startEndNode = SKNode()
    let puzzlesNode = SKNode()
    let gameFieldService = GameFieldService()
    let MIN_MOVE = CGFloat(30)
    var tileSize: CGFloat?
    var levelSolved = false
    
    init(size: CGSize, level: Level) {
        self.level = level
        super.init(size: size)
        initNodes()
    }
    
    func initNodes() {
        gameFieldNode.addChild(startEndNode)
        gameFieldNode.addChild(puzzlesNode)
        puzzlesNode.zPosition = -1
        addChild(gameFieldNode)
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func didMove(to view: SKView) {
        updateGameField()
    }
    
    func rotateStartAndFinishTile(tile: SKSpriteNode, column: Int, row: Int, columns: Int, rows: Int) {
        if (row == 0) {
            // TOP
            tile.zRotation = -CGFloat(Double.pi) / 2
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
            
        } else if (column == 0) {
            // LEFT
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
            
        } else if (row == rows - 1) {
            // BOTTOM
            tile.zRotation = -(CGFloat(Double.pi) / 2) * 3
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
            
        } else if (column == columns - 1) {
            // RIGHT
            tile.zRotation = CGFloat(Double.pi)
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
        }
    }
    func toBorders(value: Int, from: Int, to: Int) -> Int {
        if value < from {
            return from
        }
        if value > to {
            return to
        }
        return value
    }
    
    func updateGameField() {
        puzzlesNode.removeAllChildren()
        startEndNode.removeAllChildren()
        let columns = level.tiles.count
        let rows = level.tiles[0].count
        tileSize = size.width / CGFloat(level.tiles.count - 2)
        for column in 0...columns - 1 {
            for row in 0...rows - 1 {
                addTile(column: column, row: row, columns: columns, rows: rows)
            }
        }
        if(gameFieldService.solvedPuzzle(level: level)) {
            levelSolved = true
            print("Level Solved")
        }
    }
    func addTile(column: Int, row: Int, columns: Int, rows: Int) {
        let tile = level.tiles[column][row]
        let shortcut = tile.shortcut
        let tileType = tile.tileType
        
        if (shortcut != "n") {
            let tileNode = TileSpriteNode(imageNamed: TILE_TEXTURES[String(tile.shortcut)]!)
            tileNode.size.width = tileSize!
            tileNode.size.height = tileSize!
            
            tileNode.position = CGPoint(x: tileSize! * CGFloat(toBorders(value: column - 1, from: 0, to: columns - 3)) + (tileSize! / 2.0), y: size.height - tileSize! * CGFloat(toBorders(value: row - 1, from: 0, to: rows-3)) + (tileSize! / 2.0) - tileSize!)<commit_msg>Change to filled tiles when level is solved<commit_after>//
//  GameScene.swift
//  SOPA
//
//  Created by <NAME> on 21.10.17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import SpriteKit
import GameplayKit

class GameScene: SKScene {
    var level: Level
    let gameFieldNode = SKNode()
    let startEndNode = SKNode()
    let puzzlesNode = SKNode()
    let gameFieldService = GameFieldService()
    let MIN_MOVE = CGFloat(30)
    var tileSize: CGFloat?
    var levelSolved = false
    
    init(size: CGSize, level: Level) {
        self.level = level
        super.init(size: size)
        initNodes()
    }
    
    func initNodes() {
        gameFieldNode.addChild(startEndNode)
        gameFieldNode.addChild(puzzlesNode)
        puzzlesNode.zPosition = -1
        addChild(gameFieldNode)
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func didMove(to view: SKView) {
        updateGameField()
    }
    
    func rotateStartAndFinishTile(tile: SKSpriteNode, column: Int, row: Int, columns: Int, rows: Int) {
        if (row == 0) {
            // TOP
            tile.zRotation = -CGFloat(Double.pi) / 2
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
            
        } else if (column == 0) {
            // LEFT
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
            
        } else if (row == rows - 1) {
            // BOTTOM
            tile.zRotation = -(CGFloat(Double.pi) / 2) * 3
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
            
        } else if (column == columns - 1) {
            // RIGHT
            tile.zRotation = CGFloat(Double.pi)
            tile.position = CGPoint(x: tile.position.x, y: tile.position.y)
        }
    }
    func toBorders(value: Int, from: Int, to: Int) -> Int {
        if value < from {
            return from
        }
        if value > to {
            return to
        }
        return value
    }
    
    func updateGameField() {
        puzzlesNode.removeAllChildren()
        startEndNode.removeAllChildren()
        let columns = level.tiles.count
        let rows = level.tiles[0].count
        tileSize = size.width / CGFloat(level.tiles.count - 2)
        if(gameFieldService.solvedPuzzle(level: level)) {
            levelSolved = true
        }
        for column in 0...columns - 1 {
            for row in 0...rows - 1 {
                addTile(column: column, row: row, columns: columns, rows: rows)
            }
        }
        
    }
    func addTile(column: Int, row: Int, columns: Int, rows: Int) {
        let tile = level.tiles[column][row]
        let shortcut = tile.shortcut
        let tileType = tile.tileType
        if (shortcut != "n") {
            let tileNode: TileSpriteNode
            if(levelSolved) {
                tileNode = TileSpriteNode(imageNamed: TILE_TEXTURES[String(tile.shortcut).uppercased()]!)
            } else {
                tileNode = TileSpriteNode(imageNamed: TILE_TEXTURES[String(tile.shortcut)]!)
            }
            tileNode.size.width = tileSize!
            tileNode.size.height = tileSize!
            
            tileNode.position = CGPoint(x: tileSize! * CGFloat(toBorders(value: column - 1, from: 0, to: columns - 3)) + (tileSize! / 2.0), y: size.height - tileSize! * CGFloat(toBorders(value: row - 1, from: 0, to: rows-3)) + (tileSize! / 2.0) - tileSize!)
{'fraction_non_alphanumeric': 0.11511216056670602, 'fraction_numerical': 0.010625737898465172, 'mean_word_length': 1.8190515806988352, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4790620', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2095, 'n_words': 513}