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 @@ +
+

connect to a server

+
+
Loading servers...
+ +
+
+
+

server address:

+ +
+ +
+

enter or start a game

-
-
Loading grids...
- +
+
Loading grids...
+
@@ -48,3 +62,9 @@

loading...

+ +
+ connected to [none] +
+ +
 
diff --git a/templates/index.html b/client/templates/index.html similarity index 100% rename from templates/index.html rename to client/templates/index.html diff --git a/hooks/pre-commit b/hooks/pre-commit deleted file mode 100755 index 47dba50..0000000 --- a/hooks/pre-commit +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -make test || exit 1 diff --git a/api/__init__.py b/server/api/__init__.py similarity index 100% rename from api/__init__.py rename to server/api/__init__.py diff --git a/server/api/grid.py b/server/api/grid.py new file mode 100644 index 0000000..1e313ed --- /dev/null +++ b/server/api/grid.py @@ -0,0 +1,37 @@ +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 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/config.py b/server/config.py similarity index 83% rename from config.py rename to server/config.py index 5414f54..1507680 100644 --- a/config.py +++ b/server/config.py @@ -11,4 +11,4 @@ } # Path to installation, with trailing slash -path = '/vagrant/' +path = '/Users/john/Code/thegrid/server/' diff --git a/controller/__init__.py b/server/controller/__init__.py similarity index 100% rename from controller/__init__.py rename to server/controller/__init__.py diff --git a/controller/async.py b/server/controller/async.py similarity index 86% rename from controller/async.py rename to server/controller/async.py index 21fa9ee..fe42343 100644 --- a/controller/async.py +++ b/server/controller/async.py @@ -26,6 +26,42 @@ def getGrids(handler, **args): return {"status": 200, "grids": grids} +def createGrid(handler, **args): + name = args['name'] + size = args['size'] + 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 {"status": 200, "gid": g['id']} + def startGame(handler, **args): g = Grid(handler.user['grid']) diff --git a/controller/client.py b/server/controller/client.py similarity index 100% rename from controller/client.py rename to server/controller/client.py diff --git a/controller/index.py b/server/controller/index.py similarity index 100% rename from controller/index.py rename to server/controller/index.py diff --git a/server/maps/16_default.json b/server/maps/16_default.json new file mode 100644 index 0000000..c338baa --- /dev/null +++ b/server/maps/16_default.json @@ -0,0 +1,62 @@ +{ + "players": 4, + "autogenerate": 1, + "tlim": 100, + "init_tused": 3, + "init_tlim": 6, + "init_cash": 500, + + "colors": { + "1": "#FEBE07", + "2": "#10A1FF", + "3": "#FF401C", + "4": "#3FCD45" + }, + + "coords": { + "0_0": { + "type": 99 + }, + "15_0": { + "type": 99 + }, + + "1_1": { + "type": 2, + "health": 100, + "player": 1 + }, + "1_0": { + "type": 1, + "health": 25, + "player": 1 + }, + "0_1": { + "type": 1, + "health": 25, + "player": 1 + }, + + "14_0": { + "type": 1, + "health": 25, + "player": 2 + }, + "15_1": { + "type": 1, + "health": 25, + "player": 2 + }, + "14_1": { + "type": 2, + "health": 100, + "player": 2 + } + }, + + "events": { + "init": ["0_0", "15_0"], + "join_1": ["1_1", "1_0", "0_1"], + "join_2": ["14_0", "15_1", "14_1"] + } +} diff --git a/server/maps/32_default.json b/server/maps/32_default.json new file mode 100644 index 0000000..4a1ecdb --- /dev/null +++ b/server/maps/32_default.json @@ -0,0 +1,62 @@ +{ + "players": 4, + "autogenerate": 1, + "tlim": 100, + "init_tused": 3, + "init_tlim": 6, + "init_cash": 750, + + "colors": { + "1": "#FEBE07", + "2": "#10A1FF", + "3": "#FF401C", + "4": "#3FCD45" + }, + + "coords": { + "0_0": { + "type": 99 + }, + "31_0": { + "type": 99 + }, + + "1_1": { + "type": 2, + "health": 100, + "player": 1 + }, + "1_0": { + "type": 1, + "health": 25, + "player": 1 + }, + "0_1": { + "type": 1, + "health": 25, + "player": 1 + }, + + "30_0": { + "type": 1, + "health": 25, + "player": 2 + }, + "31_1": { + "type": 1, + "health": 25, + "player": 2 + }, + "30_1": { + "type": 2, + "health": 100, + "player": 2 + } + }, + + "events": { + "init": ["0_0", "31_0"], + "join_1": ["1_1", "1_0", "0_1"], + "join_2": ["30_0", "31_1", "30_1"] + } +} diff --git a/server/maps/64_default.json b/server/maps/64_default.json new file mode 100644 index 0000000..d63f665 --- /dev/null +++ b/server/maps/64_default.json @@ -0,0 +1,62 @@ +{ + "players": 4, + "autogenerate": 1, + "tlim": 1024, + "init_tused": 3, + "init_tlim": 6, + "init_cash": 500, + + "colors": { + "1": "#FEBE07", + "2": "#10A1FF", + "3": "#FF401C", + "4": "#3FCD45" + }, + + "coords": { + "0_0": { + "type": 99 + }, + "63_0": { + "type": 99 + }, + + "1_1": { + "type": 2, + "health": 100, + "player": 1 + }, + "1_0": { + "type": 1, + "health": 25, + "player": 1 + }, + "0_1": { + "type": 1, + "health": 25, + "player": 1 + }, + + "62_0": { + "type": 1, + "health": 25, + "player": 2 + }, + "63_1": { + "type": 1, + "health": 25, + "player": 2 + }, + "62_1": { + "type": 2, + "health": 100, + "player": 2 + } + }, + + "events": { + "init": ["0_0", "63_0"], + "join_1": ["1_1", "1_0", "0_1"], + "join_2": ["62_0", "63_1", "62_1"] + } +} diff --git a/model/__init__.py b/server/model/__init__.py similarity index 100% rename from model/__init__.py rename to server/model/__init__.py diff --git a/model/grid.py b/server/model/grid.py similarity index 99% rename from model/grid.py rename to server/model/grid.py index 39817b6..84eac6d 100644 --- a/model/grid.py +++ b/server/model/grid.py @@ -157,7 +157,7 @@ def load(self, coords): return True def loadEvent(self, event): - f = open(config.path + "static/maps/%s_%s.json" % (self['size'], self['map']), "r") + f = open(config.path + "maps/%s_%s.json" % (self['size'], self['map']), "r") data = json.loads(f.read()) f.close() diff --git a/model/periodical.py b/server/model/periodical.py similarity index 100% rename from model/periodical.py rename to server/model/periodical.py diff --git a/model/tiles.py b/server/model/tiles.py similarity index 100% rename from model/tiles.py rename to server/model/tiles.py diff --git a/model/user.py b/server/model/user.py similarity index 100% rename from model/user.py rename to server/model/user.py diff --git a/requirements.txt b/server/requirements.txt similarity index 100% rename from requirements.txt rename to server/requirements.txt diff --git a/tests/__init__.py b/server/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to server/tests/__init__.py diff --git a/tests/__main__.py b/server/tests/__main__.py similarity index 100% rename from tests/__main__.py rename to server/tests/__main__.py diff --git a/tests/grid.py b/server/tests/grid.py similarity index 100% rename from tests/grid.py rename to server/tests/grid.py diff --git a/thegrid.py b/server/thegrid.py similarity index 95% rename from thegrid.py rename to server/thegrid.py index fe60197..e2344fb 100644 --- a/thegrid.py +++ b/server/thegrid.py @@ -12,7 +12,6 @@ app = tornado.web.Application([ # The API... Hereeee we go. ('/api/grid/exists', api.grid.Exists), - ('/api/grid/create', api.grid.Create), ('/api/grid/info', api.grid.Info), ('/api/socket', controller.SocketHandler), diff --git a/utility/__init__.py b/server/utility/__init__.py similarity index 100% rename from utility/__init__.py rename to server/utility/__init__.py diff --git a/utility/template.py b/server/utility/template.py similarity index 100% rename from utility/template.py rename to server/utility/template.py diff --git a/utility/updatemanager.py b/server/utility/updatemanager.py similarity index 100% rename from utility/updatemanager.py rename to server/utility/updatemanager.py diff --git a/static/js/HomeView.js b/static/js/HomeView.js deleted file mode 100644 index f5367da..0000000 --- a/static/js/HomeView.js +++ /dev/null @@ -1,226 +0,0 @@ -var HomeView = (function() { - var tpl = "home.html"; - - function onLoad() { - var xTiles, yTiles, grid; - AsyncClient.connect(function() { - AsyncClient.send("getGrids", {}, getGridsCb); - }); - $("#enter").click(function() { - var selected = $(".gridlist tr.selected"); - if(selected.length == 0) { - return; - } - GameData['gid'] = selected.data("gid"); - GameData['size'] = parseInt(selected.data("size")); - GameData['name'] = selected.data("name"); - if(selected.data("active") == 1) ViewController.load(GameView); - else enterRoom(); - }); - $(".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); - $(window).resize(windowResize); - - //generateGrid(); - } - - // Background animation stuff - // Compass starts at 0 and goes clockwise - function startBgAnimation() { - HomeView.anim = setInterval(proceedBgAnimation, 50); - HomeView.dots = []; - sendBgWave(); - } - function sendBgWave() { - var classes = ["blue", "green", "red", "yellow"]; - var elems = $("#home_grid tr:first-child td").get().sort(function(){ - return Math.round(Math.random())-0.5 - }).slice(0,1) - $(elems).each(function() { - var coord = new Coord($(this).attr("id")); - var cls = classes[Math.floor(Math.random() * classes.length)]; - $("#" + coord.x + "_" + coord.y).addClass(cls); - HomeView.dots.push({"x": coord.x, "y": coord.y, "class": cls}); - }); - HomeView.wave = setTimeout(sendBgWave, Math.floor(Math.random() * (800 - 300 + 1)) + 300); - } - - function proceedBgAnimation() { - $.each(HomeView.dots, function(i, dot) { - var coord, dir, next; - if(dot == undefined) return; - coord = $("#" + dot['x'] + "_" + dot['y']); - dir = checkDir(dot['x'], dot['y'], 2); - if(dir != true) { - HomeView.dots.splice(i, 1); - coord.removeClass(dot['class']); - return; - } - next = getMovedCoords(dot['x'], dot['y'], 2); - coord.removeClass(dot['class']); - coord = $("#" + next[0] + "_" + next[1]); - coord.addClass(dot['class']); - HomeView.dots[i]['x'] = next[0]; - HomeView.dots[i]['y'] = next[1]; - }); - } - - function stopBgAnimation() { - clearInterval(HomeView.anim); - clearTimeout(HomeView.wave); - } - - function checkDir(x, y, d) { - var next; - next = getMovedCoords(x, y, d); - if($("#"+ next[0] + "_" + next[1]).length == 0) { - return false - } else return true; - } - - function getMovedCoords(x, y, d) { - switch(d) { - case 0: - y--; - break; - case 1: - x++; - break; - case 2: - y++; - break; - case 3: - x--; - break; - } - return [x, y]; - } - - function generateGrid() { - // Populate the homegrid based on the window size - HomeView.x_tiles = parseInt($(window).width() / 32) - 1; - HomeView.y_tiles = parseInt($(window).height() / 32) - 1; - grid = $("#home_grid").html(""); - $(".grid_container").css("width", $(window).width()).css("height", $(window).height()) - for(var y = 0; y < HomeView.y_tiles; y++) { - tr = $("").appendTo(grid) - for(var x = 0; x < HomeView.x_tiles; x++) { - $(" ").appendTo(tr) - } - } - startBgAnimation(); - } - - function windowResize() { - stopBgAnimation(); - clearTimeout(HomeView.resize_to); - HomeView.resize_to = setTimeout(generateGrid, 250); - } - - function getGridsCb(data) { - var grids = data['grids']; - $("#loading_list").hide(); - for(grid in grids) { - $(""+ grids[grid]['name'] +""+ grids[grid]['players'] +" players") - .appendTo(".gridlist") - .data("gid", grids[grid]['gid']) - .data("active", grids[grid]['active']) - .data("name", grids[grid]['name']) - .data("size", grids[grid]['size']); - } - - if(grids.length == 0) { - $("#loading_list").text("No grids found.").show(); - } - setupList(); - } - - function setupList() { - $(".gridlist tr").off().click(function(e) { - $(".gridlist tr.selected").removeClass("selected"); - $(this).addClass("selected"); - $("#enter").removeClass("disabled"); - }); - } - - function createGame() { - SyncClient.post("grid/create", { - "name": $("input[name=room]").val(), - "size": $("input[name=size]").val(), - }, createGameCb); - } - - function createGameCb(data) { - if(data['status'] != 200) { - alert("Error! " + data['status']); - return; - } - - 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"); - } - - function cleanup() { - stopBgAnimation(); - } - - return { - "tpl": tpl, - "onLoad": onLoad, - "cleanup": cleanup, - "startBgAnimation": startBgAnimation, - "stopBgAnimation": stopBgAnimation, - "sendBgWave": sendBgWave, - "setupList": setupList, - } -})();