function Game(gameMsg) {
    var self = this;

    self.name = gameMsg.name;
    self.number = gameMsg.num;
    self.isFull = ko.observable(gameMsg.isFull);
    self.started = ko.observable(gameMsg.started);
    self.seatChart = ko.observableArray(gameMsg.seatChart);
    self.seats = ko.computed(function() {
        var seats = {};
        var players = CinchApp.players;

        [players.north, players.south, players.east, players.west].forEach(function(pNum) {
            var seatChartName = null;

            //Extract the name from the seat chart if someone is there
            self.seatChart().forEach(function(chartItem) {
                chartItem[1] === pNum && (seatChartName = chartItem[0]);
            });

            //Create an seat object in place (could move to a class if needed elsewhere)
            seats[pNum] = {
                available: seatChartName === null,
                displayText: seatChartName === null ? '<Available>' : seatChartName,
                join: function() {
                    self.join(pNum);
                }
            };
        });

        return seats;
    });

    // Gets unordered list of users in the room
    self.playerNames = ko.computed(function () {
        var users = [];
        var i;
        var seatChart = self.seatChart();

        for (i = 0; i < seatChart.length; i++) {
            users.push(seatChart[i][0]);
        }

        return users; 
    });

    self.select = function() {
        CinchApp.viewModel.selectedRoom(self);
        CinchApp.viewModel.activeView(CinchApp.views.seatSelect);
    };

    // Only called when joining existing game, not ICW new
    self.join = function(seatNum) {
        CinchApp.socket.emit('join', self.number, seatNum, CinchApp.viewModel.joinCallback);
    };
}
//Represents a single joinable game, as listed in the lobby
Represents a single joinable game, as listed in the lobby
Represents a single joinable game as listed in the lobby
function Game(gameMsg) {
    var self = this;
    self.name = gameMsg.name;
    self.number = gameMsg.num;
    self.isFull = ko.observable(gameMsg.isFull);
    self.started = ko.observable(gameMsg.started);
    self.seatChart = ko.observableArray(gameMsg.seatChart);
    self.seats = ko.computed(function() {
        var seats = {};
        var players = CinchApp.players;
        [players.north, players.south, players.east, players.west].forEach(function(pNum) {
            var seatChartName = null;
            self.seatChart().forEach(function(chartItem) {
                chartItem[1] === pNum && (seatChartName = chartItem[0]);
            });
            seats[pNum] = {
                available: seatChartName === null,
                displayText: seatChartName === null ? '<Available>' : seatChartName,
                join: function() {
                    self.join(pNum);
                }
            };
        });
        return seats;
    });
    self.playerNames = ko.computed(function () {
        var users = [];
        var i;
        var seatChart = self.seatChart();
        for (i = 0; i < seatChart.length; i++) {
            users.push(seatChart[i][0]);
        }
        return users; 
    });
    self.select = function() {
        CinchApp.viewModel.selectedRoom(self);
        CinchApp.viewModel.activeView(CinchApp.views.seatSelect);
    };
    self.join = function(seatNum) {
        CinchApp.socket.emit('join', self.number, seatNum, CinchApp.viewModel.joinCallback);
    };
}
function Game ( gameMsg ) { var self = this ; self . name = gameMsg . name ; self . number = gameMsg . num ; self . isFull = ko . observable ( gameMsg . isFull ) ; self . started = ko . observable ( gameMsg . started ) ; self . seatChart = ko . observableArray ( gameMsg . seatChart ) ; self . seats = ko . computed ( function ( ) { var seats = { } ; var players = CinchApp . players ; [ players . north , players . south , players . east , players . west ] . forEach ( function ( pNum ) { var seatChartName = null ; self . seatChart ( ) . forEach ( function ( chartItem ) { chartItem [ 1 ] === pNum && ( seatChartName = chartItem [ 0 ] ) ; } ) ; seats [ pNum ] = { available : seatChartName === null , displayText : seatChartName === null ? '<Available>' : seatChartName , join : function ( ) { self . join ( pNum ) ; } } ; } ) ; return seats ; } ) ; self . playerNames = ko . computed ( function ( ) { var users = [ ] ; var i ; var seatChart = self . seatChart ( ) ; for ( i = 0 ; i < seatChart . length ; i ++ ) { users . push ( seatChart [ i ] [ 0 ] ) ; } return users ; } ) ; self . select = function ( ) { CinchApp . viewModel . selectedRoom ( self ) ; CinchApp . viewModel . activeView ( CinchApp . views . seatSelect ) ; } ; self . join = function ( seatNum ) { CinchApp . socket . emit ( 'join' , self . number , seatNum , CinchApp . viewModel . joinCallback ) ; } ; }
Represents a single joinable game, as listed in the lobby
Represents a single joinable game as listed in the lobby
//Extract the name from the seat chart if someone is there //Create an seat object in place (could move to a class if needed elsewhere) // Gets unordered list of users in the room // Only called when joining existing game, not ICW new