diff --git a/Makefile b/Makefile
deleted file mode 100644
index acce3da..0000000
--- a/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-test:
- python -m tests
diff --git a/api/grid.py b/api/grid.py
deleted file mode 100644
index 9aa2371..0000000
--- a/api/grid.py
+++ /dev/null
@@ -1,74 +0,0 @@
-import tornado.web
-from model import Grid
-from utility.template import jsonify
-from utility import UpdateManager
-import json, os
-
-class Exists(tornado.web.RequestHandler):
- def get(self):
- name = self.get_argument("name", None)
- if name is None:
- return jsonify(self, status=406)
-
- grid = Grid.fromName(name)
- if grid.exists() is False:
- return jsonify(self, status=404)
-
- return jsonify(self, status=200, colors = grid.getUsedColors())
-
-class Create(tornado.web.RequestHandler):
- def post(self):
- name = self.get_argument("name", None)
- size = self.get_argument("size", None)
- mapfile = "default"
-
- if name is None or size is None:
- return jsonify(self, status=406, error = "name")
- try:
- int(size)
- except ValueError:
- return jsonify(self, status=406, error = "size")
-
-
- if size not in ['16', '32', '64']:
- return jsonify(self, status=404)
-
- # Make sure the name doesn't already exist
- if Grid.fromName(name).exists():
- return jsonify(self, status=406, error = "Name taken")
-
- status, g = Grid.create(name, size, "default")
-
- if status == False:
- return jsonify(self, status=406, error=g)
-
- # Send to nogrids
- UpdateManager.sendNogrids("newGrid",
- gid = g['id'],
- size = size,
- active = g['active'],
- name = g['name'],
- players = 1,
- )
-
- return jsonify(self, status=200, gid = g['id'])
-
-class Info(tornado.web.RequestHandler):
- def get(self):
- name = self.get_argument("name", None)
- gid = self.get_argument("gid", None)
- if name is None and gid is None:
- return jsonify(self, status=406)
-
- if gid is None:
- g = Grid.fromName(name)
- elif name is None:
- g = Grid(gid)
-
- if g.exists() is False:
- return jsonify(self, status=404)
-
- return jsonify(self, status=200, data = {
- "gid": g['id'],
- "size": g['size']
- })
diff --git a/client/run.py b/client/run.py
new file mode 100644
index 0000000..315ec6d
--- /dev/null
+++ b/client/run.py
@@ -0,0 +1,9 @@
+from flask import Flask, render_template
+app = Flask(__name__)
+
+@app.route("/")
+def index():
+ return render_template("index.html")
+
+if __name__ == "__main__":
+ app.run()
diff --git a/static/css/game.less b/client/static/css/game.less
similarity index 100%
rename from static/css/game.less
rename to client/static/css/game.less
diff --git a/static/css/style.less b/client/static/css/style.less
similarity index 77%
rename from static/css/style.less
rename to client/static/css/style.less
index 9772a54..688dd62 100644
--- a/static/css/style.less
+++ b/client/static/css/style.less
@@ -237,60 +237,62 @@ div.room {
div.room_select {
border:1px solid @darkish;
color: @dark;
+}
+div.listcontainer {
+ background: @light;
+ width:100%;
+ height:100px;
+ margin:10px 0px 10px 0px;
+ overflow-y:auto;
+ border:1px solid @gray;
+
+ .listcontainer_loading {
+ color: @dark;
+ text-align:center;
+ margin:40px auto 0px auto;
+ text-weight:400;
+ }
+}
- div.listcontainer {
- background: @light;
- width:100%;
- height:100px;
- margin:10px 0px 10px 0px;
- overflow-y:auto;
- border:1px solid @gray;
-
- #loading_list {
- color: @dark;
- text-align:center;
- margin:40px auto 0px auto;
- text-weight:400;
+table.listcontainer_list {
+ background:@light;
+ width:100%;
+ vertical-align:top;
+ margin:0px;
+ border-spacing:0px;
+
+ tr {
+ td {
+ padding:10px;
+ cursor:pointer;
+ border-bottom:1px solid @gray;
}
}
- table.gridlist {
- background:@light;
- width:100%;
- vertical-align:top;
- margin:0px;
- border-spacing:0px;
-
- tr {
- td {
- padding:10px;
- cursor:pointer;
- border-bottom:1px solid @gray;
- }
- td:first-child {
- width:75%;
- font-weight:400;
- font-size:18px;
- }
- td:last-child {
- font-size:12px;
- color:@darkish;
- text-align:right;
- }
- }
+ tr:last {
+ border-bottom:0px;
+ }
+
+ tr:hover {
+ background:@gray;
+ }
- tr:last {
- border-bottom:0px;
- }
-
- tr:hover {
- background:@gray;
- }
+ tr.selected {
+ background:@blue;
+ color:@light;
+ }
+}
- tr:active, tr.selected {
- background:@blue;
- color:@light;
- }
+#gridList {
+ td:first-child {
+ width:75%;
+ font-weight:400;
+ font-size:18px;
+ }
+ td:last-child {
+ font-size:12px;
+ color:@darkish;
+ text-align:right;
}
}
@@ -313,6 +315,28 @@ div.room_create {
}
}
+div.server_browser {
+ z-index: 4;
+
+ .server_browser_other {
+ display: none;
+ }
+}
+
+.connection {
+ position: fixed;
+ bottom: 0px;
+ right: 0px;
+ padding: 5px;
+
+ font-size: 12px;
+ display: none;
+
+ span {
+ font-family: monospace;
+ }
+}
+
div.screen {
background:#000;
opacity:.2;
diff --git a/static/css/tiles.less b/client/static/css/tiles.less
similarity index 100%
rename from static/css/tiles.less
rename to client/static/css/tiles.less
diff --git a/static/img/favicon.png b/client/static/img/favicon.png
similarity index 100%
rename from static/img/favicon.png
rename to client/static/img/favicon.png
diff --git a/static/img/grid_noise.png b/client/static/img/grid_noise.png
similarity index 100%
rename from static/img/grid_noise.png
rename to client/static/img/grid_noise.png
diff --git a/static/img/logout.png b/client/static/img/logout.png
similarity index 100%
rename from static/img/logout.png
rename to client/static/img/logout.png
diff --git a/static/img/menu.png b/client/static/img/menu.png
similarity index 100%
rename from static/img/menu.png
rename to client/static/img/menu.png
diff --git a/static/img/tiles/10.png b/client/static/img/tiles/10.png
similarity index 100%
rename from static/img/tiles/10.png
rename to client/static/img/tiles/10.png
diff --git a/static/img/tiles/2.png b/client/static/img/tiles/2.png
similarity index 100%
rename from static/img/tiles/2.png
rename to client/static/img/tiles/2.png
diff --git a/static/img/tiles/3.png b/client/static/img/tiles/3.png
similarity index 100%
rename from static/img/tiles/3.png
rename to client/static/img/tiles/3.png
diff --git a/static/img/tiles/4.png b/client/static/img/tiles/4.png
similarity index 100%
rename from static/img/tiles/4.png
rename to client/static/img/tiles/4.png
diff --git a/static/img/tiles/5.png b/client/static/img/tiles/5.png
similarity index 100%
rename from static/img/tiles/5.png
rename to client/static/img/tiles/5.png
diff --git a/static/img/tiles/6.png b/client/static/img/tiles/6.png
similarity index 100%
rename from static/img/tiles/6.png
rename to client/static/img/tiles/6.png
diff --git a/static/img/tiles/7.png b/client/static/img/tiles/7.png
similarity index 100%
rename from static/img/tiles/7.png
rename to client/static/img/tiles/7.png
diff --git a/static/img/tiles/8.png b/client/static/img/tiles/8.png
similarity index 100%
rename from static/img/tiles/8.png
rename to client/static/img/tiles/8.png
diff --git a/static/img/tiles/9.png b/client/static/img/tiles/9.png
similarity index 100%
rename from static/img/tiles/9.png
rename to client/static/img/tiles/9.png
diff --git a/static/img/tiles/99.png b/client/static/img/tiles/99.png
similarity index 100%
rename from static/img/tiles/99.png
rename to client/static/img/tiles/99.png
diff --git a/static/js/GameClient.js b/client/static/js/GameClient.js
similarity index 86%
rename from static/js/GameClient.js
rename to client/static/js/GameClient.js
index d82a47b..b5c7344 100644
--- a/static/js/GameClient.js
+++ b/client/static/js/GameClient.js
@@ -67,14 +67,9 @@ var GameClient = (function() {
}
function newGrid(data) {
- $("#loading_list").hide();
- $("
"+ data['name'] +" | "+ data['players'] +" players |
")
- .appendTo(".gridlist")
- .data("gid", data['gid'])
- .data("active", data['active'])
- .data("name", data['name'])
- .data("size", data['size']);
- HomeView.setupList();
+ if(ViewController.current != HomeView) return;
+ ViewController.current.grids[data['gid']] = data;
+ ViewController.current.gridList.addItem([data['name'], data['players'] + " players"], data['gid']);
}
return {
diff --git a/static/js/GameEvents.js b/client/static/js/GameEvents.js
similarity index 100%
rename from static/js/GameEvents.js
rename to client/static/js/GameEvents.js
diff --git a/static/js/GameView.js b/client/static/js/GameView.js
similarity index 100%
rename from static/js/GameView.js
rename to client/static/js/GameView.js
diff --git a/static/js/Grid.js b/client/static/js/Grid.js
similarity index 100%
rename from static/js/Grid.js
rename to client/static/js/Grid.js
diff --git a/client/static/js/HomeView.js b/client/static/js/HomeView.js
new file mode 100644
index 0000000..93edb3e
--- /dev/null
+++ b/client/static/js/HomeView.js
@@ -0,0 +1,155 @@
+var HomeView = (function() {
+ var tpl = "home.html";
+
+ function onLoad() {
+ var xTiles, yTiles, grid;
+
+ // Load list views
+ this.grids = {};
+ this.gridList = new BaseUI.List("#gridList", function(val) {
+ var grids = ViewController.current.grids;
+ if(val == null) {
+ $("#enter").addClass("disabled");
+ } else {
+ GameData['gid'] = val;
+ GameData['size'] = parseInt(grids[val]['size']);
+ GameData['name'] = grids[val]['name'];
+ GameData['active'] = grids[val]['active'];
+ $("#enter").removeClass("disabled");
+ }
+ });
+ this.serverList = new BaseUI.List("#serverList", function(val) {
+ if(val == "other") {
+ $("#server_browser_other").show();
+ return;
+ } else $("#server_browser_other").hide();
+
+ GameData['server'] = val;
+ $("#connect").removeClass("disabled");
+ });
+
+ // If we've connected to a server try to load it up
+ if(GameData['server']) {
+ $("#connection_server").text(GameData['server']);
+ $("#connection").show();
+ fetchGrids();
+ } else {
+ $("#screen").show();
+ $("#server_browser").show();
+ this.serverList.addItem(["local testing"], 'localhost:8080');
+ this.serverList.addItem(["other"], "other");
+ }
+
+ $("#server_browser_address").on("keyup", function() {
+ if($(this).val().length > 0) $("#connect").removeClass("disabled");
+ else $("#connect").addClass("disabled");
+
+ GameData['server'] = $(this).val();
+ });
+
+ $("#enter").click(function() {
+ if(GameData['active'] == 1) ViewController.load(GameView);
+ else enterRoom();
+ });
+
+ $("#connect").click(function() {
+ fetchGrids();
+ $("#server_browser, #screen").fadeOut(150);
+ $("#connection_server").text(GameData['server']);
+ $("#connection").show();
+ });
+
+ $(".side_menu a").on("click", function() {
+ if($(".fade.open").attr("id") == $(this).attr("fade")) return;
+
+ $(".side_menu a.selected").removeClass("selected");
+ $(this).addClass("selected");
+
+ $(".fade").fadeOut(250).removeClass("open");
+ $("#" + $(this).attr("fade")).fadeIn(250).addClass("open");
+ HomeView.current = $(this).attr("fade");
+ });
+
+ $("a.option").click(BaseUI.optionSelect);
+ $("input[name=create]").click(createGame);
+ $("input[name=start]").on("click", startGame);
+ }
+
+ // Makes sure we're connected to the server
+ // and then fetches a list of active grids
+ // for the player to join
+ function fetchGrids() {
+ AsyncClient.connect(function() {
+ AsyncClient.send("getGrids", {}, getGridsCb);
+ });
+ }
+
+ function getGridsCb(data) {
+ var grids = data['grids'];
+ $("#loading_list").hide();
+ for(grid in grids) {
+ ViewController.current.gridList.addItem([grids[grid]['name'], grids[grid]['players'] + " players"], grids[grid]['gid']);
+ ViewController.current.grids[grids[grid]['gid']] = grids[grid];
+ }
+
+ if(grids.length == 0) {
+ ViewController.current.gridList.setLoadingText("No grids found.");
+ }
+ }
+
+ function createGame() {
+ AsyncClient.send("createGrid", {
+ "name": $("input[name=room]").val(),
+ "size": $("input[name=size]").val(),
+ }, createGameCb);
+ }
+
+ function createGameCb(data) {
+ GameData['gid'] = data['gid'];
+ GameData['size'] = parseInt($("input[name=size]").val());
+ GameData['name'] = $("input[name=room]").val();
+ enterRoom();
+ }
+
+ /*
+ * Waiting room stuff
+ */
+ function enterRoom() {
+ AsyncClient.send("joinRoom", {gid: GameData['gid'], pid: GameData['pid']}, joinRoomCb);
+ $("#menu_lobby").text(GameData['name'] + " lobby").addClass("selected").fadeIn(250);
+ $(".side_menu a.selected").removeClass("selected");
+ }
+
+ function startGame() {
+ if(GameData['players_active'].length <= 1) return;
+
+ AsyncClient.send("startGame");
+ }
+
+ function joinRoomCb(data) {
+ // Load the game data
+ GameData['pid'] = parseInt(data['pid']);
+ GameData['colors'] = data['colors'];
+ GameData['color'] = GameData['colors'][GameData['pid']];
+ GameData['players_active'] = data['active'];
+ GameData['active'] = false;
+ GameData['has_init'] = true;
+
+ // Update the UI
+ $("#roomname").text(GameData['name']);
+ $.each(GameData['players_active'], function(i, pid) {
+ $("#p" + pid).css("background", GameData['colors'][pid]);
+ });
+
+ if(GameData['active'].length > 1) {
+ $("input[name=start]").removeClass("disabled");
+ }
+ $(".open").removeClass("open");
+ $("#waiting").fadeIn(250).addClass("open");
+ }
+
+ return {
+ "tpl": tpl,
+ "onLoad": onLoad,
+ }
+})();
diff --git a/static/js/KeyEvents.js b/client/static/js/KeyEvents.js
similarity index 100%
rename from static/js/KeyEvents.js
rename to client/static/js/KeyEvents.js
diff --git a/static/js/coord.js b/client/static/js/coord.js
similarity index 100%
rename from static/js/coord.js
rename to client/static/js/coord.js
diff --git a/static/js/jquery-1.7.1.min.js b/client/static/js/jquery-1.7.1.min.js
similarity index 100%
rename from static/js/jquery-1.7.1.min.js
rename to client/static/js/jquery-1.7.1.min.js
diff --git a/static/js/jquery-ui-1.8.17.custom.min.js b/client/static/js/jquery-ui-1.8.17.custom.min.js
similarity index 100%
rename from static/js/jquery-ui-1.8.17.custom.min.js
rename to client/static/js/jquery-ui-1.8.17.custom.min.js
diff --git a/static/js/jquery.cookie.js b/client/static/js/jquery.cookie.js
similarity index 100%
rename from static/js/jquery.cookie.js
rename to client/static/js/jquery.cookie.js
diff --git a/static/js/jquery.hotkeys.js b/client/static/js/jquery.hotkeys.js
similarity index 100%
rename from static/js/jquery.hotkeys.js
rename to client/static/js/jquery.hotkeys.js
diff --git a/static/js/less-1.2.2.js b/client/static/js/less-1.2.2.js
similarity index 100%
rename from static/js/less-1.2.2.js
rename to client/static/js/less-1.2.2.js
diff --git a/static/js/main.js b/client/static/js/main.js
similarity index 79%
rename from static/js/main.js
rename to client/static/js/main.js
index b7757f0..bd53a19 100644
--- a/static/js/main.js
+++ b/client/static/js/main.js
@@ -170,6 +170,48 @@ var BaseUI = (function() {
}
}
+ // List container element
+ // element: The element of the list container
+ // callback: The function to be called whenever an item
+ // is selected. function(val)
+ var List = function(element, callback) {
+ if(callback == undefined) selectCallback = function() {};
+
+ this.el = $(element);
+ this.callback = callback;
+ this.table = this.el.children("table");
+ this.loading = this.el.children(".listcontainer_loading");
+
+ function clickItem() {
+ if($(this).hasClass("selected")) {
+ $(this).removeClass("selected");
+ $(this).data("list").callback(null);
+ } else {
+ $(this).siblings(".selected").removeClass("selected");
+ $(this).addClass("selected");
+ $(this).data("list").callback($(this).attr("value"));
+ }
+ }
+
+ this.addItem = function(item, value) {
+ this.loading.hide();
+ var str = "";
+ for(var i in item) {
+ str += "" + item[i] + " | ";
+ };
+ str += "
";
+ var el = $(str);
+ el.click(clickItem);
+ el.attr("value", value);
+ el.data("list", this);
+ this.table.append(el);
+ }
+
+ this.setLoadingText = function(val) {
+ this.loading.text(val);
+ }
+ }
+
return {
"loading": loading,
"done": done,
@@ -180,6 +222,7 @@ var BaseUI = (function() {
"hideChatbox": hideChatbox,
"show_msg": show_msg,
"notif_disp": [],
+ "List": List
};
})();
@@ -204,7 +247,12 @@ var AsyncClient = (function() {
function connect(callback) {
if(ws != undefined && ws.readyState == ws.OPEN) return callback();
- ws = new WebSocket("ws://"+ document.domain + ":" + window.location.port + "/api/socket");
+
+ if(GameData['server'] == undefined)
+ ws = new WebSocket("ws://"+ document.domain + ":" + window.location.port + "/api/socket");
+ else
+ ws = new WebSocket("ws://" + GameData['server'] + "/api/socket")
+
ws.onopen = callback;
ws.onmessage = newMessage;
ws.onclose = closeSocket;
@@ -256,7 +304,8 @@ $(document).ready(function() {
$.ajaxSetup({ cache: false });
this.onselectstart = function() { return false; }
- if($.cookie("gid") != undefined) {
+ if($.cookie("server") != undefined && $.cookie("gid") != undefined) {
+ GameData['server'] = $.cookie("server");
GameData['pid'] = $.cookie("pid");
GameData['gid'] = $.cookie("gid");
GameData['size'] = $.cookie("size");
diff --git a/static/js/raphael-min.js b/client/static/js/raphael-min.js
similarity index 100%
rename from static/js/raphael-min.js
rename to client/static/js/raphael-min.js
diff --git a/static/js/tiles.js b/client/static/js/tiles.js
similarity index 100%
rename from static/js/tiles.js
rename to client/static/js/tiles.js
diff --git a/static/maps/16_default.json b/client/static/maps/16_default.json
similarity index 100%
rename from static/maps/16_default.json
rename to client/static/maps/16_default.json
diff --git a/static/maps/32_default.json b/client/static/maps/32_default.json
similarity index 100%
rename from static/maps/32_default.json
rename to client/static/maps/32_default.json
diff --git a/static/maps/64_default.json b/client/static/maps/64_default.json
similarity index 100%
rename from static/maps/64_default.json
rename to client/static/maps/64_default.json
diff --git a/static/tpl/game.html b/client/static/tpl/game.html
similarity index 100%
rename from static/tpl/game.html
rename to client/static/tpl/game.html
diff --git a/static/tpl/home.html b/client/static/tpl/home.html
similarity index 67%
rename from static/tpl/home.html
rename to client/static/tpl/home.html
index ceef78d..1e2eef3 100644
--- a/static/tpl/home.html
+++ b/client/static/tpl/home.html
@@ -13,11 +13,25 @@
+
+