<commit_before>//
//  RoomViewController.swift
//  Courir
//
//  Created by <NAME> on 3/25/16.
//  Copyright © 2016 NUS CS3217. All rights reserved.
//

import UIKit
import SpriteKit
import MultipeerConnectivity

private let cellIdentifier = "peerCell"

class RoomViewController: UIViewController {

    static let numberOfVCsToMenu = 2

    @IBOutlet weak var startButton: UIButton!
    @IBOutlet weak var peersTableView: UITableView!

    private var seed: NSData?

    private(set) var mode: GameMode = .Multiplayer
    private(set) var isHost = true
    var host: MCPeerID? = myPeerID
    
    private var peers = [MCPeerID]()

    private var gameSetupData: GameSetupData {
        return GameSetupData(mode: mode, host: host, peers: peers, seed: seed)
    }

    private let portal = GameNetworkPortal._instance
    
    override func viewDidLoad() {
        super.viewDidLoad()
        portal.connectionDelegate = self
        peersTableView.dataSource = self

        startButton.setLetterSpacing(defaultLetterSpacing)
        
        if isHost {
            portal.beginHosting()
            startButton.enabled = peers.count > 0
        } else {
            startButton.enabled = false
        }
    }

    // MARK: Setup<commit_msg>Lobby title changes for host depending on current mode<commit_after>//
//  RoomViewController.swift
//  Courir
//
//  Created by <NAME> on 3/25/16.
//  Copyright © 2016 NUS CS3217. All rights reserved.
//

import UIKit
import SpriteKit
import MultipeerConnectivity

private let cellIdentifier = "peerCell"

class RoomViewController: UIViewController {

    static let numberOfVCsToMenu = 2

    @IBOutlet weak var startButton: UIButton!
    @IBOutlet weak var peersTableView: UITableView!
    @IBOutlet weak var lobbyTitle: UILabel!

    @IBOutlet weak var switchModeButton: UIButton!

    private var seed: NSData?

    private(set) var mode: GameMode! {
        didSet {
            updateLobbyTitle(mode)
        }
    }
    private(set) var isHost = true
    var host: MCPeerID? = myPeerID
    
    private var peers = [MCPeerID]()

    private var gameSetupData: GameSetupData {
        return GameSetupData(mode: mode, host: host, peers: peers, seed: seed)
    }

    private let portal = GameNetworkPortal._instance
    
    override func viewDidLoad() {
        super.viewDidLoad()
        portal.connectionDelegate = self
        peersTableView.dataSource = self

        startButton.setLetterSpacing(defaultLetterSpacing)
        switchModeButton.setFadeForUserActions()
        
        mode = .Multiplayer

        if isHost {
            portal.beginHosting()
            startButton.enabled = peers.count > 0
        } else {
            lobbyTitle.text = "Lobby"
            startButton.enabled = false
            switchModeButton.enabled = false
        }
    }

    @IBAction func handleSwitchModeAction(sender: AnyObject) {
        let newMode: GameMode = mode == .Multiplayer ? .SpecialMultiplayer : .Multiplayer
        setMode(newMode)
    }

    private func updateLobbyTitle(mode: GameMode) {
        if isHost {
            let gameType = mode == .SpecialMultiplayer ? "Special" : ""
            lobbyTitle.text = "Hosting \(gameType) Multiplayer"
        }
    }

    // MARK: Setup
{'fraction_non_alphanumeric': 0.08087330873308733, 'fraction_numerical': 0.00922509225092251, 'mean_word_length': 2.456960680127524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '351695', 'n_tokens_mistral': 981, 'n_tokens_neox': 924, 'n_words': 254}