summaryrefslogtreecommitdiff
path: root/webcards/scripts/client/lobby.js
blob: 8d463529413ce022ac5efa34f77069a6935da38d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Lobby manages the players and games provided by the server and allows users to join or create their own games.
function Lobby(el){
    this.root = el;

    this.elements = {
        status: this.root.getElementsByClassName("status")[0],
        addr:   this.root.getElementsByClassName("addr")[0],

        stats:  {
            game:       document.getElementById("game"),
            packs:      document.getElementById("packs"),
            online:     document.getElementById("online"),
            ingame:     document.getElementById("ingame"),
            pubgame:    document.getElementById("pubgame")
        },

        settings: {
            name:   document.getElementById("name"),
            color:  document.getElementById("usercolor")
        }
    };

    this.top = new TopBar(document.getElementsByClassName("topbar")[0]);
    
    this.init = false;
    this.online = [];
    this.games = [];
    this.packs = [];
    this.players = [];
}

Lobby.prototype = {
    packList: function(data){

        this.elements.stats.packs.innerText = this.packs.length();
    },

    gameList: function(data, game){

        this.elements.stats.pubgame.innerText = this.games.length();
    },

    players: function(data) {

        this.elements.stats.online.innerText = this.players.length();
        this.init = true;
    },

    addGame: function(data){

    },

    removeGame: function(data){

    },

    addPlayer: function(data){

    },

    movePlayer: function(data){

    },

    removePlayer: function(data){

    },

    newGameScreen: function(){
        if(this.init) return;
    },

    setState: function(text, color, server){
        this.elements.status.style.backgroundColor = color;
        this.elements.status.innerText = text;
        this.elements.addr.innerText = server;
        this.top.setColor(color);
    },

    reset: function(){
        this.setState("Connecting", "#DA0", this.elements.addr.innerText);
        this.init = false;
    }
};

// ###############
// # TopBar Code #
// ###############

function TopBar(el) {
    this.root = el;

    this.newGame = el.getElementsByClassName("new-game")[0];
    this.mobileSettings = el.getElementsByClassName("mobile-settings")[0];
    this.status = el.getElementsByClassName("status")[0];
}

TopBar.prototype = {
    setColor: function(color) {
        this.status.style.backgroundColor = color;
    }
};