toss-devel-svn Mailing List for Toss (Page 11)
Status: Beta
Brought to you by:
lukaszkaiser
You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(25) |
Dec
(62) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(26) |
Feb
(38) |
Mar
(67) |
Apr
(22) |
May
(41) |
Jun
(30) |
Jul
(24) |
Aug
(32) |
Sep
(29) |
Oct
(34) |
Nov
(18) |
Dec
(2) |
2012 |
Jan
(19) |
Feb
(25) |
Mar
(16) |
Apr
(2) |
May
(18) |
Jun
(21) |
Jul
(11) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <luk...@us...> - 2011-07-01 23:30:25
|
Revision: 1499 http://toss.svn.sourceforge.net/toss/?rev=1499&view=rev Author: lukaszkaiser Date: 2011-07-01 23:30:17 +0000 (Fri, 01 Jul 2011) Log Message: ----------- Delete obsolete fontstyle, start adding game descriptions to WebClient. Modified Paths: -------------- trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html trunk/Toss/WebClient/register.html trunk/Toss/WebClient/support.html Removed Paths: ------------- trunk/Toss/WebClient/fontstyle.css Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-30 22:13:07 UTC (rev 1498) +++ trunk/Toss/WebClient/Main.js 2011-07-01 23:30:17 UTC (rev 1499) @@ -197,6 +197,8 @@ function play_click (game, play_id, pi) { document.getElementById ("opponents").style.display = "none"; + document.getElementById (game + "-desc").style.display = "block"; + document.getElementById ("game-desc-controls").style.display = "block"; list_plays (game); document.getElementById ("welcome").style.display = "none"; document.getElementById ("game-disp").style.display = "none"; @@ -307,14 +309,7 @@ function new_play_guest (game) { GAME_NAME = game; UNAME = "guest"; - wgame = game; - if (game == "Breakthrough") { wgame = "Breakthrough_(board_game)" }; - if (game == "Pawn-Whopping") { wgame = "Pawn_(chess)" }; - if (game == "Entanglement") { wgame = "Entanglement_(graph_measure)" }; - wiki = "http://en.wikipedia.org/wiki/" + wgame; - document.getElementById ("topuser").innerHTML = - game + ' (<a href="' + wiki + '">Move Rules</a>)'; - if (SIMPLE_SET) { document.getElementById ("topuser").innerHTML = game }; + document.getElementById ("topuser").innerHTML = game; document.getElementById ("game-title").style.display = "none"; document.getElementById ("game-title-move").style.display = "none"; document.getElementById ("game-info-par").style.paddingBottom = "1em"; @@ -332,6 +327,8 @@ } function new_play_do (opp_uid) { + document.getElementById (GAME_NAME + "-desc").style.display = "block"; + document.getElementById ("game-desc-controls").style.display = "block"; list_plays (GAME_NAME); document.getElementById ("welcome").style.display = "none"; document.getElementById ("game-disp").style.display = "none"; @@ -430,6 +427,17 @@ suggest_move_async (mv_time, function () {}); } +function toggle_game_desc () { + var bt = document.getElementById ("descbt"); + if (bt.innerHTML == "Hide") { + bt.innerHTML = "Show"; + document.getElementById (GAME_NAME + "-desc").style.display = "none"; + } else { + bt.innerHTML = "Hide"; + document.getElementById (GAME_NAME + "-desc").style.display = "block"; + } +} + function toggle_suggestions () { var txt = document.getElementById ("suggestions-toggle").innerHTML; if (txt.indexOf ("Before") == -1) { Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-30 22:13:07 UTC (rev 1498) +++ trunk/Toss/WebClient/Style.css 2011-07-01 23:30:17 UTC (rev 1499) @@ -484,7 +484,33 @@ color: #f5f2ef; } +.game-desc { + display: none; + width: 80%; + margin: auto; + padding-bottom: 1em; +} +.game-desc a, .game-desc a:link, .game-desc a:active, .game-desc a:visited { + color: #260314; + text-decoration: underline; +} + +.game-desc a:hover { + color: #400827; +} + +#game-desc-controls { + display: none; + width: 80%; + margin: auto; + text-align: center; +} + +#game-desc-title { + font-weight: bold; +} + /* Content */ .mail, .ta { Deleted: trunk/Toss/WebClient/fontstyle.css =================================================================== --- trunk/Toss/WebClient/fontstyle.css 2011-06-30 22:13:07 UTC (rev 1498) +++ trunk/Toss/WebClient/fontstyle.css 2011-07-01 23:30:17 UTC (rev 1499) @@ -1,86 +0,0 @@ -/* Generated by Font Squirrel (http://www.fontsquirrel.com); - http://www.fontsquirrel.com/fonts/TeX-Gyre-Heros - http://www.fontsquirrel.com/fonts/OFL-Sorts-Mill-Goudy -*/ - -@font-face { - font-family: 'OFLSortsMillGoudyRegular'; - src: url('OFLGoudyStM-webfont.eot'); - src: local('OFLMG'), url('OFLGoudyStM-webfont.woff') format('woff'), url('OFLGoudyStM-webfont.ttf') format('truetype'), url('OFLGoudyStM-webfont.svg#webfontwzHaehaw') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'OFLSortsMillGoudyItalic'; - src: url('OFLGoudyStM-Italic-webfont.eot'); - src: local('OFLMGI'), url('OFLGoudyStM-Italic-webfont.woff') format('woff'), url('OFLGoudyStM-Italic-webfont.ttf') format('truetype'), url('OFLGoudyStM-Italic-webfont.svg#webfontRrg0pQHE') format('svg'); - font-weight: normal; - font-style: normal; -} - - -@font-face { - font-family: 'TeXGyreHerosRegular'; - src: url('texgyreheros-regular-webfont.eot'); - src: local('☺'), url('texgyreheros-regular-webfont.woff') format('woff'), url('texgyreheros-regular-webfont.ttf') format('truetype'), url('texgyreheros-regular-webfont.svg#webfontLnIzFk4Q') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'TeXGyreHerosItalic'; - src: url('texgyreheros-italic-webfont.eot'); - src: local('☺'), url('texgyreheros-italic-webfont.woff') format('woff'), url('texgyreheros-italic-webfont.ttf') format('truetype'), url('texgyreheros-italic-webfont.svg#webfontvQjiCLIH') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'TeXGyreHerosBold'; - src: url('texgyreheros-bold-webfont.eot'); - src: local('☺'), url('texgyreheros-bold-webfont.woff') format('woff'), url('texgyreheros-bold-webfont.ttf') format('truetype'), url('texgyreheros-bold-webfont.svg#webfont2ZFI5J8u') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'TeXGyreHerosBoldItalic'; - src: url('texgyreheros-bolditalic-webfont.eot'); - src: local('☺'), url('texgyreheros-bolditalic-webfont.woff') format('woff'), url('texgyreheros-bolditalic-webfont.ttf') format('truetype'), url('texgyreheros-bolditalic-webfont.svg#webfontv2u9PPvQ') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'TeXGyreHerosCnRegular'; - src: url('texgyreheroscn-regular-webfont.eot'); - src: local('☺'), url('texgyreheroscn-regular-webfont.woff') format('woff'), url('texgyreheroscn-regular-webfont.ttf') format('truetype'), url('texgyreheroscn-regular-webfont.svg#webfontQv7FcPaV') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'TeXGyreHerosCnItalic'; - src: url('texgyreheroscn-italic-webfont.eot'); - src: local('☺'), url('texgyreheroscn-italic-webfont.woff') format('woff'), url('texgyreheroscn-italic-webfont.ttf') format('truetype'), url('texgyreheroscn-italic-webfont.svg#webfont4ZGc7aNL') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'TeXGyreHerosCnBold'; - src: url('texgyreheroscn-bold-webfont.eot'); - src: local('☺'), url('texgyreheroscn-bold-webfont.woff') format('woff'), url('texgyreheroscn-bold-webfont.ttf') format('truetype'), url('texgyreheroscn-bold-webfont.svg#webfontsYT6t1M5') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'TeXGyreHerosCnBoldItalic'; - src: url('texgyreheroscn-bolditalic-webfont.eot'); - src: local('☺'), url('texgyreheroscn-bolditalic-webfont.woff') format('woff'), url('texgyreheroscn-bolditalic-webfont.ttf') format('truetype'), url('texgyreheroscn-bolditalic-webfont.svg#webfont4yhgrpSG') format('svg'); - font-weight: normal; - font-style: normal; -} - Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-30 22:13:07 UTC (rev 1498) +++ trunk/Toss/WebClient/index.html 2011-07-01 23:30:17 UTC (rev 1499) @@ -7,7 +7,6 @@ content="Play the best strategic games online with a nice interface." /> <meta http-equiv="X-UA-Compatible" content="chrome=1" /> <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> - <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> @@ -210,8 +209,6 @@ <div id="plays"> </div> - - <div id="game-disp"> <p id="game-info-par"> <span id="game-title"></span> @@ -244,6 +241,144 @@ <div id="board"><div id="working">Working...</div></div> </div> +<div id="game-descs"> + <p id="game-desc-controls"> + <span id="game-desc-title">Game Description</span> + <button id="descbt" class="bt" onclick="toggle_game_desc ()">Hide</button> + </p> + <div class="game-desc" id="Breakthrough-desc"> + <p><a href="http://en.wikipedia.org/wiki/Breakthrough_(board_game)"> + Breakthrough</a> is an abstract strategy board game invented by + Dan Troyka in 2000. It won the 2001 8x8 Game Design Competition.</p> + <p><b>Moves.</b>The players alternate, with each player moving one piece + per turn. A piece may move one space straight or diagonally forward if + the target square is empty. A piece may move into a square containing an + opponent's piece only if that square is one step diagonally forward. + The opponent's piece is removed and the player's piece replaces it. + Capturing is not compulsory, nor is it chained as in checkers.</p> + <p><b>Objective.</b>The first player to reach the opponent's home + row – the one farthest from the player – is the winner. + If all the pieces of a player are captured, that player loses. + A draw is impossible.</p> + </div> + <div class="game-desc" id="Checkers-desc"> + <p><a href="http://en.wikipedia.org/wiki/Checkers">Checkers</a> or + English Draughts, also called American checkers or straight checkers, + are a form of draughts board game. Unlike international draughts, + it is played on an eight by eight squared board (with sixty-four total + squares) with twelve pieces on each side.</p> + <p><b>Moves.</b> A simple move involves sliding a piece one space + diagonally forwards to an adjacent unoccupied dark square. + A jump is a move from a square diagonally adjacent to one of + the opponent's pieces to an empty square immediately and directly on + the opposite side of the opponent's square, thus jumping directly over + the square containing the opponent's piece. An uncrowned piece may only + jump diagonally forwards, kings may jump diagonally backwards. A piece + that is jumped is captured and removed from the board. Multiple-jump + moves are possible if when the jumping piece lands, there is another + immediate piece that can be jumped; even if the jump is in a different + direction. Jumping is mandatory – whenever a player has the option + to jump, she must jump. When multiple-option jumping moves are available, + whether with the one piece in different directions or multiple pieces + that can make various jumping moves, the player may choose which piece to + jump with and which jumping option or sequence of jumps to make. + The jumping sequence chosen does not necessarily have to be the one that + would have resulted in the most captures; however, one must make all + available captures in the chosen sequence.</p> + <p><b>Kings.</b> If a player's piece moves into the kings row on + the opposing player's side of the board, that piece is said to be + crowned (or often kinged in the U.S.), becoming a king and gaining + the ability to move both forwards and backwards. If a player's piece + jumps into the kings row, the current move terminates; having just been + crowned, the piece cannot continue on by jumping back out (as in a + multiple jump), until the next move. Any piece, whether it is + a king or not, can jump a king.</p> + <p><b>Objective.</b> A player wins by capturing all of the opposing + player's pieces or by leaving the opposing player with no legal moves. + The game ends in a draw, if neither side can force a win.</p> + </div> + <div class="game-desc" id="Chess-desc"> + <p><a href="http://en.wikipedia.org/wiki/Chess">Chess</a> is a two-player + board game played on a chessboard, a square-checkered board with 64 + squares arranged in an eight-by-eight grid. Each player begins the game + with sixteen pieces: One king, one queen, two rooks, two knights, + two bishops, and eight pawns. Pieces move in different assigned ways + according to their type, and accordingly are used to attack and capture + the opponent's pieces. The object of the game is to checkmate + the opponent's king, whereby the king is under immediate attack + (in check) if there is no way to move or defend it.</p> + <p><b>Moves.</b> The moves differ by figure.</p> + <p><b>Objective.</b> Checkmate.</p> + </div> + <div class="game-desc" id="Connect4-desc"> + <p><a href="http://en.wikipedia.org/wiki/Connect4">Connect4</a> (also known + as Captain's Mistress, Four Up, Plot Four, Find Four, Four in a Row, + and Four in a Line) is a two-player game played on a standing grid.</p> + <p><b>Moves.</b> The players take turns dropping their colored discs from + the top into a seven-column, six-row grid. The pieces fall straight + down, occupying the next available space within the column, so to make + a move click on a field which is empty and on top of a non-empty one, + or in the bottom row.</p> + <p><b>Objective.</b> The objective of the game is to connect four of + one's own discs of the same color next to each other vertically, + horizontally, or diagonally before the opponent can do so.</p> + </div> + <div class="game-desc" id="Entanglement-desc"> + <p><a href="http://en.wikipedia.org/wiki/Entanglement_(graph_measure)"> + Entanglement</a> is a cops vs. robber game played on a graph, which + plays an important role in structural theory of directed graphs.</p> + <p><b>Moves.</b> The players move in turn. In each move the cops either + stay where they are, or place one of them on the vertex currently + occupied by the robber. The robber must move from her current vertex, + along an edge, to a successor that is not occupied by a cop. The robber + must move even if no cop is following him.</p> + <p><b>Objective.</b> If there is no free successor to which the robber + can move, she is caught, and the cops win. The robber wins if she cannot + be caught and the cops give up.</p> + </div> + <div class="game-desc" id="Gomoku-desc"> + <p><a href="http://en.wikipedia.org/wiki/Gomoku">Gomoku</a> is an abstract + strategy board game and is also called Five in a Row. The name Gomoku is + from the Japanese language, in which it is referred to as gomokunarabe + Go means five, moku is a counter word for pieces and narabe means line-up. + The game is also popular in Korea, where it is called omok.</p> + <p><b>Moves.</b> Players alternate in placing a cross or a circle on an + empty square, starting from an empty 8×8 board.</p> + <p><b>Objective.</b> The winner is the first player to get an unbroken + row of five stones horizontally, vertically, or diagonally.</p> + </div> + <div class="game-desc" id="Pawn-Whopping-desc"> + <p><a href="http://en.wikipedia.org/wiki/Pawn_(chess)">Pawn-Whopping</a> + is a training game for chess players. The aim is to improve one's + handling of pawn play by concentrating solely on this aspect of chess.</p> + <p><b>Moves.</b> The standard Chess pawn moves apply. Normally a pawn moves + by advancing a single square, but the first time each pawn is moved from + its initial position, it has the option to advance two squares. Pawns may + not use the initial two-square advance to jump over an occupied square, + or to capture. Any piece directly in front of a pawn, friend or foe, + blocks its advance. A pawn captures diagonally, one square forward and to + the left or right. Additionally, it may capture en passant. This arises + when a pawn uses its initial-move option to advance two squares instead + of one, and in so doing passes over a square that is attacked by an enemy + pawn. That enemy pawn, which would have been able to capture the moving + pawn had it advanced only one square, is entitled to capture the moving + pawn in passing, as if it had advanced only one square.</p> + <p><b>Objective.</b> The goal in Pawn-Whopping is simply to be the first + to bring one of the pawns to the other end of the board.</p> + </div> + <div class="game-desc" id="Tic-Tac-Toe-desc"> + <p><a href="http://en.wikipedia.org/wiki/Tic-tac-toe">Tic-Tac-Toe</a> + also rendered wick wack woe (in some Asian countries), or noughts and + crosses/Xs and Os as it is known in the UK, Australia and New Zealand, + is a pencil-and-paper game for two players, X and O, who take turns + marking the spaces in a 3×3 grid.</p> + <p><b>Moves.</b> Players alternate in placing a cross or a circle on an + empty square.</p> + <p><b>Objective.</b> The player who first succeeds in placing three + respective marks in a horizontal, vertical, or diagonal row + wins the game.</p> + </div> +</div> <div id="bottom"> <div id="bottomright"> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-06-30 22:13:07 UTC (rev 1498) +++ trunk/Toss/WebClient/profile.html 2011-07-01 23:30:17 UTC (rev 1499) @@ -5,7 +5,6 @@ <title>tPlay — Profile</title> <meta http-equiv="X-UA-Compatible" content="chrome=1" /> <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> - <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> Modified: trunk/Toss/WebClient/register.html =================================================================== --- trunk/Toss/WebClient/register.html 2011-06-30 22:13:07 UTC (rev 1498) +++ trunk/Toss/WebClient/register.html 2011-07-01 23:30:17 UTC (rev 1499) @@ -5,7 +5,6 @@ <title>tPlay — Registration</title> <meta http-equiv="X-UA-Compatible" content="chrome=1" /> <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> - <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> Modified: trunk/Toss/WebClient/support.html =================================================================== --- trunk/Toss/WebClient/support.html 2011-06-30 22:13:07 UTC (rev 1498) +++ trunk/Toss/WebClient/support.html 2011-07-01 23:30:17 UTC (rev 1499) @@ -5,7 +5,6 @@ <title>tPlay — Support</title> <meta http-equiv="X-UA-Compatible" content="chrome=1" /> <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> - <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="Login.js"> </script> </head> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-30 22:13:14
|
Revision: 1498 http://toss.svn.sourceforge.net/toss/?rev=1498&view=rev Author: lukaszkaiser Date: 2011-06-30 22:13:07 +0000 (Thu, 30 Jun 2011) Log Message: ----------- WebClient corrections. Modified Paths: -------------- trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html Removed Paths: ------------- trunk/Toss/WebClient/msw.html trunk/Toss/WebClient/msw.js Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/Login.js 2011-06-30 22:13:07 UTC (rev 1498) @@ -35,18 +35,6 @@ FRIENDS = parse_list (',', lst); } -// Clear view -function clear_view () { - document.getElementById("loginform").style.display = "inline"; - document.getElementById("topright-register").style.display = "inline"; - document.getElementById("topright").style.display = "none"; - document.getElementById("topuser").innerHTML = ""; - document.getElementById("plays").style.display = "none"; - document.getElementById("game-title").style.display = "none"; - document.getElementById("game-disp").style.display = "none"; - document.getElementById("welcome").style.display = "block"; -} - // Onload handler function startup (game) { GAMESPAGE = new GamesPage ("plays", GAMES); @@ -59,6 +47,7 @@ } if (window.location.href.indexOf("?simple=true") > 0) { SIMPLE_SET = true; + document.getElementById("gamestablink").href = "index.html?simple=true"; document.getElementById("pdescChess").style.display = "block"; document.getElementById("pdescConnect4").style.display = "block"; document.getElementById("pdescPawn-Whopping").style.display = "block"; @@ -182,7 +171,6 @@ // Logout function logout () { - //clear_view (); var resp = CONN.logout (); window.location.reload (); return; Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/Main.js 2011-06-30 22:13:07 UTC (rev 1498) @@ -315,13 +315,14 @@ document.getElementById ("topuser").innerHTML = game + ' (<a href="' + wiki + '">Move Rules</a>)'; if (SIMPLE_SET) { document.getElementById ("topuser").innerHTML = game }; - document.getElementById ("pdescBack").style.display = "inline"; document.getElementById ("game-title").style.display = "none"; + document.getElementById ("game-title-move").style.display = "none"; document.getElementById ("game-info-par").style.paddingBottom = "1em"; document.getElementById ("loginform").style.display = "none"; document.getElementById ("topright-register").style.display = "none"; document.getElementById ("topright").style.display = "inline"; - document.getElementById ("logoutbt").style.display = "none"; + document.getElementById ("logouttab").style.display = "none"; + document.getElementById ("profiletab").style.display = "none"; document.getElementById ("welcome").style.display = "none"; if (game == "Chess") { show_chess_warning (); @@ -415,8 +416,8 @@ function suggest_move_async (time, f) { show_moving_msg (time); var fm = function (m) { - document.getElementById ("working").style.display = "none"; - document.getElementById ("working").innerHTML = "Working..."; + document.getElementById("working").style.display = "none"; + document.getElementById("working").innerHTML = "Working..."; if (m != "") { PLAYS[CUR_PLAY_I].show_move (new Move (m)); f() } }; CONN.suggest (PLAYS[CUR_PLAY_I].cur_state.players[0]+1, time, @@ -424,6 +425,7 @@ } function suggest_move_click () { + if (PLAYS[CUR_PLAY_I].move_nbr < PLAYS[CUR_PLAY_I].last_move_nbr) {return;} var mv_time = document.getElementById ("speed").value; suggest_move_async (mv_time, function () {}); } @@ -440,32 +442,11 @@ } else { SIMPLE_MOVES = false; document.getElementById ("play-nbr-info").style.display = "inline"; + document.getElementById ("game-title").style.display = "inline"; + document.getElementById ("game-title-move").style.display = "inline"; document.getElementById ("board").style.paddingTop = "0em"; document.getElementById ("suggestions-toggle").innerHTML = "Move Without Asking"; document.getElementById ("move-info-par").style.display = "block"; } } - -function msw_play_from_string (s) { - var lst = parse_list ('#', s); - return (new Play (lst[0], [0, 1], [lst[1], lst[2]], - lst[3], lst[4], lst[5], UNAME)); -} - -function UserData(){ - var udata = CONN.plays(); - udata = udata.split("@"); - this.user = udata[0]; - this.userName = udata[1]; - this.play_lists = new Object(); - for (var i=2; i < udata.length; i++){ - var plays = parse_list("##", udata[i]); - for (var j=0; j < plays.length; j++){ - var play = msw_play_from_string(plays[j]); - var key = play.game; - if (this.play_lists[key] == undefined) this.play_lists[key] = new Object(); - this.play_lists[key][play.pid] = play; - } - } -} Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/Play.js 2011-06-30 22:13:07 UTC (rev 1498) @@ -16,12 +16,14 @@ this.players[game_players[i]] = player_names[i]; } this.pid = pid; - this.move_nbr = move; + this.move_nbr = parseInt(move); + this.last_move_nbr = this.move_nbr; var mirror = 0; if (game == "Connect4") { mirror = 0; } else { mirror = (player_names[0] == this.cur_player_uid) ? 0 : 1; } this.cur_state = new State (game, state_str, mirror); + this.last_state_str = state_str; this.ELEM_COUNTERS = {}; this.CUR_MOVE = ""; @@ -33,7 +35,9 @@ function play_new_state (state_str) { this.cur_state = new State (this.game, state_str, this.cur_state.mirror); + this.last_state_str = state_str; this.move_nbr = this.move_nbr + 1; + this.last_move_nbr = this.move_nbr; } Play.prototype.new_state = play_new_state; @@ -56,6 +60,7 @@ PlayDISP.show_payoff (this); this.cur_state.draw_model (this.game); document.getElementById("speedtab").style.display = "inline"; + document.getElementById("movenbr").innerHTML = this.move_nbr; } Play.prototype.redraw = play_redraw; @@ -131,6 +136,7 @@ function play_move () { if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } if (this.CUR_MOVE == "") return; + if (this.move_nbr < this.last_move_nbr) { return; } var m = parseInt(this.CUR_MOVE.substring (0, 1)) - 1; if (!isNaN(m) && this.players[m] != this.cur_player_uid && this.players[m] != "computer") { @@ -155,64 +161,65 @@ Play.prototype.move_continue = play_move_continue; function play_prev_move () { - alert (CONN.prev_move (this.pid, this.move_nbr - 1)); + var prev = CONN.prev_move (this.pid, this.move_nbr - 1); + if (prev == "NONE") { return; } + this.cur_state = new State (this.game, prev, this.cur_state.mirror); + this.move_nbr = this.move_nbr - 1; + this.redraw (); } Play.prototype.prev_move = play_prev_move; function play_next_move () { - alert (CONN.prev_move (this.pid, this.move_nbr + 1)); + var next = CONN.prev_move (this.pid, this.move_nbr + 1); + if (next == "NONE") { + this.cur_state = + new State (this.game, this.last_state_str, this.cur_state.mirror); + this.move_nbr = this.last_move_nbr; + } else { + this.cur_state = new State (this.game, next, this.cur_state.mirror); + this.move_nbr = this.move_nbr + 1; + } + this.redraw (); } Play.prototype.next_move = play_next_move; -Play.prototype.get_winners = function() -{ - var result; - if (this.cur_state.result != null) result = this.cur_state.result; - else return null; - var winners = new Array(); - var maximum, minimum; - for (index in result) - { - if (maximum != undefined) - { - if (result[index] > maximum) - { - maximum = result[index]; - winners = new Array(this.players[index]); - } - else - { - if (result[index] == maximum) winners.push(this.players[index]); - else minimum = result[index]; - } - } - else - { - minimum = maximum = result[index]; - winners = new Array(this.players[index]); - } - } - if (maximum > minimum) return winners; - else return null; +Play.prototype.get_winners = function () { + var result; + if (this.cur_state.result != null) { + result = this.cur_state.result; + } else { return null; } + var winners = new Array(); + var maximum, minimum; + for (index in result) { + if (maximum != undefined) { + if (result[index] > maximum) { + maximum = result[index]; + winners = new Array(this.players[index]); + } else { + if (result[index] == maximum) { + winners.push(this.players[index]); + } else { minimum = result[index]; } + } + } else { + minimum = maximum = result[index]; + winners = new Array(this.players[index]); + } + } + if (maximum > minimum) { return winners; } else { return null; } } -Play.prototype.get_formatted_result_string = function () -{ - var result_string = ""; - if (this.cur_state.result == null) return ""; - else - { - winners = this.get_winners(); - if (winners == null) return "Tie"; - if (winners.length == 0) return null; - for (var i=0; i < winners.length; i++) - { - if (i > 0) result_string += ', ' + disp_name(winners[i]); - else result_string = disp_name(winners[i]); - } - result_string += " won"; - return result_string; - } +Play.prototype.get_formatted_result_string = function () { + var result_string = ""; + if (this.cur_state.result == null) { return ""; } + winners = this.get_winners(); + if (winners == null) { return "Tie"; } + if (winners.length == 0) { return null; } + for (var i=0; i < winners.length; i++) { + if (i > 0) result_string += ', ' + disp_name(winners[i]); + else result_string = disp_name(winners[i]); + } + result_string += " won"; + return result_string; } // --- Wrapper Class for unified handling of Play display functions --- Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/Style.css 2011-06-30 22:13:07 UTC (rev 1498) @@ -170,25 +170,6 @@ opacity: 1; } -.logo-picspan { - position: relative; - top: -0.5em; - left: 0px; - display: none; - font-size: 1.1em; - font-weight: bold; -} - -.logo-pictxt { - position: relative; - top: 0em; - border-radius: 4px; - -moz-border-radius: 4px; - opacity: 1; - font-size: 1em; - background-color: rgba(64, 8, 39, 0.7); -} - #leftupperlogo-img { position: relative; left: -0.2em; @@ -220,11 +201,14 @@ #speed { position: relative; - top: 0px; + top: -0.1em; font-weight: bold; font-family: Verdana, 'TeXGyreHerosRegular', sans; + font-size: 0.8em; color: #fff1d4; background-color: #777777; + padding: 0px; + margin: 0px; border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; @@ -394,33 +378,32 @@ .toprighttab { position: relative; - top: 0.5em; + top: 0.8em; background-color: #260314; border-color: #fff1d4; border-style: solid; border-width: 2px 2px 0px 2px; border-radius: 6px 6px 0px 0px; - padding-top: 0.15em; - padding-bottom: 0.3em; + padding-top: 0.1em; + padding-bottom: 0.2em; -moz-border-radius: 6px 6px 0px 0px; } #bottom { position: absolute; - bottom: 0px; - left: 0em; + bottom: 1px; + left: 0px; width: 100%; padding: 0px; margin: 0px; height: 1.3em; - text-align: center; font-size: 0.9em; font-weight: bold; color: #fff1d4; background-color: #400827; border-color: #260314; border-style: solid; - border-width: 5px 0px 0px 0px; + border-width: 3px 0px 1px 0px; } #bottom a, #bottom a:link, #bottom a:active, #bottom a:visited { @@ -436,27 +419,40 @@ /* Bottom styles. */ -.contact { +#bottomright { position: absolute; - top: 0px; - right: 0.5em; - color: inherit; + top: 0em; + right: 1em; + margin-right: 0em; } -#suggestions-toggle { - position: absolute; - margin: 0px; - padding: 0px; - top: 0px; - left: 0.5em; - border: 0px; - background-color: #400827; +#toss-link, .contact, #suggestions-toggle { + position: relative; + top: -1px; + padding-left: 0.5em; + padding-right: 0.5em; color: #fff1d4; - font-family: Verdana, 'TeXGyreHerosRegular', sans; font-size: 1em; font-weight: bold; + font-family: Verdana; + background-color: #260314; + border-color: #fff1d4; + border-style: solid; + border-width: 0px 2px 2px 2px; + border-radius: 0px 0px 6px 6px; + -moz-border-radius: 0px 0px 6px 6px; } +#toss-link { + display: none; +} + +#suggestions-toggle { + margin: 0px; + padding-top: 0px; + padding-bottom: 0px; +} + #suggestions-toggle:hover { color: #ffffff; text-decoration: underline; @@ -694,6 +690,10 @@ padding: 0px; } +#nextmovebt { + display: inline; +} + #player-info-par { display: none; margin-top: 0.5em; Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/index.html 2011-06-30 22:13:07 UTC (rev 1498) @@ -24,9 +24,6 @@ <div id="top"> <div id="logo"> <a id="leftupperlogo-link" href="index.html"> - <span id="pdescBack" class="logo-picspan"> - <span class="logo-pictxt">⇐</span> - </span> <img id="leftupperlogo-img" src="toss.png" alt="tPlay" /> </a> </div> @@ -56,27 +53,14 @@ </div> <span id="topright"> <span class="toprighttab"> - <a href="index.html">Games</a> + <a href="index.html" id="gamestablink">Games</a> </span> - <span class="toprighttab"> + <span class="toprighttab" id="profiletab"> <a href="profile.html">Profile</a> - </span> - <span class="toprighttab"> + </span> + <span class="toprighttab" id="logouttab"> <button id="logoutbt" onclick="logout()">Logout</button> </span> - <span class="toprighttab" id="speedtab" style="display: none;"> - Speed: <select id="speed"> - <option class="speed_val" value="1">1s</option> - <option class="speed_val" value="2">2s</option> - <option class="speed_val" value="3">3s</option> - <option class="speed_val" value="4">4s</option> - <option class="speed_val" value="5">5s</option> - <option class="speed_val" value="10">10s</option> - <option class="speed_val" value="15">15s</option> - <option class="speed_val" value="30">30s</option> - <option class="speed_val" value="60">60s</option> - </select> - </span> </span> <span id="topright-register"> <a href="register.html">Register</a> @@ -189,6 +173,7 @@ <div id="news"> <h3>News</h3> <ul id="welcome-list-news" class="welcome-list"> +<li><b>30/06/11</b> View previous moves in a play</li> <li><b>27/06/11</b> Tabs and searching opponents in the profile page</li> <li><b>22/06/11</b> Better organized lists of plays</li> <li><b>19/06/11</b> News section on the front page of tPlay</li> @@ -233,6 +218,12 @@ <span id="play-nbr-info" style="display:none;"> (game <span id="play-number">?</span>) </span> + <span id="game-title-move">Move <span id="movenbr">?</span> + <button id="prevmovebt" class="bt" onclick="prev_move_click()"> + – + </button><button id="nextmovebt" class="bt" onclick="next_move_click()"> + + + </button></span> <span id="payoffs" style="display:none;">Not Finished Yet</span> </p> <p id="new-play-par"> @@ -249,25 +240,39 @@ <button id="sugbt" class="bt" onclick="suggest_move_click()"> Suggest </button> - <button id="prevmovebt" class="bt" onclick="prev_move_click()"> - Prev - </button> - <button id="nextmovebt" class="bt" onclick="next_move_click()"> - Next - </button> </p> <div id="board"><div id="working">Working...</div></div> </div> <div id="bottom"> -<button id="suggestions-toggle" style="display: none;" - onclick="toggle_suggestions()">Ask Before Move</button> -<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> -<script type="text/javascript">begin_mailto( - "tossplay", "gmail.com", "Contact Us");</script> -tossplay [AT] gmail [DOT] com -<script type="text/javascript">end_mailto();</script> + <div id="bottomright"> + <a href="http://toss.sourceforge.net" id="toss-link"> + Powered by Toss + </a><script type="text/javascript">begin_mailto( + "tossplay", "gmail.com", "Contact Us");</script> + tossplay [AT] gmail [DOT] com + <script type="text/javascript"> + end_mailto(); + </script> + <button id="suggestions-toggle" style="display: none;" + onclick="toggle_suggestions()"> + Ask Before Move + </button> + <span class="contact" id="speedtab" style="display: none;"> + Speed: <select id="speed"> + <option class="speed_val" value="1">1s</option> + <option class="speed_val" value="2">2s</option> + <option class="speed_val" value="3">3s</option> + <option class="speed_val" value="4">4s</option> + <option class="speed_val" value="5">5s</option> + <option class="speed_val" value="10">10s</option> + <option class="speed_val" value="15">15s</option> + <option class="speed_val" value="30">30s</option> + <option class="speed_val" value="60">60s</option> + </select> + </span> + </div> </div> </div> Deleted: trunk/Toss/WebClient/msw.html =================================================================== --- trunk/Toss/WebClient/msw.html 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/msw.html 2011-06-30 22:13:07 UTC (rev 1498) @@ -1,72 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xml:lang="en" lang="en"> -<head> - <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> - <title>tPlay</title> - <meta name="Description" - content="Play the best strategic games online with a nice interface." /> - <meta http-equiv="X-UA-Compatible" content="chrome=1" /> - <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> - <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> - <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> - <script type="text/javascript" src="crypto-sha256.js"> </script> - <script type="text/javascript" src="Connect.js"> </script> - <script type="text/javascript" src="State.js"> </script> - <script type="text/javascript" src="Main.js"> </script> - <script type="text/javascript" src="Login.js"> </script> - <script type="text/javascript" src="msw.js"></script> - <!--<script type="text/javascript" src="Model.js"></script>--> -</head> - -<body> - -<div id="main"> -<span id="topright"> - Speed: <select id="speed"> - <option class="speed_val" value="1">1s</option> - <option class="speed_val" value="2">2s</option> - <option class="speed_val" value="3">3s</option> - <option class="speed_val" value="4">4s</option> - <option class="speed_val" value="5">5s</option> - <option class="speed_val" value="10">10s</option> - <option class="speed_val" value="15">15s</option> - <option class="speed_val" value="30">30s</option> - <option class="speed_val" value="60">60s</option> - </select> - <button id="logoutbt" onclick="logout()">Logout</button> -</span> - -<div id="plays"></div> - -<div id="game-disp"> - <p id="game-info-par"> - <span id="game-title"></span> - <span id="play-nbr-info" style="display:none;"> - (game <span id="play-number">?</span>) - </span> - <span id="payoffs" style="display:none;">Not Finished Yet</span> - </p> - - <p id="new-play-par"> - <button id="new_game_me" class="bt" onclick="play_anew(true)"> - New Game (You Start) - </button> - <button id="new_game_opp" class="bt" onclick="play_anew(false)"> - New Game (Opponent Starts) - </button> - </p> - - <p id="move-info-par"> - <button id="movebt" class="bt" onclick="make_move ()">Make move:</button> - <span id="cur-move">none</span> - <button id="sugbt" class="bt" onclick="suggest_move_click()"> - Suggest - </button> - </p> - <div id="board"><div id="working">Working...</div></div> -</div> -</div> - - -</body> -</html> Deleted: trunk/Toss/WebClient/msw.js =================================================================== --- trunk/Toss/WebClient/msw.js 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/msw.js 2011-06-30 22:13:07 UTC (rev 1498) @@ -1,46 +0,0 @@ -GAMES = new Array( - "Breakthrough", - "Checkers", - "Chess", - "Connect4", - "Entanglement", - "Gomoku", - "Pawn-Whopping", - "Tic-Tac-Toe", - "Concurrent-Tic-Tac-Toe" - ); - -function GamesPage(id, games){// html tag id - this.games = games; - this.paragraphs = new Object(); - this.container = document.getElementById(id); - for (var i = 0; i < this.games.length; i++){ - var game = this.games[i]; - var paragraph = this.paragraphs[game] = document.createElement("p"); - paragraph.setAttribute("class", "game-par"); - var button = paragraph.button = document.createElement("button"); - button.setAttribute("class", "boldobt"); - button.setAttribute("onclick", "new_play('" + game + "')"); - button.innerHTML = game; - this.container.appendChild(paragraph); - paragraph.appendChild(button); - - var open_play_list = paragraph.open_play_list = document.createElement("ul"); - open_play_list.setAttribute("class", "play-list"); - open_play_list.setAttribute("id", "a-plays-list-" + game); - paragraph.appendChild(open_play_list); - - var closed_play_list = paragraph.closed_play_list = document.createElement("ul"); - closed_play_list.setAttribute("class", "play-list"); - closed_play_list.setAttribute("id", "d-plays-list-" + game); - paragraph.appendChild(closed_play_list); - } -} - -GamesPage.prototype.show = function(){ - this.container.style.display = "block"; -} - -GamesPage.prototype.hide = function(){ - this.container.style.display = "none"; -} Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-06-28 00:48:40 UTC (rev 1497) +++ trunk/Toss/WebClient/profile.html 2011-06-30 22:13:07 UTC (rev 1498) @@ -134,11 +134,13 @@ </div> <div id="bottom"> -<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> -<script type="text/javascript">begin_mailto( - "tossplay", "gmail.com", "Contact Us");</script> -tossplay [AT] gmail [DOT] com -<script type="text/javascript">end_mailto();</script> + <div id="bottomright"> + <a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> + <script type="text/javascript">begin_mailto( + "tossplay", "gmail.com", "Contact Us");</script> + tossplay [AT] gmail [DOT] com + <script type="text/javascript">end_mailto();</script> + </div> </div> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-28 00:48:46
|
Revision: 1497 http://toss.svn.sourceforge.net/toss/?rev=1497&view=rev Author: lukaszkaiser Date: 2011-06-28 00:48:40 +0000 (Tue, 28 Jun 2011) Log Message: ----------- Tabs and opponents searching in profile. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-28 00:48:40 UTC (rev 1497) @@ -607,8 +607,33 @@ "\nYou can change it after you login on tPlay.\n" ^ "\nThank You!\n\ntPlay Team\n") in ignore (send_mail email "New password on tPlay.org" mailtxt); + print_endline "Subject: New password on tPlay.org"; print_endline mailtxt; "Your password has been reset and sent to " ^ email ^ "." in + let search_users txt = + let l, txtlen = "like \"%" ^ txt ^ "%\"", String.length txt in + let query_s = + Printf.sprintf "name %s or surname %s or id %s or email %s" l l l l in + let all = List.map (fun a -> a.(0)) (dbtable query_s "users") in + lstr (List.filter (fun s -> String.length s < 2*txtlen + 1) all) in + let invite uid email = + let usrs = dbtable ("email='" ^ email ^ "'") "users" in + if List.length usrs > 0 then + Printf.sprintf "Sorry, %s is already a registered email." email + else + let (uname, usurname, umail) = get_user_name_surname_mail uid in + let mailtxt = + ("\nYour Friend invites you to play on tPlay.org\n\n" ^ + "\nYour friend " ^ uname ^ " " ^ usurname ^ " (" ^ umail ^ ") " ^ + "invites you to join a game on tPlay.org.\n" ^ + "To this end, please register on: www.tplay.org/register.html\n" ^ + "\nWe wish you a good game!\n\ntPlay Team\n") in + let subj = + Printf.sprintf "Invitation to tPlay.org from %s %s" uname usurname in + ignore (send_mail email subj mailtxt); + print_endline ("Subject: " ^ subj); + print_endline mailtxt; + "Invitation email has been sent to " ^ email ^ "." in let (tcmd, data) = split_two "#" msg in let resp, new_cookies = match tcmd with | "USERNAME" -> @@ -634,6 +659,8 @@ let c = [(tID ^ "username", "a", None); (tID ^ "passphrase", "a", None)] in ("User logged out: " ^ (verif_uid ()), c) + | "SEARCHUSR" -> + search_users data, [] | "ADDOPP" -> add_opponent (verif_uid ()) data, [] | "GET_NAME" -> @@ -645,6 +672,9 @@ | "GET_MAIL" -> if verif_uid()="" then "You must login first to get email data.", [] else let (_, _, mail) = get_user_name_surname_mail data in mail, [] + | "INVITE" -> + let uid = verif_uid () in + if uid = "" then "Error: please Log In again", [] else invite uid data, [] | "FORGOTPWD" -> forgotpwd data, [] | "CHANGEPWD" -> Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/WebClient/Connect.js 2011-06-28 00:48:40 UTC (rev 1497) @@ -122,7 +122,7 @@ } this.friends = function () { return (srv ("LIST_FRIENDS", "user")); } - this.allopnts = function () { return (srv ("LIST_FRIENDS", "**")); } + this.search_users = function (txt) { return (srv ("SEARCHUSR", txt)); } this.plays = function () { return (srv("USERPLAYS", "user")); } this.username = function () { return (srv("USERNAME", "user")); } this.addopp = function (opp) { return (srv("ADDOPP", opp)); } @@ -138,6 +138,7 @@ this.register = function (data, cpwd) { return (srv ("REGISTER", data + "$" + cpwd)); } + this.invite = function (mail) { return (srv("INVITE", mail)); } this.forgotpwd = function (mail) { return (srv("FORGOTPWD", mail)); } this.change_pwd = function (un, pwd) { var resp = srv("CHANGEPWD", pwd); Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/WebClient/Login.js 2011-06-28 00:48:40 UTC (rev 1497) @@ -31,7 +31,8 @@ list_plays_string ("Pawn-Whopping", udata[8]); list_plays_string ("Tic-Tac-Toe", udata[9]); /* list_plays_string ("Concurrent-Tic-Tac-Toe", udata[10]); */ - get_opponents (); + var lst = CONN.friends (); + FRIENDS = parse_list (',', lst); } // Clear view @@ -86,13 +87,54 @@ } } -// Html of the list item for adding new opponents. -function add_opponent_item_html (uname) { - var onclick = 'onclick="add_opponent (' + "'" + uname + "'" + ')"'; - var bt = '<button class="bt" ' + onclick + ">Add</button>" - return (bt + " " + disp_name(uname) + " (" + uname + ")") +// Find opponents given (email or name or surname or username). +function find_opnts () { + var txt = document.getElementById('findopnt').value; + if (txt.length < 2) { + alert ("Emails and names have at least 2 letters." + CORRMSG); + return; + } + if (txt.indexOf(" ") > 0) { + alert ("Emails and names do not contain spaces." + CORRMSG); + return; + } + // Get the list of found users. + var lst = CONN.search_users (txt); + var users = parse_list (',', lst); + + // Offer to email an invitation if no user was found. + document.getElementById("invite").style.display = "block"; + + // Helper function: html of the list item for adding new opponents. + var add_opponent_item_html = function (uname) { + var onclick = 'onclick="add_opponent (' + "'" + uname + "'" + ')"'; + var bt = '<button class="bt" ' + onclick + ">Add</button>" + return (bt + " " + disp_name(uname) + " (" + uname + ")") + } + + // Print out the found list. + var u = document.getElementById("add-opponents-list"); + while (u.childNodes.length > 0) { u.removeChild (u.firstChild); } + for (var i = 0; i < users.length; i++) { + if (users[i] != UNAME && FRIENDS.indexOf(users[i]) == -1) { + var li = document.createElement('li'); + li.innerHTML = add_opponent_item_html (users[i]); + u.appendChild (li); + } + } } +// Send invitation email to a new user. +function invite () { + var email = document.getElementById('findopnt').value; + if (email.indexOf("@") < 1 || email.indexOf(".") < 1) { + alert ("Please provide a valid email address in the search field."); + return; + } + alert (CONN.invite (email)); + window.location.reload(); +} + // Onload handler for the profile page function startup_profile () { var un = CONN.username (); @@ -108,23 +150,14 @@ document.getElementById('name').value = CONN.name (un); document.getElementById('surname').value = CONN.surname (un); document.getElementById('email').value = CONN.email (un); - get_opponents (); + var lst = CONN.friends (); + FRIENDS = parse_list (',', lst); var o = document.getElementById("opponents-list"); for (var i = 0; i < FRIENDS.length; i++) { var li = document.createElement('li'); li.innerHTML = disp_name(FRIENDS[i]) + " (" + FRIENDS[i] + ")"; o.appendChild (li); } - var lst = CONN.allopnts (); - var users = parse_list (',', lst); - var u = document.getElementById("users-list"); - for (var i = 0; i < users.length; i++) { - if (users[i] != un && FRIENDS.indexOf(users[i]) == -1) { - var li = document.createElement('li'); - li.innerHTML = add_opponent_item_html (users[i]); - u.appendChild (li); - } - } }; } @@ -149,19 +182,15 @@ // Logout function logout () { - clear_view (); - resp = CONN.logout (); + //clear_view (); + var resp = CONN.logout (); + window.location.reload (); return; } function logout_profile () { - document.getElementById("loginform").style.display = "inline"; - document.getElementById("topright-register").style.display = "inline"; - document.getElementById("topright").style.display = "none"; - document.getElementById("topuser").innerHTML = ""; - document.getElementById("main-profile").style.display = "none"; - document.getElementById("welcome").style.display = "block"; - resp = CONN.logout (); + var resp = CONN.logout (); + window.location.reload (); return; } Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/WebClient/Main.js 2011-06-28 00:48:40 UTC (rev 1497) @@ -363,11 +363,6 @@ //document.getElementById ("plays-list-" + GAME_NAME).appendChild (li); } -function get_opponents () { - var lst = CONN.friends (); - FRIENDS = parse_list (',', lst); -} - function play_anew (me_starts) { document.getElementById ('payoffs').innerHTML = "Not Finished Yet"; document.getElementById ('payoffs').style.display = "none"; Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/WebClient/Play.js 2011-06-28 00:48:40 UTC (rev 1497) @@ -55,6 +55,7 @@ PlayDISP.set_cur_move ("", ""); PlayDISP.show_payoff (this); this.cur_state.draw_model (this.game); + document.getElementById("speedtab").style.display = "inline"; } Play.prototype.redraw = play_redraw; Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/WebClient/Style.css 2011-06-28 00:48:40 UTC (rev 1497) @@ -220,34 +220,42 @@ #speed { position: relative; - top: -2px; + top: 0px; font-weight: bold; font-family: Verdana, 'TeXGyreHerosRegular', sans; - color: #400827; - background-color: #fff1d4; + color: #fff1d4; + background-color: #777777; border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; - border-width: 1px; + border-width: 0px; } .speed_val { - color: #400827; - background-color: #fff1d4; - border-color: #400827; + color: #fff1d4; + font-weight: bold; + background-color: #666666; + border-width: 0px; } -.forminput { +.forminput, .hiddenforminput { border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; border-width: 2px; position: relative; top: 2px; + width: 12em; } -.list_result -{ +.hiddenforminput { + color: #fff1d4; + background-color: #fff1d4; + border: 0px; + margin: 4px; +} + +.list_result { font-size: 0.9em } @@ -284,16 +292,11 @@ } #logoutbt { - position: relative; - top: -0.1em; font-family: Verdana, 'TeXGyreHerosRegular', sans; font-size: 1em; font-weight: bold; color: #fff1d4; - background-color: #400827; - border-color: #fff1d4; - border-radius: 4px; - -moz-border-radius: 4px; + background-color: #260314; border-width: 0px; } @@ -376,7 +379,7 @@ #topright { position: absolute; - top: 0.7em; + top: 0.5em; right: 1em; margin-right: 0em; display: none; @@ -389,6 +392,19 @@ margin-right: 0em; } +.toprighttab { + position: relative; + top: 0.5em; + background-color: #260314; + border-color: #fff1d4; + border-style: solid; + border-width: 2px 2px 0px 2px; + border-radius: 6px 6px 0px 0px; + padding-top: 0.15em; + padding-bottom: 0.3em; + -moz-border-radius: 6px 6px 0px 0px; +} + #bottom { position: absolute; bottom: 0px; @@ -530,11 +546,43 @@ } #main-profile { + display: none; position: relative; left: 1em; top: 3em; + margin-bottom: 4em; + width: 100%; } +.separator-div { + width: 100%; + padding: 0px; + margin-left: -1em; + margin-top: 1em; + border-top: 1px solid #260314; + +} + +.positioning-div { + position: relative; + left: 0px; + right: 0px; + padding: 0px; + margin: 0px; +} + +.profile-right { + position: absolute; + top: -1.2em; + left: 26em; /* 50%; */ +} + +#invite { + display: none; + position: relative; + top: -1em; +} + .welcome-list { list-style: square; padding-left: 1.5em; @@ -544,9 +592,9 @@ margin-top: 0.5em; } -#users-list { +#add-opponents-list { list-style: none; - padding-left: 1.5em; + padding-left: 0em; margin-top: 0.5em; padding-bottom: 1em; } @@ -565,7 +613,7 @@ background-color: #400827; font-weight: bold; padding: 1em; - border: 1px solid #260314; + border: 1px solid #260314; z-index: 10; } Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/WebClient/index.html 2011-06-28 00:48:40 UTC (rev 1497) @@ -55,18 +55,28 @@ </form> </div> <span id="topright"> - Speed: <select id="speed"> - <option class="speed_val" value="1">1s</option> - <option class="speed_val" value="2">2s</option> - <option class="speed_val" value="3">3s</option> - <option class="speed_val" value="4">4s</option> - <option class="speed_val" value="5">5s</option> - <option class="speed_val" value="10">10s</option> - <option class="speed_val" value="15">15s</option> - <option class="speed_val" value="30">30s</option> - <option class="speed_val" value="60">60s</option> - </select> - <button id="logoutbt" onclick="logout()">Logout</button> + <span class="toprighttab"> + <a href="index.html">Games</a> + </span> + <span class="toprighttab"> + <a href="profile.html">Profile</a> + </span> + <span class="toprighttab"> + <button id="logoutbt" onclick="logout()">Logout</button> + </span> + <span class="toprighttab" id="speedtab" style="display: none;"> + Speed: <select id="speed"> + <option class="speed_val" value="1">1s</option> + <option class="speed_val" value="2">2s</option> + <option class="speed_val" value="3">3s</option> + <option class="speed_val" value="4">4s</option> + <option class="speed_val" value="5">5s</option> + <option class="speed_val" value="10">10s</option> + <option class="speed_val" value="15">15s</option> + <option class="speed_val" value="30">30s</option> + <option class="speed_val" value="60">60s</option> + </select> + </span> </span> <span id="topright-register"> <a href="register.html">Register</a> @@ -179,6 +189,7 @@ <div id="news"> <h3>News</h3> <ul id="welcome-list-news" class="welcome-list"> +<li><b>27/06/11</b> Tabs and searching opponents in the profile page</li> <li><b>22/06/11</b> Better organized lists of plays</li> <li><b>19/06/11</b> News section on the front page of tPlay</li> <li><b>15/06/11</b> Bug with underscores in user names corrected</li> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-06-25 14:13:14 UTC (rev 1496) +++ trunk/Toss/WebClient/profile.html 2011-06-28 00:48:40 UTC (rev 1497) @@ -46,7 +46,15 @@ </form> </div> <span id="topright"> - <button id="logoutbt" onclick="logout_profile()">Logout</button> + <span class="toprighttab"> + <a href="index.html">Games</a> + </span> + <span class="toprighttab"> + <a href="profile.html">Profile</a> + </span> + <span class="toprighttab"> + <button id="logoutbt" onclick="logout()">Logout</button> + </span> </span> <span id="topright-register"> <a href="register.html">Register</a> @@ -59,8 +67,9 @@ </p> </div> -<div id="main-profile" style="display: none;"> -<h2>Your Profile</h2> +<div id="main-profile"> +<div id="change-data"> +<h2>Change Your Data</h2> <div id="changeprofileform"> <p> <span class="reglabel">Name:</span> <input class="forminput" type="text" name="name" id="name" /> @@ -74,7 +83,9 @@ <p><button class="bt" id="changebt" type="button" onclick="change_profile()">Change</button></p> </div> +</div> +<div id="change-password" class="profile-right"> <h2>Change Password</h2> <div id="changepwdform"> <p> <span class="reglabel">New Password:</span> @@ -83,27 +94,51 @@ <p> <span class="reglabel">Repeat New Password:</span> <input class="forminput" type="password" name="rptnewpwd" id="rptnewpwd" /> </p> +<p> <input class="hiddenforminput" /> </p> <p><button class="bt" id="changepwdbt" type="button" onclick="change_password()">Change Password</button></p> </div> +</div> -<h2>Your Current Opponents</h2> +<div class="separator-div"></div> -<div id="opponents-profile"> - <ul id="opponents-list"><li style="display: none;"/></ul> -</div> +<div class="positioning-div"> + <div id="find-opponents"> + <h2>Find New Opponents</h2> + <div id="findopntform"> + <p> <span class="reglabel">Email or Name:</span> + <input class="forminput" type="text" name="findopnt" id="findopnt" /> + </p> + <p><button class="bt" id="findopntbt" type="button" + onclick="find_opnts()">Find Opponents</button> + </p> + </div> + <ul id="add-opponents-list"><li style="display: none;"/></ul> + <div id="invite"> + <p> <span class="reglabel">Your Friend not here?</span><br/> </p> + <p> + <button class="bt" id="invitebt" type="button" + onclick="invite()">Send Invitation</button> + </p> + </div> + </div> -<h2>Suggested New Opponents</h2> - -<div id="users-profile"> - <ul id="users-list"><li style="display: none;"/></ul> + <div id="current-opponents" class="profile-right"> + <h2>Your Current Opponents</h2> + <div id="opponents-profile"> + <ul id="opponents-list"><li style="display: none;"/></ul> + </div> + </div> </div> </div> <div id="bottom"> <a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> -<a href="contact.html" id="contact">Contact and Info</a> +<script type="text/javascript">begin_mailto( + "tossplay", "gmail.com", "Contact Us");</script> +tossplay [AT] gmail [DOT] com +<script type="text/javascript">end_mailto();</script> </div> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-25 14:13:21
|
Revision: 1496 http://toss.svn.sourceforge.net/toss/?rev=1496&view=rev Author: lukaszkaiser Date: 2011-06-25 14:13:14 +0000 (Sat, 25 Jun 2011) Log Message: ----------- Password changing in WebClient. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/profile.html Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-24 13:49:35 UTC (rev 1495) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-25 14:13:14 UTC (rev 1496) @@ -586,6 +586,11 @@ upd ("surname='" ^ udata.(1) ^ "'"); upd ("email='" ^ udata.(2) ^ "'"); "OK" in + let change_pwd uid pwd = + let uid_s = "id='" ^ uid ^ "'" in + let upd s = ignore (DB.update_table dbFILE ~select:uid_s s "users") in + upd ("passwd='" ^ pwd ^ "'"); + "OK" in let forgotpwd email = let mail_s = "email='" ^ email ^ "'" in let usrs = dbtable mail_s "users" in @@ -642,6 +647,9 @@ let (_, _, mail) = get_user_name_surname_mail data in mail, [] | "FORGOTPWD" -> forgotpwd data, [] + | "CHANGEPWD" -> + let uid = verif_uid () in + if uid = "" then "Please Log In again", [] else change_pwd uid data, [] | "CHANGEUSR" -> change_user_data (verif_uid ()) (split "$" data), [] | "LIST_PLAYS" -> Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-24 13:49:35 UTC (rev 1495) +++ trunk/Toss/WebClient/Connect.js 2011-06-25 14:13:14 UTC (rev 1496) @@ -139,6 +139,14 @@ return (srv ("REGISTER", data + "$" + cpwd)); } this.forgotpwd = function (mail) { return (srv("FORGOTPWD", mail)); } + this.change_pwd = function (un, pwd) { + var resp = srv("CHANGEPWD", pwd); + if (resp == "OK") { + this.logout (); + this.login (un, true, pwd); + return ("Password changed successfully"); + } else { return (resp); } + } this.change_data = function (name, surname, email) { return (srv ("CHANGEUSR", name +"$"+ surname +"$"+ email)); } Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-24 13:49:35 UTC (rev 1495) +++ trunk/Toss/WebClient/Login.js 2011-06-25 14:13:14 UTC (rev 1496) @@ -260,6 +260,22 @@ alert (resp); } +// Change user password +function change_password () { + var pwd = document.getElementById('newpwd').value; + var rptpwd = document.getElementById('rptnewpwd').value; + if (pwd.length < 3) { + alert ("Your password is too short." + CORRMSG); + return; + } + if (pwd != rptpwd) { + alert ("Password and Repeated Password do not match." + CORRMSG); + return; + } + var resp = CONN.change_pwd (UNAME, crypt(TSALT + pwd)); + alert (resp); +} + // Change user data function change_profile () { var name = document.getElementById('name').value; Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-24 13:49:35 UTC (rev 1495) +++ trunk/Toss/WebClient/Style.css 2011-06-25 14:13:14 UTC (rev 1496) @@ -532,6 +532,7 @@ #main-profile { position: relative; left: 1em; + top: 3em; } .welcome-list { Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-06-24 13:49:35 UTC (rev 1495) +++ trunk/Toss/WebClient/profile.html 2011-06-25 14:13:14 UTC (rev 1496) @@ -61,8 +61,7 @@ <div id="main-profile" style="display: none;"> <h2>Your Profile</h2> - -<form id="changeprofileform" action=""> +<div id="changeprofileform"> <p> <span class="reglabel">Name:</span> <input class="forminput" type="text" name="name" id="name" /> </p> @@ -74,8 +73,20 @@ </p> <p><button class="bt" id="changebt" type="button" onclick="change_profile()">Change</button></p> -</form> +</div> +<h2>Change Password</h2> +<div id="changepwdform"> +<p> <span class="reglabel">New Password:</span> + <input class="forminput" type="password" name="newpwd" id="newpwd" /> +</p> +<p> <span class="reglabel">Repeat New Password:</span> + <input class="forminput" type="password" name="rptnewpwd" id="rptnewpwd" /> +</p> +<p><button class="bt" id="changepwdbt" type="button" + onclick="change_password()">Change Password</button></p> +</div> + <h2>Your Current Opponents</h2> <div id="opponents-profile"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-24 13:49:42
|
Revision: 1495 http://toss.svn.sourceforge.net/toss/?rev=1495&view=rev Author: lukaszkaiser Date: 2011-06-24 13:49:35 +0000 (Fri, 24 Jun 2011) Log Message: ----------- Plays list and stability corrections. Modified Paths: -------------- trunk/Toss/Server/DB.ml trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/Server.ml trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/register.html Modified: trunk/Toss/Server/DB.ml =================================================================== --- trunk/Toss/Server/DB.ml 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/Server/DB.ml 2011-06-24 13:49:35 UTC (rev 1495) @@ -7,7 +7,9 @@ let tID = ref "toss_id_05174_" -let dbFILE = ref ((Unix.getenv "HOME") ^ "/.tossdb.sqlite") +let dbFILE = ref + ( try (Unix.getenv "HOME") ^ "/.tossdb.sqlite" + with _ -> "/tossdb.sqlite" ) let tGAMES = ref ["Breakthrough"; "Checkers"; "Chess"; "Connect4"; "Entanglement"; "Gomoku"; "Pawn-Whopping"; "Tic-Tac-Toe"; @@ -106,7 +108,7 @@ Printf.printf "DB busy or locked, retrying %i\n%!" retried; ignore (Unix.select [] [] [] 0.1); apply_cmd ~retried:(retried+1) dbfile select cmd - | x -> raise (DBError (Sqlite3.Rc.to_string x)) + | x -> raise (DBError ((Sqlite3.Rc.to_string x) ^ ":" ^ select_s)) let get_table dbfile ?(select="") tbl = fst (apply_cmd dbfile select ("select * from " ^ tbl)) Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-24 13:49:35 UTC (rev 1495) @@ -693,7 +693,7 @@ if line_in = "" || line_in = "\r" then try nonempty () with End_of_file -> "" else line_in in - nonempty () in + try nonempty () with Sys_error _ -> "" in let line_in_len = String.length line_in in if line_in_len = 0 then ("", None) else (* TODO: who needs escaping? *) Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/Server/Server.ml 2011-06-24 13:49:35 UTC (rev 1495) @@ -42,6 +42,7 @@ try ignore (Unix.waitpid [Unix.WNOHANG] (-1)); ignore (Unix.waitpid [Unix.WNOHANG] (-1)); + ignore (Unix.waitpid [Unix.WNOHANG] (-1)); with Unix.Unix_error (e,_,_) -> if !debug_level > 1 then Printf.printf "UNIX WAITPID: %s\n%!" (Unix.error_message e); Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/WebClient/Main.js 2011-06-24 13:49:35 UTC (rev 1495) @@ -64,7 +64,7 @@ function GamesPage(id, games){ // html tag id this.games = games; this.paragraphs = new Object(); - this.container = document.getElementById(id); + this.container = document.getElementById (id); for (var i = 0; i < this.games.length; i++) { var game = this.games[i]; @@ -74,35 +74,42 @@ var button = document.createElement("button"); paragraph.game_button = button; - button.setAttribute("class", "boldobt"); + button.setAttribute("class", "gamebt"); button.setAttribute("onclick", "new_play('" + game + "')"); button.innerHTML = game; button.style.display = "block"; - this.container.appendChild(paragraph); - paragraph.appendChild(button); + this.container.appendChild (paragraph); + paragraph.appendChild (button); var open_play_list = document.createElement("ul"); paragraph.open_play_list = open_play_list; open_play_list.setAttribute("class", "plays-list"); open_play_list.setAttribute("id", "a-plays-list-" + game); - paragraph.appendChild(open_play_list); + paragraph.appendChild (open_play_list); + var closed_plays = document.createElement("div"); + paragraph.closed_plays = closed_plays; + closed_plays.setAttribute("id", "d-plays-div-" + game); + var completed_bt = document.createElement("button"); paragraph.completed_button = completed_bt; completed_bt.setAttribute("class", "completedbt"); completed_bt.setAttribute("onclick", - "GAMESPAGE.toggle_completed('" + game + "')"); + "GAMESPAGE.toggle_completed ('" + game + "')"); completed_bt.innerHTML = "Completed games (Show)"; - this.container.appendChild(paragraph); - paragraph.appendChild(completed_bt); - paragraph.completed_shown = false; + closed_plays.appendChild (completed_bt); var closed_play_list = document.createElement("ul"); paragraph.closed_play_list = closed_play_list; closed_play_list.setAttribute("class", "plays-list"); closed_play_list.setAttribute("id", "d-plays-list-" + game); closed_play_list.style.display = "none"; - paragraph.appendChild(closed_play_list); + closed_plays.appendChild (closed_play_list); + + closed_plays.style.display = "none"; + paragraph.appendChild (closed_plays); + paragraph.completed_shown = false; + this.container.appendChild (paragraph); } return (this); } @@ -116,11 +123,11 @@ } GamesPage.prototype.show_completed = function (game) { - this.paragraphs[game].closed_play_list.style.display = "block"; + this.paragraphs[game].closed_plays.style.display = "block"; } GamesPage.prototype.hide_completed = function (game) { - this.paragraphs[game].closed_play_list.style.display = "none"; + this.paragraphs[game].closed_plays.style.display = "none"; } GamesPage.prototype.toggle_completed = function (game) { @@ -163,27 +170,23 @@ function list_plays_string (game, lst) { PLAYS = parse_list ('##', lst); - var a_plist = document.getElementById("a-plays-list-" + game); - var d_plist = document.getElementById("d-plays-list-" + game); + var a_plist = document.getElementById ("a-plays-list-" + game); + var d_plist = document.getElementById ("d-plays-list-" + game); while (a_plist.childNodes.length > 0) { - a_plist.removeChild(a_plist.firstChild); + a_plist.removeChild (a_plist.firstChild); } while (d_plist.childNodes.length > 0) { - d_plist.removeChild(d_plist.firstChild); + d_plist.removeChild (d_plist.firstChild); } for (var i = 0; i < PLAYS.length; i++) { PLAYS[i] = play_from_string (game, PLAYS[i]); if (PLAYS[i].cur_state.payoff == "") { - a_plist.appendChild(new_play_item (game, i)); + a_plist.appendChild (new_play_item (game, i)); } else { - d_plist.appendChild(new_play_item (game, i)); + d_plist.appendChild (new_play_item (game, i)); } } - if (PLAYS.length == 0) { - document.getElementById("a-plays-list-" + game).style.display = "none"; - } else { - document.getElementById("a-plays-list-" + game).style.display = "block"; - } + if (d_plist.childNodes.length > 0) { GAMESPAGE.show_completed (game); } } function list_plays (game) { @@ -193,19 +196,19 @@ function play_click (game, play_id, pi) { - document.getElementById("opponents").style.display = "none"; + document.getElementById ("opponents").style.display = "none"; list_plays (game); - document.getElementById("welcome").style.display = "none"; - document.getElementById("game-disp").style.display = "none"; - document.getElementById("plays").style.display = "none"; + document.getElementById ("welcome").style.display = "none"; + document.getElementById ("game-disp").style.display = "none"; + document.getElementById ("plays").style.display = "none"; GAME_NAME = game; - var gd = document.getElementById("game-disp"); + var gd = document.getElementById ("game-disp"); gd.style.display = "block"; gd.setAttribute ("class", "Game-" + game); document.getElementById ("game-title").innerHTML = game; - document.getElementById("game-disp").style.display = "block"; - document.getElementById("play-number").innerHTML = "" + play_id; - document.getElementById("suggestions-toggle").style.display = "inline"; + document.getElementById ("game-disp").style.display = "block"; + document.getElementById ("play-number").innerHTML = "" + play_id; + document.getElementById ("suggestions-toggle").style.display = "inline"; CUR_PLAY_I = pi; PLAYS[CUR_PLAY_I].redraw (); } @@ -232,12 +235,12 @@ } function make_opnt_list () { - var o = document.getElementById("opponents-list"); + var o = document.getElementById ("opponents-list"); FULL_OPNT_LEN = FRIENDS.length + 1; CUR_OPNT_START = 0; - document.getElementById("opponents-prev").style.display = "none"; + document.getElementById ("opponents-prev").style.display = "none"; if (MAX_OPNT_LEN > FULL_OPNT_LEN) { - document.getElementById("opponents-next").style.display = "none" + document.getElementById ("opponents-next").style.display = "none" } var zeroli = document.createElement('li'); zeroli.setAttribute ("class", "opponents-list-elem"); @@ -250,55 +253,55 @@ if (i > MAX_OPNT_LEN - 2) { oi.style.display = "none"; } o.appendChild (oi); } - document.getElementById("opponents").style.display = "block"; + document.getElementById ("opponents").style.display = "block"; } function new_play (game) { if (UNAME == "") { alert ("Please log in to create plays"); return; } GAME_NAME = game; - var olist = document.getElementById("opponents-list"); - while (olist.childNodes.length > 0) { olist.removeChild(olist.firstChild); } + var olist = document.getElementById ("opponents-list"); + while (olist.childNodes.length > 0) { olist.removeChild (olist.firstChild); } make_opnt_list (); } function opponents_next () { for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { - document.getElementById("opponent-" + "-" + i).style.display = "none"; + document.getElementById ("opponent-" + "-" + i).style.display = "none"; } CUR_OPNT_START += MAX_OPNT_LEN; for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { if (i < FULL_OPNT_LEN) { - document.getElementById("opponent-" + "-" + i).style.display = "list-item"; + document.getElementById ("opponent-" + "-" + i).style.display = "list-item"; } } - document.getElementById("opponents-prev").style.display = "block" + document.getElementById ("opponents-prev").style.display = "block" if (CUR_OPNT_START + MAX_OPNT_LEN > FULL_OPNT_LEN) { - document.getElementById("opponents-next").style.display = "none" + document.getElementById ("opponents-next").style.display = "none" } } function opponents_prev () { for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { if (i < FULL_OPNT_LEN) { - document.getElementById("opponent-" + "-" + i).style.display = "none"; + document.getElementById ("opponent-" + "-" + i).style.display = "none"; } } CUR_OPNT_START -= MAX_OPNT_LEN; for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { - document.getElementById("opponent-" + "-" + i).style.display = "list-item"; + document.getElementById ("opponent-" + "-" + i).style.display = "list-item"; } - document.getElementById("opponents-next").style.display = "block" + document.getElementById ("opponents-next").style.display = "block" if (CUR_OPNT_START == 0) { - document.getElementById("opponents-prev").style.display = "none" + document.getElementById ("opponents-prev").style.display = "none" } } function show_chess_warning () { - document.getElementById("chess-level-warning").style.display = "block"; + document.getElementById ("chess-level-warning").style.display = "block"; } function hide_chess_warning () { - document.getElementById("chess-level-warning").style.display = "none"; + document.getElementById ("chess-level-warning").style.display = "none"; } function new_play_guest (game) { @@ -309,17 +312,17 @@ if (game == "Pawn-Whopping") { wgame = "Pawn_(chess)" }; if (game == "Entanglement") { wgame = "Entanglement_(graph_measure)" }; wiki = "http://en.wikipedia.org/wiki/" + wgame; - document.getElementById("topuser").innerHTML = + document.getElementById ("topuser").innerHTML = game + ' (<a href="' + wiki + '">Move Rules</a>)'; - if (SIMPLE_SET) { document.getElementById("topuser").innerHTML = game }; - document.getElementById("pdescBack").style.display = "inline"; - document.getElementById("game-title").style.display = "none"; - document.getElementById("game-info-par").style.paddingBottom = "1em"; - document.getElementById("loginform").style.display = "none"; - document.getElementById("topright-register").style.display = "none"; - document.getElementById("topright").style.display = "inline"; - document.getElementById("logoutbt").style.display = "none"; - document.getElementById("welcome").style.display = "none"; + if (SIMPLE_SET) { document.getElementById ("topuser").innerHTML = game }; + document.getElementById ("pdescBack").style.display = "inline"; + document.getElementById ("game-title").style.display = "none"; + document.getElementById ("game-info-par").style.paddingBottom = "1em"; + document.getElementById ("loginform").style.display = "none"; + document.getElementById ("topright-register").style.display = "none"; + document.getElementById ("topright").style.display = "inline"; + document.getElementById ("logoutbt").style.display = "none"; + document.getElementById ("welcome").style.display = "none"; if (game == "Chess") { show_chess_warning (); setTimeout("hide_chess_warning ()", 3000); @@ -329,35 +332,35 @@ function new_play_do (opp_uid) { list_plays (GAME_NAME); - document.getElementById("welcome").style.display = "none"; - document.getElementById("game-disp").style.display = "none"; - document.getElementById("plays").style.display = "none"; - var gd = document.getElementById("game-disp"); + document.getElementById ("welcome").style.display = "none"; + document.getElementById ("game-disp").style.display = "none"; + document.getElementById ("plays").style.display = "none"; + var gd = document.getElementById ("game-disp"); gd.style.display = "block"; gd.setAttribute ("class", "Game-" + GAME_NAME); document.getElementById ("game-title").innerHTML = GAME_NAME; - document.getElementById("opponents").style.display = "none"; - var olist = document.getElementById("opponents-list"); - while (olist.childNodes.length > 0) { olist.removeChild(olist.firstChild); } + document.getElementById ("opponents").style.display = "none"; + var olist = document.getElementById ("opponents-list"); + while (olist.childNodes.length > 0) { olist.removeChild (olist.firstChild); } if (opp_uid == -1) { opp_uid = UNAME; } if (opp_uid == 0 || UNAME == "") { return; } - //document.getElementById("plays-list-" + GAME_NAME).style.display = "block"; - document.getElementById("working").style.display = "block"; + //document.getElementById ("plays-list-" + GAME_NAME).style.display = "block"; + document.getElementById ("working").style.display = "block"; info_nbr = CONN.new_play (GAME_NAME, UNAME, opp_uid); - document.getElementById("working").style.display = "none"; - document.getElementById("suggestions-toggle").style.display = "inline"; + document.getElementById ("working").style.display = "none"; + document.getElementById ("suggestions-toggle").style.display = "inline"; info_idx = info_nbr.indexOf('$'); FREE_PLAY_NO = parseInt(info_nbr.substring(0, info_idx)); - document.getElementById("play-number").innerHTML = "" + FREE_PLAY_NO; + document.getElementById ("play-number").innerHTML = "" + FREE_PLAY_NO; CUR_PLAY_I = PLAYS.length; - document.getElementById("game-disp").style.display = "block"; - document.getElementById("plays").style.left = "30em"; + document.getElementById ("game-disp").style.display = "block"; + document.getElementById ("plays").style.left = "30em"; var p = new Play (GAME_NAME, [0,1], [UNAME, opp_uid], FREE_PLAY_NO, 0, info_nbr.substring(info_idx+1), UNAME); PLAYS.push(p); p.redraw (); //li = new_play_item (GAME_NAME, CUR_PLAY_I); - //document.getElementById("plays-list-" + GAME_NAME).appendChild(li); + //document.getElementById ("plays-list-" + GAME_NAME).appendChild (li); } function get_opponents () { @@ -366,16 +369,16 @@ } function play_anew (me_starts) { - document.getElementById('payoffs').innerHTML = "Not Finished Yet"; - document.getElementById('payoffs').style.display = "none"; - document.getElementById('new-play-par').style.display = "none"; + document.getElementById ('payoffs').innerHTML = "Not Finished Yet"; + document.getElementById ('payoffs').style.display = "none"; + document.getElementById ('new-play-par').style.display = "none"; if (UNAME == "guest") { - document.getElementById("game-info-par").style.paddingBottom = "1em"; + document.getElementById ("game-info-par").style.paddingBottom = "1em"; }; toggle_suggestions (); toggle_suggestions (); PLAYS[CUR_PLAY_I].clear (); - document.getElementById('cur-move').innerHTML = "none"; + document.getElementById ('cur-move').innerHTML = "none"; if (me_starts) { var opp = PLAYS[CUR_PLAY_I].players[1]; if (PLAYS[CUR_PLAY_I].players[0] != UNAME) { @@ -393,14 +396,14 @@ UNAME = me; PLAYS[CUR_PLAY_I].cur_player_uid = UNAME; if (opp == "computer") { - var mv_time = document.getElementById("speed").value; + var mv_time = document.getElementById ("speed").value; suggest_move_async (mv_time, make_move); } } } function decrease_moving (n) { - document.getElementById("working").innerHTML = "Moving in " + n + "s ..."; + document.getElementById ("working").innerHTML = "Moving in " + n + "s ..."; if (n > 0) { setTimeout("decrease_moving(" + (n-1) + ")", 1000); } @@ -408,8 +411,8 @@ function show_moving_msg (n) { if (n > 1) { - document.getElementById("working").innerHTML = "Moving in "+ n+ "s ..."; - document.getElementById("working").style.display = "block"; + document.getElementById ("working").innerHTML = "Moving in "+ n+ "s ..."; + document.getElementById ("working").style.display = "block"; setTimeout("decrease_moving(" + (n-1) + ")", 1000); } } @@ -417,8 +420,8 @@ function suggest_move_async (time, f) { show_moving_msg (time); var fm = function (m) { - document.getElementById("working").style.display = "none"; - document.getElementById("working").innerHTML = "Working..."; + document.getElementById ("working").style.display = "none"; + document.getElementById ("working").innerHTML = "Working..."; if (m != "") { PLAYS[CUR_PLAY_I].show_move (new Move (m)); f() } }; CONN.suggest (PLAYS[CUR_PLAY_I].cur_state.players[0]+1, time, @@ -426,26 +429,26 @@ } function suggest_move_click () { - var mv_time = document.getElementById("speed").value; + var mv_time = document.getElementById ("speed").value; suggest_move_async (mv_time, function () {}); } function toggle_suggestions () { - var txt = document.getElementById("suggestions-toggle").innerHTML; + var txt = document.getElementById ("suggestions-toggle").innerHTML; if (txt.indexOf ("Before") == -1) { SIMPLE_MOVES = true; - document.getElementById("play-nbr-info").style.display = "none"; - document.getElementById("board").style.paddingTop = "1em"; - document.getElementById("suggestions-toggle").innerHTML = + document.getElementById ("play-nbr-info").style.display = "none"; + document.getElementById ("board").style.paddingTop = "1em"; + document.getElementById ("suggestions-toggle").innerHTML = "Ask Before Move"; - document.getElementById("move-info-par").style.display = "none"; + document.getElementById ("move-info-par").style.display = "none"; } else { SIMPLE_MOVES = false; - document.getElementById("play-nbr-info").style.display = "inline"; - document.getElementById("board").style.paddingTop = "0em"; - document.getElementById("suggestions-toggle").innerHTML = + document.getElementById ("play-nbr-info").style.display = "inline"; + document.getElementById ("board").style.paddingTop = "0em"; + document.getElementById ("suggestions-toggle").innerHTML = "Move Without Asking"; - document.getElementById("move-info-par").style.display = "block"; + document.getElementById ("move-info-par").style.display = "block"; } } Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/WebClient/Style.css 2011-06-24 13:49:35 UTC (rev 1495) @@ -64,7 +64,7 @@ float: right; } -.obt, .boldobt { +.obt, .boldobt, .gamebt { text-align: left; border-color: #260314; border-radius: 4px; @@ -81,17 +81,25 @@ text-decoration: underline; } -.boldobt { +.boldobt, .gamebt { font-weight: bold; font-size: 1em; } -.boldobt:hover { +.boldobt:hover, .gamebt:hover { cursor: pointer; text-decoration: underline; } +.gamebt { + margin-bottom: 1em; + +} + .completedbt { + position: relative; + top: -1em; + left: 1em; text-align: left; border-color: #260314; border-radius: 4px; @@ -730,15 +738,17 @@ } .plays-list { - margin-left: 1em; - padding-left: 0px; list-style: none; margin: 0.5em; + margin-bottom: 0px; + margin-left: 0px; + padding-left: 0px; + padding-bottom: 1em; border-bottom: 1px solid #260314; } .plays-list-elem { - margin-left: 0em; + margin-left: 1em; margin-bottom: 0em; } Modified: trunk/Toss/WebClient/register.html =================================================================== --- trunk/Toss/WebClient/register.html 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/WebClient/register.html 2011-06-24 13:49:35 UTC (rev 1495) @@ -24,7 +24,7 @@ <h2>Register on tPlay</h2> -<form id="registerform" action=""> +<div id="registerform"> <p> <span class="reglabel">Email:</span> <input class="forminput" type="text" name="email" id="email" onchange="register_email_change()" /> @@ -50,7 +50,7 @@ <p> <span class="reglabel">Surname:</span> <input class="forminput" type="text" name="surname" id="surname" /> </p> -</form> +</div> <p> </p> <p> <span class="reglabel">Forgot your password?</span> <button class="bt" id="forgotbt" type="button" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-22 22:37:44
|
Revision: 1494 http://toss.svn.sourceforge.net/toss/?rev=1494&view=rev Author: lukaszkaiser Date: 2011-06-22 22:37:37 +0000 (Wed, 22 Jun 2011) Log Message: ----------- Lists of plays in JavaScript. Modified Paths: -------------- trunk/Toss/Toss.py trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Modified: trunk/Toss/Toss.py =================================================================== --- trunk/Toss/Toss.py 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/Toss.py 2011-06-22 22:37:37 UTC (rev 1494) @@ -35,7 +35,7 @@ app_win.show() sys.exit(app.exec_()) else: - args = [toss_dir + "/TossServer", "-s", host, "-p", str(port), "-d", log_level] + args = [toss_dir + "/TossServer", "-nocache", "-s", host, "-p", str(port), "-d", log_level] # gather exception backtrace information os.environ['OCAMLRUNPARAM'] = 'b' server_proc = subprocess.Popen(args) Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/Login.js 2011-06-22 22:37:37 UTC (rev 1494) @@ -30,7 +30,7 @@ list_plays_string ("Gomoku", udata[7]); list_plays_string ("Pawn-Whopping", udata[8]); list_plays_string ("Tic-Tac-Toe", udata[9]); - list_plays_string ("Concurrent-Tic-Tac-Toe", udata[10]); + /* list_plays_string ("Concurrent-Tic-Tac-Toe", udata[10]); */ get_opponents (); } @@ -48,6 +48,7 @@ // Onload handler function startup (game) { + GAMESPAGE = new GamesPage ("plays", GAMES); if (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('MSIE 9') == -1) { document.getElementById("nosvg").style.display = "block"; Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/Main.js 2011-06-22 22:37:37 UTC (rev 1494) @@ -45,6 +45,98 @@ PLAYS[CUR_PLAY_I].next_move (); } + +var GAMES = new Array( + /* "Concurrent-Tic-Tac-Toe" */ + "Breakthrough", + "Checkers", + "Chess", + "Connect4", + "Entanglement", + "Gomoku", + "Pawn-Whopping", + "Tic-Tac-Toe" +); + +var GAMESPAGE = undefined; + + +function GamesPage(id, games){ // html tag id + this.games = games; + this.paragraphs = new Object(); + this.container = document.getElementById(id); + for (var i = 0; i < this.games.length; i++) { + var game = this.games[i]; + + var paragraph = document.createElement("p"); + this.paragraphs[game] = paragraph; + paragraph.setAttribute("class", "game-par"); + + var button = document.createElement("button"); + paragraph.game_button = button; + button.setAttribute("class", "boldobt"); + button.setAttribute("onclick", "new_play('" + game + "')"); + button.innerHTML = game; + button.style.display = "block"; + this.container.appendChild(paragraph); + paragraph.appendChild(button); + + var open_play_list = document.createElement("ul"); + paragraph.open_play_list = open_play_list; + open_play_list.setAttribute("class", "plays-list"); + open_play_list.setAttribute("id", "a-plays-list-" + game); + paragraph.appendChild(open_play_list); + + var completed_bt = document.createElement("button"); + paragraph.completed_button = completed_bt; + completed_bt.setAttribute("class", "completedbt"); + completed_bt.setAttribute("onclick", + "GAMESPAGE.toggle_completed('" + game + "')"); + completed_bt.innerHTML = "Completed games (Show)"; + this.container.appendChild(paragraph); + paragraph.appendChild(completed_bt); + paragraph.completed_shown = false; + + var closed_play_list = document.createElement("ul"); + paragraph.closed_play_list = closed_play_list; + closed_play_list.setAttribute("class", "plays-list"); + closed_play_list.setAttribute("id", "d-plays-list-" + game); + closed_play_list.style.display = "none"; + paragraph.appendChild(closed_play_list); + } + return (this); +} + +GamesPage.prototype.show = function () { + this.container.style.display = "block"; +} + +GamesPage.prototype.hide = function () { + this.container.style.display = "none"; +} + +GamesPage.prototype.show_completed = function (game) { + this.paragraphs[game].closed_play_list.style.display = "block"; +} + +GamesPage.prototype.hide_completed = function (game) { + this.paragraphs[game].closed_play_list.style.display = "none"; +} + +GamesPage.prototype.toggle_completed = function (game) { + var par = this.paragraphs[game]; + if (par.completed_shown) { + par.closed_play_list.style.display = "none"; + par.completed_button.innerHTML = "Completed games (Show)"; + par.completed_shown = false; + } else { + par.closed_play_list.style.display = "block"; + par.completed_button.innerHTML = "Completed games (Hide)"; + par.completed_shown = true; + } +} + + function play_from_string (game, s) { var p = s.substring(game.length + 1); var lst = parse_list ('#', p); @@ -73,14 +165,18 @@ PLAYS = parse_list ('##', lst); var a_plist = document.getElementById("a-plays-list-" + game); var d_plist = document.getElementById("d-plays-list-" + game); - while (a_plist.childNodes.length > 0) { a_plist.removeChild(a_plist.firstChild); } - while (d_plist.childNodes.length > 0) { d_plist.removeChild(d_plist.firstChild); } + while (a_plist.childNodes.length > 0) { + a_plist.removeChild(a_plist.firstChild); + } + while (d_plist.childNodes.length > 0) { + d_plist.removeChild(d_plist.firstChild); + } for (var i = 0; i < PLAYS.length; i++) { PLAYS[i] = play_from_string (game, PLAYS[i]); - if (PLAYS[i].cur_state.payoff == "") a_plist.appendChild(new_play_item (game, i)); - else - { - d_plist.appendChild(new_play_item (game, i)); + if (PLAYS[i].cur_state.payoff == "") { + a_plist.appendChild(new_play_item (game, i)); + } else { + d_plist.appendChild(new_play_item (game, i)); } } if (PLAYS.length == 0) { Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/Style.css 2011-06-22 22:37:37 UTC (rev 1494) @@ -91,6 +91,23 @@ text-decoration: underline; } +.completedbt { + text-align: left; + border-color: #260314; + border-radius: 4px; + -moz-border-radius: 4px; + border-width: 0px; + color: #260314; + background-color: #fff1d4; + font-size: 0.8em; + font-family: Verdana, 'TeXGyreHerosRegular', sans; +} + +.completedbt:hover { + cursor: pointer; + text-decoration: underline; +} + .dbt { border-color: #fff1d4; border-radius: 4px; @@ -716,8 +733,8 @@ margin-left: 1em; padding-left: 0px; list-style: none; - margin-top: 0em; - border-top: 1px solid #260314; + margin: 0.5em; + border-bottom: 1px solid #260314; } .plays-list-elem { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/index.html 2011-06-22 22:37:37 UTC (rev 1494) @@ -179,6 +179,7 @@ <div id="news"> <h3>News</h3> <ul id="welcome-list-news" class="welcome-list"> +<li><b>22/06/11</b> Better organized lists of plays</li> <li><b>19/06/11</b> News section on the front page of tPlay</li> <li><b>15/06/11</b> Bug with underscores in user names corrected</li> <li><b>10/06/11</b> New register site handles forgotten passwords</li> @@ -211,96 +212,6 @@ </div> <div id="plays"> - <p class="game-par"> - <button onclick="new_play('Breakthrough')" - class="boldobt">Breakthrough</button> - </p> - <ul class="plays-list" id="a-plays-list-Breakthrough"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Breakthrough"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Checkers')" - class="boldobt">Checkers</button> - </p> - <ul class="plays-list" id="a-plays-list-Checkers"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Checkers"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Chess')" - class="boldobt">Chess</button> - </p> - <ul class="plays-list" id="a-plays-list-Chess"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Chess"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Connect4')" - class="boldobt">Connect4</button> - </p> - <ul class="plays-list" id="a-plays-list-Connect4"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Connect4"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Entanglement')" - class="boldobt">Entanglement</button> - </p> - <ul class="plays-list" id="a-plays-list-Entanglement"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Entanglement"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Gomoku')" - class="boldobt">Gomoku</button> - </p> - <ul class="plays-list" id="a-plays-list-Gomoku"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Gomoku"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Pawn-Whopping')" - class="boldobt">Pawn-Whopping</button> - </p> - <ul class="plays-list" id="a-plays-list-Pawn-Whopping"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Pawn-Whopping"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Tic-Tac-Toe')" - class="boldobt">Tic-Tac-Toe</button> - </p> - <ul class="plays-list" id="a-plays-list-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Concurrent-Tic-Tac-Toe')" - class="boldobt">Concurrent-Tic-Tac-Toe</button> - </p> - <ul class="plays-list" id="a-plays-list-Concurrent-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Concurrent-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-22 07:34:09
|
Revision: 1493 http://toss.svn.sourceforge.net/toss/?rev=1493&view=rev Author: chalmi Date: 2011-06-22 07:34:03 +0000 (Wed, 22 Jun 2011) Log Message: ----------- GamesPage draft - do not use Modified Paths: -------------- trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/msw.html trunk/Toss/WebClient/msw.js Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-21 14:48:59 UTC (rev 1492) +++ trunk/Toss/WebClient/Main.js 2011-06-22 07:34:03 UTC (rev 1493) @@ -367,11 +367,11 @@ this.play_lists = new Object(); for (var i=2; i < udata.length; i++){ var plays = parse_list("##", udata[i]); - for (var j=0; j<plays.length; j++){ + for (var j=0; j < plays.length; j++){ var play = msw_play_from_string(plays[j]); var key = play.game; - if (this.play_lists[key] == undefined) this.play_lists[key] = new Array(); - this.play_lists[key].push(play); + if (this.play_lists[key] == undefined) this.play_lists[key] = new Object(); + this.play_lists[key][play.pid] = play; } } } Modified: trunk/Toss/WebClient/msw.html =================================================================== --- trunk/Toss/WebClient/msw.html 2011-06-21 14:48:59 UTC (rev 1492) +++ trunk/Toss/WebClient/msw.html 2011-06-22 07:34:03 UTC (rev 1493) @@ -35,6 +35,9 @@ </select> <button id="logoutbt" onclick="logout()">Logout</button> </span> + +<div id="plays"></div> + <div id="game-disp"> <p id="game-info-par"> <span id="game-title"></span> @@ -64,16 +67,6 @@ </div> </div> -<script type="text/javascript"> - UNAME = "michal"; - CUR_PLAY_I = 0; - GAME_NAME = "Chess"; - msw_plays(GAME_NAME); - var info = CONN.open_db(PLAYS[CUR_PLAY_I][2]); - document.getElementById("game-disp").style.display = "block"; - document.getElementById("game-disp").setAttribute ("class", "Game-" + GAME_NAME); - full_redraw(GAME_NAME, info); - //document.write(info); -</script> + </body> </html> Modified: trunk/Toss/WebClient/msw.js =================================================================== --- trunk/Toss/WebClient/msw.js 2011-06-21 14:48:59 UTC (rev 1492) +++ trunk/Toss/WebClient/msw.js 2011-06-22 07:34:03 UTC (rev 1493) @@ -1,171 +1,46 @@ -function msw_list_plays_string (game, lst) { - PLAYS = parse_list ('#', lst); - //var plist = document.getElementById("plays-list-" + game); - //while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } - var d = game.length + 2; - for (var i = 0; i < PLAYS.length; i++) { - var p = PLAYS[i].substring(PLAYS[i].lastIndexOf('/') + d); - PLAYS[i] = parse_list ('_', p); - //plist.appendChild(new_play_item (game, i)); - } - /*if (PLAYS.length == 0) { - document.getElementById("plays-list-" + game).style.display = "none"; - } else { - document.getElementById("plays-list-" + game).style.display = "block"; - }*/ -} +GAMES = new Array( + "Breakthrough", + "Checkers", + "Chess", + "Connect4", + "Entanglement", + "Gomoku", + "Pawn-Whopping", + "Tic-Tac-Toe", + "Concurrent-Tic-Tac-Toe" + ); -function msw_plays (game) { - var lst = CONN.list_plays (game, UNAME); - msw_list_plays_string (game, lst); +function GamesPage(id, games){// html tag id + this.games = games; + this.paragraphs = new Object(); + this.container = document.getElementById(id); + for (var i = 0; i < this.games.length; i++){ + var game = this.games[i]; + var paragraph = this.paragraphs[game] = document.createElement("p"); + paragraph.setAttribute("class", "game-par"); + var button = paragraph.button = document.createElement("button"); + button.setAttribute("class", "boldobt"); + button.setAttribute("onclick", "new_play('" + game + "')"); + button.innerHTML = game; + this.container.appendChild(paragraph); + paragraph.appendChild(button); + + var open_play_list = paragraph.open_play_list = document.createElement("ul"); + open_play_list.setAttribute("class", "play-list"); + open_play_list.setAttribute("id", "a-plays-list-" + game); + paragraph.appendChild(open_play_list); + + var closed_play_list = paragraph.closed_play_list = document.createElement("ul"); + closed_play_list.setAttribute("class", "play-list"); + closed_play_list.setAttribute("id", "d-plays-list-" + game); + paragraph.appendChild(closed_play_list); + } } -function msw_make_move_continue (info) { - document.getElementById("working").style.display = "none"; - full_redraw (GAME_NAME, info); - //var old_li = document.getElementById ("plays-list-" + GAME_NAME + - // "-elem-" + CUR_PLAY_I); - //var li = new_play_item (GAME_NAME, CUR_PLAY_I); - //old_li.parentNode.replaceChild (li, old_li); - if (ST.players.length==1 && PLAYS[CUR_PLAY_I][ST.players[0]]=="computer") { - var mv_time = document.getElementById("speed").value; - suggest_move_async (mv_time, msw_make_move); - } +GamesPage.prototype.show = function(){ + this.container.style.display = "block"; } -function msw_state_draw_model (game) { - var draw_background = function (game) { - var x = SVG_MARGINX; - var y = SVG_MARGINY; - var w = SVG_WIDTH + 2 * x; - var h = SVG_HEIGHT + 2 * x; - var bg = SHAPES.background_svg (game, 0, 0, w, h, []); - if (bg != undefined) {document.getElementById("svg").appendChild(bg);} - } - - // Draw the element [elem]. - var draw_elem = function (game, elem) { - if (game != "Connect4") { - var r = SHAPES.rect ( - elem.x, elem.y, 2 * SHAPES.elem_size_x, 2 * SHAPES.elem_size_y, - [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], - ["onclick", ("msw_handle_elem_click('" + elem.id + "')")]]); - document.getElementById("svg").appendChild(r); - } else { - var circ = SHAPES.circle ( - elem.x, elem.y, 30, - [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], - ["onclick", "msw_handle_elem_click('" + elem.id + "')"]]); - document.getElementById("svg").appendChild(circ); - } - } - - - // Draw relation [rel_name] between elements [args]. - function draw_rel (game, rel) { - if (rel.args.length == 1) { - var ihatrs = [["id", "pred_" + rel.args[0].id + "_" + rel.name], - ["onclick","msw_handle_elem_click('"+rel.args[0].id+"')"]] - var pos = [rel.args[0].x, rel.args[0].y]; - var f = SHAPES.rel_svg (game, pos[0],pos[1],20,20, rel.name,ihatrs); - if (f != undefined) { - document.getElementById("svg").appendChild(f); - } else { - var circ = SHAPES.circle ( - pos[0], pos[1], SHAPES.elem_size_x - 10, - [["id", "pred_" + rel.args[0].id + "_" + rel.name], - ["class", "model-pred-" + rel.name], - ["stroke-width", (SHAPES.elem_size_x / 10) + 2], - ["onclick", ("msw_handle_elem_click('"+rel.args[0].id+"')")]]); - document.getElementById("svg").appendChild(circ); - } - } - if (rel.args.length == 2) { - if (rel.name == "E") { - var l = SHAPES.line (rel.args[0].x, rel.args[0].y, - rel.args[1].x, rel.args[1].y, - [["class", "model-edge-E"]]); - document.getElementById("svg").appendChild(l); - } - } - } - - // Main draw_model function. - var sqrt = Math.round (Math.sqrt (this.elems.length)); - if (sqrt * sqrt == this.elems.length) { // perhaps a grid - SHAPES.elem_size_x = SVG_WIDTH / (2.0 * (sqrt-1)); - SHAPES.elem_size_y = SVG_HEIGHT / (2.0 * (sqrt-1)); - } else { - SHAPES.elem_size_x = SVG_WIDTH / 20; - SHAPES.elem_size_y = SVG_HEIGHT / 20; - } - draw_background (game); - for (var i = 0; i < this.elems.length; i++) { - draw_elem (game, this.elems[i]); - } - for (var i = 0; i < this.rels.length; i++) { - draw_rel (game, this.rels[i]); - } +GamesPage.prototype.hide = function(){ + this.container.style.display = "none"; } -State.prototype.draw_model = msw_state_draw_model; - -function msw_handle_elem_click (elem) { - if (ASYNC_ALL_REQ_PENDING != 0) { return; } - var moves = ST.get_moves (elem, LAST_CLICKED_ELEM); - if (moves.length == 0) { - LAST_CLICKED_ELEM = ""; - moves = ST.get_moves (elem, LAST_CLICKED_ELEM); - }; - if (moves.length == 0) { // still no moves, unhighlight - for (var i = 0; i < CUR_ELEMS.length; i++) { - ST.unhighlight_elem (CUR_ELEMS[i]); - } - CUR_ELEMS = []; - CUR_MOVE = ""; - LAST_CLICKED_ELEM = ""; - } else if (moves.length == 1) { - show_move (moves[0]); - ELEM_COUNTERS[elem] = 1; - if (SIMPLE_MOVES) { msw_make_move (); }; - } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast - && moves.length == 2 && moves[0].length > moves[1].length) { - show_move (moves[1]); - ELEM_COUNTERS[elem] = 2; - if (SIMPLE_MOVES) { msw_make_move (); }; - } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast - && moves.length == 2 && moves[1].length > moves[0].length) { - show_move (moves[0]); - ELEM_COUNTERS[elem] = 1; - if (SIMPLE_MOVES) { msw_make_move (); }; - } else if (moves.length > ELEM_COUNTERS[elem]) { - show_move (moves[ELEM_COUNTERS[elem]]); - ELEM_COUNTERS[elem] += 1; - } else if (moves.length > 0) { - show_move (moves[0]); - ELEM_COUNTERS[elem] = 1; - }; - if (moves.length > 1 && LAST_CLICKED_ELEM == "") { - for (var i = 0; i < CUR_ELEMS.length; i++) { - ST.unhighlight_elem (CUR_ELEMS[i]); - } - document.getElementById('cur-move').innerHTML = elem + " — ?" - ST.highlight_elem (elem); - CUR_ELEMS = [elem]; - CUR_MOVE = ""; - }; - LAST_CLICKED_ELEM = elem; -} - -function msw_make_move () { - if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } - if (CUR_MOVE == "") return; - var m = parseInt(CUR_MOVE.substring (0, 1)) - 1; - if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { - alert ("It is your Opponent's move"); - return; - } - if (! SIMPLE_MOVES) { - document.getElementById("working").style.display = "block"; - } - CONN.make_move (CUR_MOVE, play_py_id (CUR_PLAY_I), msw_make_move_continue); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-21 14:49:05
|
Revision: 1492 http://toss.svn.sourceforge.net/toss/?rev=1492&view=rev Author: chalmi Date: 2011-06-21 14:48:59 +0000 (Tue, 21 Jun 2011) Log Message: ----------- UserData Modified Paths: -------------- trunk/Toss/WebClient/Main.js Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-20 08:57:53 UTC (rev 1491) +++ trunk/Toss/WebClient/Main.js 2011-06-21 14:48:59 UTC (rev 1492) @@ -352,3 +352,26 @@ document.getElementById("move-info-par").style.display = "block"; } } + +function msw_play_from_string (s) { + var lst = parse_list ('#', s); + return (new Play (lst[0], [0, 1], [lst[1], lst[2]], + lst[3], lst[4], lst[5], UNAME)); +} + +function UserData(){ + var udata = CONN.plays(); + udata = udata.split("@"); + this.user = udata[0]; + this.userName = udata[1]; + this.play_lists = new Object(); + for (var i=2; i < udata.length; i++){ + var plays = parse_list("##", udata[i]); + for (var j=0; j<plays.length; j++){ + var play = msw_play_from_string(plays[j]); + var key = play.game; + if (this.play_lists[key] == undefined) this.play_lists[key] = new Array(); + this.play_lists[key].push(play); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-20 08:57:59
|
Revision: 1491 http://toss.svn.sourceforge.net/toss/?rev=1491&view=rev Author: chalmi Date: 2011-06-20 08:57:53 +0000 (Mon, 20 Jun 2011) Log Message: ----------- formatted result string in object style Modified Paths: -------------- trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-19 18:04:31 UTC (rev 1490) +++ trunk/Toss/WebClient/Main.js 2011-06-20 08:57:53 UTC (rev 1491) @@ -53,72 +53,7 @@ } // Play lists on display. - -function get_winners (play)//returns null if tie or play is not finished -{ - var result; - if (play.cur_state.result != null) result = play.cur_state.result; - else return null; - var winners = new Array(); - var maximum, minimum; - if (result[0] != undefined) {minimum = maximum = result[0]; winners.push(play.players[0]);} - else return null; - for (index in result) - { - if (index != 0) - { - if (result[index] > maximum) - { - maximum = result[index]; - winners = new Array(play.players[index]); - } - else if (result[index] == maximum) winners.push(play.players[index]); - if (result[index] < minimum) minimum = result[index]; - } - } - if (maximum > minimum) return winners; - else return null; -} - -function get_formatted_result_string (play) -{ - var result_string = ""; - if (play.cur_state.result == null) return ""; - else - { - winners = get_winners(play); - if (winners == null) return "Tie"; - if (winners.length == 0) return null; - for (var i=0; i < winners.length; i++) - { - if (i > 0) result_string += ', ' + disp_name(winners[i]); - else result_string = disp_name(winners[i]); - } - result_string += " won"; - return result_string; - } -} - function new_play_item (game, i) { - - var win_s = function (pl, un) { - //if (pl == un) { return ("You Win!"); } - return (disp_name(pl) + " won"); - } - var subst_pl = function (pl, str) { - var un = pl.cur_player_uid; - var s = strip (' ', '\n', str); - if (s == "0: 1., 1: -1.") { return (win_s (pl.players[0], un)); } - if (s == "0: -1., 1: 1.") { return (win_s (pl.players[1], un)); } - if (s == "0: 0., 1: 0.") { return ("Tie"); } - var s1 = s.replace (/0:/g, disp_name(pl.players[0]) + ":"); - var s2 = s1.replace (/1:/g, disp_name(pl.players[1]) + ":"); - var s3 = s2.replace (/1.,/g, "1,"); - var s4 = s3.replace (/0.,/g, "0,"); - var s5 = s4.replace (/1.$/g, "1"); - return (s5.replace (/0.$/g, "0")); - } - var li = document.createElement('li'); li.setAttribute ("class", "plays-list-elem"); li.setAttribute ("id", "plays-list-" + game + "-elem-" + i); @@ -128,7 +63,7 @@ '" onclick="'+ "play_click('" + game + "', " + PLAYS[i].pid + ", " + i + ')">' + pname + '</button> '; li.innerHTML = bs; - if (PLAYS[i].cur_state.result != null) li.innerHTML += '<span class="list_result">' + get_formatted_result_string(PLAYS[i]) + '</span>'; + if (PLAYS[i].cur_state.result != null) li.innerHTML += '<span class="list_result">' + PLAYS[i].get_formatted_result_string() + '</span>'; // +'<a href="#" onclick="'+ "del_play('"+ fn + "')" + '">Delete</a>'; return (li); } Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-19 18:04:31 UTC (rev 1490) +++ trunk/Toss/WebClient/Play.js 2011-06-20 08:57:53 UTC (rev 1491) @@ -163,7 +163,57 @@ } Play.prototype.next_move = play_next_move; +Play.prototype.get_winners = function() +{ + var result; + if (this.cur_state.result != null) result = this.cur_state.result; + else return null; + var winners = new Array(); + var maximum, minimum; + for (index in result) + { + if (maximum != undefined) + { + if (result[index] > maximum) + { + maximum = result[index]; + winners = new Array(this.players[index]); + } + else + { + if (result[index] == maximum) winners.push(this.players[index]); + else minimum = result[index]; + } + } + else + { + minimum = maximum = result[index]; + winners = new Array(this.players[index]); + } + } + if (maximum > minimum) return winners; + else return null; +} +Play.prototype.get_formatted_result_string = function () +{ + var result_string = ""; + if (this.cur_state.result == null) return ""; + else + { + winners = this.get_winners(); + if (winners == null) return "Tie"; + if (winners.length == 0) return null; + for (var i=0; i < winners.length; i++) + { + if (i > 0) result_string += ', ' + disp_name(winners[i]); + else result_string = disp_name(winners[i]); + } + result_string += " won"; + return result_string; + } +} + // --- Wrapper Class for unified handling of Play display functions --- function PlayDisplay (busy_id, cur_move_id) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-19 18:04:37
|
Revision: 1490 http://toss.svn.sourceforge.net/toss/?rev=1490&view=rev Author: lukaszkaiser Date: 2011-06-19 18:04:31 +0000 (Sun, 19 Jun 2011) Log Message: ----------- First PacMan example, some JS cleanups and news section in index html. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js trunk/Toss/WebClient/State.js trunk/Toss/WebClient/index.html trunk/Toss/WebClient/msw.js Added Paths: ----------- trunk/Toss/WebClient/pics/appstore.png trunk/Toss/examples/PacMan.toss Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-19 18:04:31 UTC (rev 1490) @@ -455,10 +455,7 @@ | x when x > 1 -> failwith ("passwd from db: multiple entries for " ^ uid) | _ -> let r = List.hd res in (* r = (uid,_,_,_,pwd) *) Some (r.(4)) in let get_user_name_surname_mail uid = - let res0 = dbtable ("id='" ^ uid ^ "'") "users" in - let res = if res0 = [] then - dbtable ("id='" ^ (str_replace "-" "_" uid) ^ "'") "users" - else res0 in + let res = dbtable ("id='" ^ uid ^ "'") "users" in match List.length res with | 0 -> ("", "", "") | x when x > 1 -> failwith ("get_user_name: multiple entries for " ^ uid) @@ -473,11 +470,9 @@ let list_plays game pl_id = let or_s = "(player1='" ^ pl_id ^ "' or player2='" ^ pl_id ^ "')" in let plays = dbtable ("game='" ^ game ^ "' and " ^ or_s) "cur_states" in - let rpl s = str_replace "_" "-" s in let play_name p = (* p = (pid, g, p1, p2, move, _, _, _, _) *) - "/" ^ (rpl p.(1)) ^ "_" ^ (rpl p.(2)) ^ "_" ^ (rpl p.(3)) ^ "_" ^ - (rpl p.(0)) ^ "_" ^ (rpl p.(4)) ^ "_" ^ (rpl p.(7)) in - lstr ~sep:"#" (List.map play_name plays) in + p.(1) ^"#"^ p.(2) ^"#"^ p.(3) ^"#"^ p.(0) ^"#"^ p.(4) ^"#"^ p.(7) in + lstr ~sep:"##" (List.map play_name plays) in let user_plays uid = let (name, _, _) = get_user_name_surname_mail uid in let app_plays plays g = plays ^ "@" ^ (list_plays g uid) in Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Connect.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -20,7 +20,7 @@ // Convert a string [str] representing python list to array and return it. // WARNING: we use [sep] as separator, it must not occur in list elements! -function convert_python_list (sep, str_in) { +function parse_list (sep, str_in) { var res_arr = []; var str = strip(' ', '\n', str_in); res_arr = strip('[', ']', str).split(sep); Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Login.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -68,6 +68,7 @@ document.getElementById("toss-link").style.display = "none"; document.getElementById("welcome-top").style.display = "none"; document.getElementById("welcome-list-main").style.display = "none"; + document.getElementById("news").style.display = "none"; document.getElementById("topuser").innerHTML = "Choose Your Next Game"; document.getElementById("leftupperlogo-link").href = "index.html?simple=true"; @@ -114,7 +115,7 @@ o.appendChild (li); } var lst = CONN.allopnts (); - var users = convert_python_list (',', lst); + var users = parse_list (',', lst); var u = document.getElementById("users-list"); for (var i = 0; i < users.length; i++) { if (users[i] != un && FRIENDS.indexOf(users[i]) == -1) { @@ -229,6 +230,11 @@ alert ("Your data must not contain #, i.e. the hash symbol." + CORRMSG); return; } + if (un.indexOf ("@") > 0 || name.indexOf ("@") > 0 || + surname.indexOf ("@") > 0) { + alert ("Your username, name and surname must not contain @." + CORRMSG); + return; + } if (un.indexOf (",") > 0 || name.indexOf (",") > 0 || surname.indexOf (",") > 0 || email.indexOf (",") > 0) { alert ("Your data must not contain commas." + CORRMSG); Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Main.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -46,9 +46,8 @@ } function play_from_string (game, s) { - var d = game.length + 2; - var p = s.substring(s.lastIndexOf('/') + d); - var lst = convert_python_list ('_', p); + var p = s.substring(game.length + 1); + var lst = parse_list ('#', p); return (new Play (game, [0, 1], [lst[0], lst[1]], lst[2], lst[3], lst[4], UNAME)); } @@ -136,7 +135,7 @@ function list_plays_string (game, lst) { - PLAYS = convert_python_list ('#', lst); + PLAYS = parse_list ('##', lst); var a_plist = document.getElementById("a-plays-list-" + game); var d_plist = document.getElementById("d-plays-list-" + game); while (a_plist.childNodes.length > 0) { a_plist.removeChild(a_plist.firstChild); } @@ -332,7 +331,7 @@ function get_opponents () { var lst = CONN.friends (); - FRIENDS = convert_python_list (',', lst); + FRIENDS = parse_list (',', lst); } function play_anew (me_starts) { Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Play.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -132,8 +132,7 @@ if (this.CUR_MOVE == "") return; var m = parseInt(this.CUR_MOVE.substring (0, 1)) - 1; if (!isNaN(m) && this.players[m] != this.cur_player_uid && - this.players[m] != "computer" && - this.players[m] != this.cur_player_uid.replace("_", "-")) { + this.players[m] != "computer") { alert ("It is your Opponent's move"); return; } Modified: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/State.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -106,10 +106,10 @@ this.height = Math.max (SVG_HEIGHT / 100, (this.maxy - this.miny)); // The second component is the list of elements of the structure. - var l = convert_python_list(',', res_arr[1]); + var l = parse_list(',', res_arr[1]); this.elems = []; for (var i = 0; i < l.length; i++) { - var e = convert_python_list (';', l[i]); + var e = parse_list (';', l[i]); var pos = translate_pos ([parseFloat(e[1]), parseFloat(e[2])], this.minx, this.miny, this.width, this.height, this.mirror); @@ -124,12 +124,12 @@ } // The third component are the relations in the structure. - var r = convert_python_list(';', res_arr[2]); + var r = parse_list(';', res_arr[2]); var rels = []; for (var i = 0; i < r.length; i++) { var rel_name = strip(' ', '\'', r[i].substring(1,r[i].indexOf(','))); var args_s = r[i].substring(r[i].indexOf('[')+1, r[i].indexOf(']')); - var args = convert_python_list (',', args_s); + var args = parse_list (',', args_s); var is_undefined = false; for (var j = 0; j < args.length; j++) { args[j] = find_elem (args[j], this.elems); @@ -153,7 +153,7 @@ // If there are no moves possible, it is the payoff. // The second option in "or" below is just for old format, will be removed. if (res_arr[3].substring(2, 3) =="(" || res_arr[3].substring(0, 1) =="(") { - var move_strs = convert_python_list (';', res_arr[3]); + var move_strs = parse_list (';', res_arr[3]); var mvs = []; var pls = []; for (i = 0; i < move_strs.length; i++) { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/index.html 2011-06-19 18:04:31 UTC (rev 1490) @@ -94,7 +94,11 @@ <div id="welcome"> <p id="welcome-top">Enjoy the best games on <span class="logo-in">tPlay</span> - for free</p> + for free + <a href="http://itunes.apple.com/us/app/tplay/id438620686"> + <img style="height: 2em; float:right;" src="pics/appstore.png" /> + </a> +</p> <p id="p-under-welcome" style="display: none;"> Strategic games are fun! <a href="register.html">Register</a>, login and enjoy quality games @@ -172,8 +176,22 @@ <li>Challenge your friends or play a fast game against the computer for fun</li> </ul> +<div id="news"> +<h3>News</h3> +<ul id="welcome-list-news" class="welcome-list"> +<li><b>19/06/11</b> News section on the front page of tPlay</li> +<li><b>15/06/11</b> Bug with underscores in user names corrected</li> +<li><b>10/06/11</b> New register site handles forgotten passwords</li> +<li><b>05/06/11</b> Pre-caching client states improves response times</li> +<li><b>03/06/11</b> Corrected tPlay 1.1 app accepted on App Store</li> +<li><b>30/05/11</b> Large restructuring of JavaScript code finished</li> +<li><b>24/05/11</b> Breakthrough generation from examples in SVN</li> +<li><b>23/05/11</b> First tPlay application accepted on App Store</li> +</ul> </div> +</div> + <div id="nosvg"> <p style="padding-left: 1.2em; font-size: 1.2em;"><b>SVG Support Missing</b></p> <p>Your browser does not seem to support SVG, Modified: trunk/Toss/WebClient/msw.js =================================================================== --- trunk/Toss/WebClient/msw.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/msw.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -1,11 +1,11 @@ function msw_list_plays_string (game, lst) { - PLAYS = convert_python_list ('#', lst); + PLAYS = parse_list ('#', lst); //var plist = document.getElementById("plays-list-" + game); //while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } var d = game.length + 2; for (var i = 0; i < PLAYS.length; i++) { var p = PLAYS[i].substring(PLAYS[i].lastIndexOf('/') + d); - PLAYS[i] = convert_python_list ('_', p); + PLAYS[i] = parse_list ('_', p); //plist.appendChild(new_play_item (game, i)); } /*if (PLAYS.length == 0) { Added: trunk/Toss/WebClient/pics/appstore.png =================================================================== (Binary files differ) Property changes on: trunk/Toss/WebClient/pics/appstore.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/Toss/examples/PacMan.toss =================================================================== --- trunk/Toss/examples/PacMan.toss (rev 0) +++ trunk/Toss/examples/PacMan.toss 2011-06-19 18:04:31 UTC (rev 1490) @@ -0,0 +1,45 @@ +PLAYERS 1, 2, 3 +RULE Go1: + [ a1, a2 | C { (a1) }; E { (a1, a2) } | - ] + -> + [ a1, a2 | C { (a2) }; E { (a1, a2) } | - ] +emb C, C2 +RULE Go2: + [ a1, a2 | C2 { (a1) }; E { (a1, a2) } | - ] + -> + [ a1, a2 | C2 { (a2) }; E { (a1, a2) } | - ] +emb C, C2 +RULE Wait: + [ a1 | R { (a1) } | - ] -> [ a1 | R { (a1) } | - ] +emb R, C, C2 +RULE Wait1: + [ a1 | C { (a1) } | - ] -> [ a1 | C { (a1) } | - ] +emb R, C, C2 +RULE Wait2: + [ a1 | C2 { (a1) } | - ] -> [ a1 | C2 { (a1) } | - ] +emb R, C, C2 +RULE Run: + [ a1, a2 | E { (a1, a2) }; R { (a1) } | - ] + -> + [ a1, a2 | E { (a1, a2) }; R { (a2) } | - ] +emb R, C, C2 +LOC 0 { + PLAYER 1 { PAYOFF 0. } + PLAYER 2 { + PAYOFF 0. + MOVES [Go1 -> 1]; [Wait1 -> 1] + } + PLAYER 3 { + PAYOFF 0. + MOVES [Go2 -> 1]; [Wait2 -> 1] + } +} +LOC 1 { + PLAYER 1 { + PAYOFF -1. + MOVES [Run -> 0]; [Wait -> 0] + } + PLAYER 2 { PAYOFF 1. } + PLAYER 3 { PAYOFF 1. } +} +MODEL [ a1, a2, b1, b2, c1, c2, d1, d2, f1, f2, g1, g2, h1, h2, e1, e2, i1, i2 | C { (a1) }; C2 { (a2) }; E { (a2, a1); (a2, b2); (a1, a2); (a1, b1); (b1, a1); (b1, b2); (b1, c1); (b2, a2); (b2, b1); (b2, c2); (c2, b2); (c2, c1); (c2, d2); (c1, b1); (c1, c2); (c1, d1); (d2, c2); (d2, d1); (d2, e1); (d1, c1); (d1, d2); (d1, e2); (f1, f2); (f1, g1); (f1, e1); (f2, f1); (f2, g2); (f2, e2); (g1, f1); (g1, g2); (g1, h1); (g2, f2); (g2, g1); (g2, h2); (h1, g1); (h1, h2); (h1, i1); (h2, g2); (h2, h1); (h2, i2); (e1, d2); (e1, f1); (e1, e2); (e2, d1); (e2, f2); (e2, e1); (i1, h1); (i1, i2); (i2, h2); (i2, i1) }; R { (e1) }; _opt_C:1 { } | vx { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; vy { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; x { d4->100., a2->-50., a1->-50., b1->0., b2->0., e4->150., c2->50., c1->50., f4->200., d2->100., d1->100., f1->200., f2->200., g1->250., g2->250., h1->300., h2->300., e1->150., e2->150., i1->350., i2->350. }; y { d4->-150., a2->-100., a1->-50., b1->-50., b2->-100., e4->0., c2->-100., c1->-50., f4->-150., d2->-100., d1->-50., f1->-100., f2->-50., g1->-100., g2->-50., h1->-100., h2->-50., e1->-100., e2->-50., i1->-100., i2->-50. } ] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-19 11:57:24
|
Revision: 1489 http://toss.svn.sourceforge.net/toss/?rev=1489&view=rev Author: chalmi Date: 2011-06-19 11:57:18 +0000 (Sun, 19 Jun 2011) Log Message: ----------- Result continued... Modified Paths: -------------- trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/State.js Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-18 19:39:12 UTC (rev 1488) +++ trunk/Toss/WebClient/Main.js 2011-06-19 11:57:18 UTC (rev 1489) @@ -53,9 +53,53 @@ lst[2], lst[3], lst[4], UNAME)); } - // Play lists on display. +function get_winners (play)//returns null if tie or play is not finished +{ + var result; + if (play.cur_state.result != null) result = play.cur_state.result; + else return null; + var winners = new Array(); + var maximum, minimum; + if (result[0] != undefined) {minimum = maximum = result[0]; winners.push(play.players[0]);} + else return null; + for (index in result) + { + if (index != 0) + { + if (result[index] > maximum) + { + maximum = result[index]; + winners = new Array(play.players[index]); + } + else if (result[index] == maximum) winners.push(play.players[index]); + if (result[index] < minimum) minimum = result[index]; + } + } + if (maximum > minimum) return winners; + else return null; +} + +function get_formatted_result_string (play) +{ + var result_string = ""; + if (play.cur_state.result == null) return ""; + else + { + winners = get_winners(play); + if (winners == null) return "Tie"; + if (winners.length == 0) return null; + for (var i=0; i < winners.length; i++) + { + if (i > 0) result_string += ', ' + disp_name(winners[i]); + else result_string = disp_name(winners[i]); + } + result_string += " won"; + return result_string; + } +} + function new_play_item (game, i) { var win_s = function (pl, un) { @@ -85,7 +129,7 @@ '" onclick="'+ "play_click('" + game + "', " + PLAYS[i].pid + ", " + i + ')">' + pname + '</button> '; li.innerHTML = bs; - if (PLAYS[i].cur_state.payoff != "") li.innerHTML += '<span class="list_result">' + subst_pl(PLAYS[i], PLAYS[i].cur_state.payoff) + '</span>'; + if (PLAYS[i].cur_state.result != null) li.innerHTML += '<span class="list_result">' + get_formatted_result_string(PLAYS[i]) + '</span>'; // +'<a href="#" onclick="'+ "del_play('"+ fn + "')" + '">Delete</a>'; return (li); } Modified: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-06-18 19:39:12 UTC (rev 1488) +++ trunk/Toss/WebClient/State.js 2011-06-19 11:57:18 UTC (rev 1489) @@ -164,6 +164,7 @@ this.moves = mvs; this.players = pls; this.payoff = ""; + this.result = null; } else { this.moves = []; this.players = []; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-18 19:39:18
|
Revision: 1488 http://toss.svn.sourceforge.net/toss/?rev=1488&view=rev Author: chalmi Date: 2011-06-18 19:39:12 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Associative array result Modified Paths: -------------- trunk/Toss/WebClient/State.js Modified: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-06-17 20:31:43 UTC (rev 1487) +++ trunk/Toss/WebClient/State.js 2011-06-18 19:39:12 UTC (rev 1488) @@ -168,6 +168,13 @@ this.moves = []; this.players = []; this.payoff = res_arr[3]; + this.result = new Object(); + var players_pays = this.payoff.split(', '); + for (var i = 0; i < players_pays.length; i++) + { + var help = players_pays[i].split(': '); + this.result[help[0]] = parseFloat(help[1]); + } }; return (this); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-17 20:31:51
|
Revision: 1487 http://toss.svn.sourceforge.net/toss/?rev=1487&view=rev Author: lukaszkaiser Date: 2011-06-17 20:31:43 +0000 (Fri, 17 Jun 2011) Log Message: ----------- PlayDisplay object and previous move command. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-17 20:31:43 UTC (rev 1487) @@ -425,7 +425,7 @@ with Not_found -> fname_in1 in let fname = !html_dir_path ^ fname_in in if !debug_level > 1 then Printf.printf "SERVING FILE: %s;\n%!" fname; - if Sys.file_exists fname then ( + if Sys.file_exists fname && not (Sys.is_directory fname) then ( let f = open_in fname in let content = Aux.input_file f in close_in f; @@ -572,6 +572,9 @@ let res = dbtable (game_select_s pid) "cur_states" in let (move, info) = ((List.hd res).(4), (List.hd res).(7)) in info in + let open_old pid move = + let res = dbtable ("playid=" ^ pid ^ " and move=" ^ move) "old_states" in + if res = [] then "NONE" else (List.hd res).(7) in let add_opponent uid oppid = if uid = "" then "You must login first to add opponents." else let (name, _, _) = get_user_name_surname_mail oppid in @@ -650,6 +653,8 @@ let a = get_args data in list_plays a.(0) a.(1), [] | "OPEN_DB" -> let a = get_args data in open_db a.(0), [] + | "PREV_MOVE" -> + let a = get_args data in open_old a.(0) a.(1), [] | "NEW_PLAY" -> let a = get_args data in new_play a.(0) a.(1) a.(2), [] | "SUGGEST" -> Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Connect.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -108,6 +108,9 @@ } this.open_db = function (pid) { return (srv ("OPEN_DB", pid)); } + this.prev_move = function (pid, mv) { + return (srv ("PREV_MOVE", pid + ", " + mv)); + } this.new_play = function (g, un, opp) { return (srv ("NEW_PLAY", g + ", " + un + ", " + opp)); } Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Login.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -224,6 +224,16 @@ alert ("Your data must not contain $, i.e. the dolar sign." + CORRMSG); return; } + if (un.indexOf ("#") > 0 || name.indexOf ("#") > 0 || + surname.indexOf ("#") > 0 || email.indexOf ("#") > 0) { + alert ("Your data must not contain #, i.e. the hash symbol." + CORRMSG); + return; + } + if (un.indexOf (",") > 0 || name.indexOf (",") > 0 || + surname.indexOf (",") > 0 || email.indexOf (",") > 0) { + alert ("Your data must not contain commas." + CORRMSG); + return; + } var data = un + "$" + name + "$" + surname + "$" + email; var resp = CONN.register (data, crypt(TSALT + pwd)); alert (resp); Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Main.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -22,6 +22,7 @@ UNAME_TO_NAME_MAP[uname] = name; return (name); } +nameDISP = disp_name; function handle_elem_click (elem) { PLAYS[CUR_PLAY_I].handle_click (elem); @@ -32,17 +33,18 @@ } function make_move_continue (info) { - var listing_f = function (play) {/* - var old_li = document.getElementById ("plays-list-" + play.game + - "-elem-" + CUR_PLAY_I); - var li = new_play_item (play.game, CUR_PLAY_I); - old_li.parentNode.replaceChild (li, old_li); - */}; var suggest_f = function (time) { suggest_move_async (time, make_move) }; - PLAYS[CUR_PLAY_I].move_continue (info, listing_f, suggest_f, disp_name); + PLAYS[CUR_PLAY_I].move_continue (info, suggest_f); } +function prev_move_click () { + PLAYS[CUR_PLAY_I].prev_move (); +} +function next_move_click () { + PLAYS[CUR_PLAY_I].next_move (); +} + function play_from_string (game, s) { var d = game.length + 2; var p = s.substring(s.lastIndexOf('/') + d); @@ -131,7 +133,7 @@ document.getElementById("play-number").innerHTML = "" + play_id; document.getElementById("suggestions-toggle").style.display = "inline"; CUR_PLAY_I = pi; - PLAYS[CUR_PLAY_I].redraw (disp_name); + PLAYS[CUR_PLAY_I].redraw (); } @@ -279,7 +281,7 @@ var p = new Play (GAME_NAME, [0,1], [UNAME, opp_uid], FREE_PLAY_NO, 0, info_nbr.substring(info_idx+1), UNAME); PLAYS.push(p); - p.redraw (disp_name); + p.redraw (); //li = new_play_item (GAME_NAME, CUR_PLAY_I); //document.getElementById("plays-list-" + GAME_NAME).appendChild(li); } Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Play.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -1,6 +1,8 @@ // JavaScript Toss Module -- Play (requires Connect.js, State.js) var SIMPLE_MOVES = true; +var nameDISP = undefined; +var PlayDISP = undefined; // --------- Play Object with Methods -------------- @@ -44,52 +46,15 @@ Play.prototype.clear = play_clear; // Full redraw. -function play_redraw (f_disp_name) { +function play_redraw () { this.clear (); - document.getElementById('cur-move').innerHTML = "none"; - this.cur_state.draw_model (this.game); - - // Functions to substitute players for 0 and 1 in a payoff string. - var win_s = function (pl, un) { - if (pl == un) { return ("You Win!"); } - return (f_disp_name(pl) + " Wins"); - } - var subst_pl = function (pl, str) { - var un = pl.cur_player_uid; - var s = strip (' ', '\n', str); - if (s == "0: 1., 1: -1.") { return (win_s (pl.players[0], un)); } - if (s == "0: -1., 1: 1.") { return (win_s (pl.players[1], un)); } - if (s == "0: 0., 1: 0.") { return ("Tie"); } - var s1 = s.replace (/0:/g, f_disp_name(pl.players[0]) + ":"); - var s2 = s1.replace (/1:/g, f_disp_name(pl.players[1]) + ":"); - var s3 = s2.replace (/1.,/g, "1,"); - var s4 = s3.replace (/0.,/g, "0,"); - var s5 = s4.replace (/1.$/g, "1"); - return (s5.replace (/0.$/g, "0")); - } - - - if (! SIMPLE_MOVES) { - document.getElementById("working").style.display = "block"; - } for (var i = 0; i < this.cur_state.elems.length; i++) { this.ELEM_COUNTERS[this.cur_state.elems[i].id] = 0; } - if (this.cur_state.payoff == "") { - document.getElementById('movebt').innerHTML = "Make move:"; - document.getElementById('cur-move').innerHTML = "none"; - } else { - if (SIMPLE_MOVES) { - document.getElementById("board").style.paddingTop = "0em"; - } - document.getElementById("move-info-par").style.display = "none"; - document.getElementById("game-info-par").style.paddingBottom = "0em"; - document.getElementById('payoffs').innerHTML = - "Result: " + subst_pl(this, this.cur_state.payoff); - document.getElementById('payoffs').style.display = "inline"; - document.getElementById('new-play-par').style.display = "block"; - } - document.getElementById("working").style.display = "none"; + PlayDISP.free (); + PlayDISP.set_cur_move ("", ""); + PlayDISP.show_payoff (this); + this.cur_state.draw_model (this.game); } Play.prototype.redraw = play_redraw; @@ -102,12 +67,7 @@ for (var i = 0; i < m.matched.length; i++) { this.cur_state.highlight_elem (m.matched[i]); } - if (m.matched_str == "") { - document.getElementById('cur-move').innerHTML = "none"; - } else { - document.getElementById('cur-move').innerHTML = - m.matched_str.replace (/,/g, " — ") + " (" + m.rule + ")" - } + PlayDISP.set_cur_move (m.matched_str, m.rule); this.CUR_ELEMS = m.matched; this.CUR_MOVE = m.def_str; } @@ -156,7 +116,7 @@ for (var i = 0; i < this.CUR_ELEMS.length; i++) { this.cur_state.unhighlight_elem (this.CUR_ELEMS[i]); } - document.getElementById('cur-move').innerHTML = elem + " — ?" + PlayDISP.set_cur_move (elem + ", ?", ""); this.cur_state.highlight_elem (elem); this.CUR_ELEMS = [elem]; this.CUR_MOVE = ""; @@ -177,18 +137,15 @@ alert ("It is your Opponent's move"); return; } - if (! SIMPLE_MOVES) { - document.getElementById("working").style.display = "block"; - } + if (! SIMPLE_MOVES) { PlayDISP.busy (); } CONN.make_move (this.CUR_MOVE, this.pid, make_move_continue); } Play.prototype.move = play_move; -function play_move_continue (info, listing_redraw_f, suggest_f, name_f) { - document.getElementById("working").style.display = "none"; +function play_move_continue (info, suggest_f) { + PlayDISP.free (); this.new_state (info); - this.redraw (name_f); - listing_redraw_f (this); + this.redraw (); if (this.cur_state.players.length == 1 && this.players[this.cur_state.players[0]] == "computer") { var mv_time = document.getElementById("speed").value; @@ -196,3 +153,83 @@ } } Play.prototype.move_continue = play_move_continue; + +function play_prev_move () { + alert (CONN.prev_move (this.pid, this.move_nbr - 1)); +} +Play.prototype.prev_move = play_prev_move; + +function play_next_move () { + alert (CONN.prev_move (this.pid, this.move_nbr + 1)); +} +Play.prototype.next_move = play_next_move; + + +// --- Wrapper Class for unified handling of Play display functions --- + +function PlayDisplay (busy_id, cur_move_id) { + this.busy_id = busy_id; + this.cur_move_id = cur_move_id; + return (this); +} + +function pd_busy () { + document.getElementById (this.busy_id).style.display = "block"; +} +PlayDisplay.prototype.busy = pd_busy; + +function pd_free () { + document.getElementById (this.busy_id).style.display = "none"; +} +PlayDisplay.prototype.free = pd_free; + +function pd_set_cur_move (matched_str, rule_str) { + if (matched_str == "") { + document.getElementById(this.cur_move_id).innerHTML = "none"; + } else { + var rule = " (" + rule_str + ")"; + if (rule_str == "") { rule = "" }; + document.getElementById(this.cur_move_id).innerHTML = + matched_str.replace (/,/g, " — ") + rule + } +} +PlayDisplay.prototype.set_cur_move = pd_set_cur_move; + +function pd_show_payoff (play) { + // Functions to substitute players for 0 and 1 in a payoff string. + var win_s = function (pl, un) { + if (pl == un) { return ("You Win!"); } + return (nameDISP(pl) + " Wins"); + } + var subst_pl = function (pl, str) { + var un = pl.cur_player_uid; + var s = strip (' ', '\n', str); + if (s == "0: 1., 1: -1.") { return (win_s (pl.players[0], un)); } + if (s == "0: -1., 1: 1.") { return (win_s (pl.players[1], un)); } + if (s == "0: 0., 1: 0.") { return ("Tie"); } + var s1 = s.replace (/0:/g, nameDISP(pl.players[0]) + ":"); + var s2 = s1.replace (/1:/g, nameDISP(pl.players[1]) + ":"); + var s3 = s2.replace (/1.,/g, "1,"); + var s4 = s3.replace (/0.,/g, "0,"); + var s5 = s4.replace (/1.$/g, "1"); + return (s5.replace (/0.$/g, "0")); + } + + if (play.cur_state.payoff == "") { + document.getElementById('movebt').innerHTML = "Make move:"; + this.set_cur_move ("", ""); + } else { + if (SIMPLE_MOVES) { + document.getElementById("board").style.paddingTop = "0em"; + } + document.getElementById("move-info-par").style.display = "none"; + document.getElementById("game-info-par").style.paddingBottom = "0em"; + document.getElementById('payoffs').innerHTML = + "Result: " + subst_pl(play, play.cur_state.payoff); + document.getElementById('payoffs').style.display = "inline"; + document.getElementById('new-play-par').style.display = "block"; + } +} +PlayDisplay.prototype.show_payoff = pd_show_payoff; + +PlayDISP = new PlayDisplay ("working", "cur-move"); Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Style.css 2011-06-17 20:31:43 UTC (rev 1487) @@ -685,7 +685,7 @@ .game-par { padding: 0px; padding-bottom: 0.2em; - border-bottom: 1px solid #260314; + /* border-bottom: 1px solid #260314; */ } #plays { @@ -717,6 +717,7 @@ padding-left: 0px; list-style: none; margin-top: 0em; + border-top: 1px solid #260314; } .plays-list-elem { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/index.html 2011-06-17 20:31:43 UTC (rev 1487) @@ -197,12 +197,12 @@ <button onclick="new_play('Breakthrough')" class="boldobt">Breakthrough</button> </p> -<ul class="plays-list" id="a-plays-list-Breakthrough"> + <ul class="plays-list" id="a-plays-list-Breakthrough"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Breakthrough"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Breakthrough"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Checkers')" class="boldobt">Checkers</button> @@ -210,9 +210,9 @@ <ul class="plays-list" id="a-plays-list-Checkers"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Checkers"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Checkers"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Chess')" class="boldobt">Chess</button> @@ -220,9 +220,9 @@ <ul class="plays-list" id="a-plays-list-Chess"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Chess"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Chess"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Connect4')" class="boldobt">Connect4</button> @@ -230,9 +230,9 @@ <ul class="plays-list" id="a-plays-list-Connect4"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Connect4"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Connect4"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Entanglement')" class="boldobt">Entanglement</button> @@ -240,9 +240,9 @@ <ul class="plays-list" id="a-plays-list-Entanglement"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Entanglement"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Entanglement"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Gomoku')" class="boldobt">Gomoku</button> @@ -250,9 +250,9 @@ <ul class="plays-list" id="a-plays-list-Gomoku"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Gomoku"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Gomoku"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Pawn-Whopping')" class="boldobt">Pawn-Whopping</button> @@ -260,9 +260,9 @@ <ul class="plays-list" id="a-plays-list-Pawn-Whopping"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Pawn-Whopping"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Pawn-Whopping"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Tic-Tac-Toe')" class="boldobt">Tic-Tac-Toe</button> @@ -270,9 +270,9 @@ <ul class="plays-list" id="a-plays-list-Tic-Tac-Toe"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Tic-Tac-Toe"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Concurrent-Tic-Tac-Toe')" class="boldobt">Concurrent-Tic-Tac-Toe</button> @@ -280,9 +280,9 @@ <ul class="plays-list" id="a-plays-list-Concurrent-Tic-Tac-Toe"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Concurrent-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Concurrent-Tic-Tac-Toe"> + <li style="display: none;"/> + </ul> </div> @@ -295,7 +295,6 @@ </span> <span id="payoffs" style="display:none;">Not Finished Yet</span> </p> - <p id="new-play-par"> <button id="new_game_me" class="bt" onclick="play_anew(true)"> New Game (You Start) @@ -304,13 +303,18 @@ New Game (Opponent Starts) </button> </p> - <p id="move-info-par"> <button id="movebt" class="bt" onclick="make_move ()">Make move:</button> <span id="cur-move">none</span> <button id="sugbt" class="bt" onclick="suggest_move_click()"> Suggest </button> + <button id="prevmovebt" class="bt" onclick="prev_move_click()"> + Prev + </button> + <button id="nextmovebt" class="bt" onclick="next_move_click()"> + Next + </button> </p> <div id="board"><div id="working">Working...</div></div> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-17 07:26:22
|
Revision: 1486 http://toss.svn.sourceforge.net/toss/?rev=1486&view=rev Author: chalmi Date: 2011-06-17 07:26:16 +0000 (Fri, 17 Jun 2011) Log Message: ----------- split plays into 2 lists: beta. Modified Paths: -------------- trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-16 17:34:11 UTC (rev 1485) +++ trunk/Toss/WebClient/Main.js 2011-06-17 07:26:16 UTC (rev 1486) @@ -32,12 +32,12 @@ } function make_move_continue (info) { - var listing_f = function (play) { + var listing_f = function (play) {/* var old_li = document.getElementById ("plays-list-" + play.game + "-elem-" + CUR_PLAY_I); var li = new_play_item (play.game, CUR_PLAY_I); old_li.parentNode.replaceChild (li, old_li); - }; + */}; var suggest_f = function (time) { suggest_move_async (time, make_move) }; PLAYS[CUR_PLAY_I].move_continue (info, listing_f, suggest_f, disp_name); } @@ -55,6 +55,25 @@ // Play lists on display. function new_play_item (game, i) { + + var win_s = function (pl, un) { + //if (pl == un) { return ("You Win!"); } + return (disp_name(pl) + " won"); + } + var subst_pl = function (pl, str) { + var un = pl.cur_player_uid; + var s = strip (' ', '\n', str); + if (s == "0: 1., 1: -1.") { return (win_s (pl.players[0], un)); } + if (s == "0: -1., 1: 1.") { return (win_s (pl.players[1], un)); } + if (s == "0: 0., 1: 0.") { return ("Tie"); } + var s1 = s.replace (/0:/g, disp_name(pl.players[0]) + ":"); + var s2 = s1.replace (/1:/g, disp_name(pl.players[1]) + ":"); + var s3 = s2.replace (/1.,/g, "1,"); + var s4 = s3.replace (/0.,/g, "0,"); + var s5 = s4.replace (/1.$/g, "1"); + return (s5.replace (/0.$/g, "0")); + } + var li = document.createElement('li'); li.setAttribute ("class", "plays-list-elem"); li.setAttribute ("id", "plays-list-" + game + "-elem-" + i); @@ -63,23 +82,31 @@ var bs = '<button class="obt" title="Open game ' + PLAYS[i].pid + '" onclick="'+ "play_click('" + game + "', " + PLAYS[i].pid + ", " + i + ')">' + pname + '</button> '; - li.innerHTML = bs + li.innerHTML = bs; + if (PLAYS[i].cur_state.payoff != "") li.innerHTML += '<span class="list_result">' + subst_pl(PLAYS[i], PLAYS[i].cur_state.payoff) + '</span>'; // +'<a href="#" onclick="'+ "del_play('"+ fn + "')" + '">Delete</a>'; return (li); } + function list_plays_string (game, lst) { PLAYS = convert_python_list ('#', lst); - var plist = document.getElementById("plays-list-" + game); - while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } + var a_plist = document.getElementById("a-plays-list-" + game); + var d_plist = document.getElementById("d-plays-list-" + game); + while (a_plist.childNodes.length > 0) { a_plist.removeChild(a_plist.firstChild); } + while (d_plist.childNodes.length > 0) { d_plist.removeChild(d_plist.firstChild); } for (var i = 0; i < PLAYS.length; i++) { PLAYS[i] = play_from_string (game, PLAYS[i]); - plist.appendChild(new_play_item (game, i)); + if (PLAYS[i].cur_state.payoff == "") a_plist.appendChild(new_play_item (game, i)); + else + { + d_plist.appendChild(new_play_item (game, i)); + } } if (PLAYS.length == 0) { - document.getElementById("plays-list-" + game).style.display = "none"; + document.getElementById("a-plays-list-" + game).style.display = "none"; } else { - document.getElementById("plays-list-" + game).style.display = "block"; + document.getElementById("a-plays-list-" + game).style.display = "block"; } } @@ -238,7 +265,7 @@ while (olist.childNodes.length > 0) { olist.removeChild(olist.firstChild); } if (opp_uid == -1) { opp_uid = UNAME; } if (opp_uid == 0 || UNAME == "") { return; } - document.getElementById("plays-list-" + GAME_NAME).style.display = "block"; + //document.getElementById("plays-list-" + GAME_NAME).style.display = "block"; document.getElementById("working").style.display = "block"; info_nbr = CONN.new_play (GAME_NAME, UNAME, opp_uid); document.getElementById("working").style.display = "none"; @@ -253,8 +280,8 @@ info_nbr.substring(info_idx+1), UNAME); PLAYS.push(p); p.redraw (disp_name); - li = new_play_item (GAME_NAME, CUR_PLAY_I); - document.getElementById("plays-list-" + GAME_NAME).appendChild(li); + //li = new_play_item (GAME_NAME, CUR_PLAY_I); + //document.getElementById("plays-list-" + GAME_NAME).appendChild(li); } function get_opponents () { Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-16 17:34:11 UTC (rev 1485) +++ trunk/Toss/WebClient/Play.js 2011-06-17 07:26:16 UTC (rev 1486) @@ -68,6 +68,7 @@ return (s5.replace (/0.$/g, "0")); } + if (! SIMPLE_MOVES) { document.getElementById("working").style.display = "block"; } Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-16 17:34:11 UTC (rev 1485) +++ trunk/Toss/WebClient/Style.css 2011-06-17 07:26:16 UTC (rev 1486) @@ -221,6 +221,11 @@ top: 2px; } +.list_result +{ + font-size: 0.9em +} + #remember { margin: 0px; padding: 0px; Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-16 17:34:11 UTC (rev 1485) +++ trunk/Toss/WebClient/index.html 2011-06-17 07:26:16 UTC (rev 1486) @@ -197,69 +197,96 @@ <button onclick="new_play('Breakthrough')" class="boldobt">Breakthrough</button> </p> - <ul class="plays-list" id="plays-list-Breakthrough"> +<ul class="plays-list" id="a-plays-list-Breakthrough"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Breakthrough"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Checkers')" class="boldobt">Checkers</button> </p> - <ul class="plays-list" id="plays-list-Checkers"> + <ul class="plays-list" id="a-plays-list-Checkers"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Checkers"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Chess')" class="boldobt">Chess</button> </p> - <ul class="plays-list" id="plays-list-Chess"> + <ul class="plays-list" id="a-plays-list-Chess"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Chess"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Connect4')" class="boldobt">Connect4</button> </p> - <ul class="plays-list" id="plays-list-Connect4"> + <ul class="plays-list" id="a-plays-list-Connect4"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Connect4"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Entanglement')" class="boldobt">Entanglement</button> </p> - <ul class="plays-list" id="plays-list-Entanglement"> + <ul class="plays-list" id="a-plays-list-Entanglement"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Entanglement"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Gomoku')" class="boldobt">Gomoku</button> </p> - <ul class="plays-list" id="plays-list-Gomoku"> + <ul class="plays-list" id="a-plays-list-Gomoku"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Gomoku"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Pawn-Whopping')" class="boldobt">Pawn-Whopping</button> </p> - <ul class="plays-list" id="plays-list-Pawn-Whopping"> + <ul class="plays-list" id="a-plays-list-Pawn-Whopping"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Pawn-Whopping"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Tic-Tac-Toe')" class="boldobt">Tic-Tac-Toe</button> </p> - <ul class="plays-list" id="plays-list-Tic-Tac-Toe"> + <ul class="plays-list" id="a-plays-list-Tic-Tac-Toe"> <li style="display: none;"/> </ul> - <p class="game-par" style="display: none;"> + <ul class="plays-list" id="d-plays-list-Tic-Tac-Toe"> + <li style="display: none;"/> + </ul> + <p class="game-par"> <button onclick="new_play('Concurrent-Tic-Tac-Toe')" class="boldobt">Concurrent-Tic-Tac-Toe</button> </p> - <ul class="plays-list" style="display: none;" - id="plays-list-Concurrent-Tic-Tac-Toe"> + <ul class="plays-list" id="a-plays-list-Concurrent-Tic-Tac-Toe"> <li style="display: none;"/> </ul> + <ul class="plays-list" id="d-plays-list-Concurrent-Tic-Tac-Toe"> + <li style="display: none;"/> + </ul> </div> + <div id="game-disp"> <p id="game-info-par"> <span id="game-title"></span> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-16 17:34:18
|
Revision: 1485 http://toss.svn.sourceforge.net/toss/?rev=1485&view=rev Author: lukaszkaiser Date: 2011-06-16 17:34:11 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Separating plays as a class in WebClient. Modified Paths: -------------- trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/State.js trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html Added Paths: ----------- trunk/Toss/WebClient/Play.js Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-16 07:21:00 UTC (rev 1484) +++ trunk/Toss/WebClient/Main.js 2011-06-16 17:34:11 UTC (rev 1485) @@ -1,12 +1,7 @@ -// JavaScript Toss Module -- Main (requires Connect.js, DefaultStyle.js) +// JavaScript Toss Module -- Main (requires Connect.js, State.js, Play.js) var UNAME = ""; var GAME_NAME = ""; // name of current game, e.g. "Breakthrough" - -var ELEM_COUNTERS = {}; -var CUR_MOVE = ""; -var CUR_ELEMS = []; - var PLAYS = []; var CUR_PLAY_I = -1; @@ -17,160 +12,57 @@ var FULL_OPNT_LEN = 0; var CUR_OPNT_START = 0; -var LAST_CLICKED_ELEM = ""; - -var SIMPLE_MOVES = true; var SIMPLE_SET = false; -var ST = undefined; -// Clear whole svg box. -function clear_svg () { - LAST_CLICKED_ELEM = ""; - ELEM_COUNTERS = {}; - CUR_MOVE = ""; - CUR_ELEMS = []; - document.getElementById('cur-move').innerHTML = "none"; - var svg_e = document.getElementById("svg"); - if (svg_e != undefined) { svg_e.parentNode.removeChild (svg_e); } +function disp_name (uname) { + if (uname == "guest") { return ("You"); } + if (UNAME_TO_NAME_MAP[uname]) { return (UNAME_TO_NAME_MAP[uname]); } + name = CONN.get_name (uname); + UNAME_TO_NAME_MAP[uname] = name; + return (name); } -function win_s (i) { - var pl = PLAYS[CUR_PLAY_I][i]; - if (pl == UNAME) { return ("You Win!"); } - return (disp_name(pl) + " Wins"); +function handle_elem_click (elem) { + PLAYS[CUR_PLAY_I].handle_click (elem); } -// Substitute players for 0 and 1 in a payoff string. -function subst_pl (str) { - var s = strip (' ', '\n', str); - if (s == "0: 1., 1: -1.") { return (win_s (0)); } - if (s == "0: -1., 1: 1.") { return (win_s (1)); } - if (s == "0: 0., 1: 0.") { return ("Tie"); } - var s1 = s.replace (/0:/g, disp_name(PLAYS[CUR_PLAY_I][0]) + ":"); - var s2 = s1.replace (/1:/g, disp_name(PLAYS[CUR_PLAY_I][1]) + ":"); - var s3 = s2.replace (/1.,/g, "1,"); - var s4 = s3.replace (/0.,/g, "0,"); - var s5 = s4.replace (/1.$/g, "1"); - return (s5.replace (/0.$/g, "0")); +function make_move () { + PLAYS[CUR_PLAY_I].move (); } -// Full redraw. -function full_redraw (game, info_s) { - clear_svg (); - ST = new State (game, info_s); - ST.draw_model (game); - if (! SIMPLE_MOVES) { - document.getElementById("working").style.display = "block"; - } - for (var i = 0; i < ST.elems.length; i++) { - ELEM_COUNTERS[ST.elems[i].id] = 0; - } - if (ST.payoff == "") { - document.getElementById('movebt').innerHTML = "Make move:"; - document.getElementById('cur-move').innerHTML = "none"; - } else { - if (SIMPLE_MOVES) { - document.getElementById("board").style.paddingTop = "0em"; - } - document.getElementById("move-info-par").style.display = "none"; - document.getElementById("game-info-par").style.paddingBottom = "0em"; - document.getElementById('payoffs').innerHTML = - "Result: " + subst_pl(ST.payoff); - document.getElementById('payoffs').style.display = "inline"; - document.getElementById('new-play-par').style.display = "block"; - } - document.getElementById("working").style.display = "none"; +function make_move_continue (info) { + var listing_f = function (play) { + var old_li = document.getElementById ("plays-list-" + play.game + + "-elem-" + CUR_PLAY_I); + var li = new_play_item (play.game, CUR_PLAY_I); + old_li.parentNode.replaceChild (li, old_li); + }; + var suggest_f = function (time) { suggest_move_async (time, make_move) }; + PLAYS[CUR_PLAY_I].move_continue (info, listing_f, suggest_f, disp_name); } -// Helper function: highlight move, unhighlight old, save current. -function show_move (m) { - for (var i = 0; i < CUR_ELEMS.length; i++) { - ST.unhighlight_elem (CUR_ELEMS[i]); - } - for (var i = 0; i < m.matched.length; i++) { - ST.highlight_elem (m.matched[i]); - } - if (m.matched_str == "") { - document.getElementById('cur-move').innerHTML = "none"; - } else { - document.getElementById('cur-move').innerHTML = - m.matched_str.replace (/,/g, " — ") + " (" + m.rule + ")" - } - CUR_ELEMS = m.matched; - CUR_MOVE = m.def_str; -} -// Handler for clicks on elements. -function handle_elem_click (elem) { - if (ASYNC_ALL_REQ_PENDING != 0) { return; } - var moves = ST.get_moves (elem, LAST_CLICKED_ELEM); - if (moves.length == 0) { - LAST_CLICKED_ELEM = ""; - moves = ST.get_moves (elem, LAST_CLICKED_ELEM); - }; - if (moves.length == 0) { // still no moves, unhighlight - for (var i = 0; i < CUR_ELEMS.length; i++) { - ST.unhighlight_elem (CUR_ELEMS[i]); - } - CUR_ELEMS = []; - CUR_MOVE = ""; - LAST_CLICKED_ELEM = ""; - } else if (moves.length == 1) { - show_move (moves[0]); - ELEM_COUNTERS[elem] = 1; - if (SIMPLE_MOVES) { make_move (); }; - } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast - && moves.length == 2 && moves[0].length > moves[1].length) { - show_move (moves[1]); - ELEM_COUNTERS[elem] = 2; - if (SIMPLE_MOVES) { make_move (); }; - } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast - && moves.length == 2 && moves[1].length > moves[0].length) { - show_move (moves[0]); - ELEM_COUNTERS[elem] = 1; - if (SIMPLE_MOVES) { make_move (); }; - } else if (moves.length > ELEM_COUNTERS[elem]) { - show_move (moves[ELEM_COUNTERS[elem]]); - ELEM_COUNTERS[elem] += 1; - } else if (moves.length > 0) { - show_move (moves[0]); - ELEM_COUNTERS[elem] = 1; - }; - if (moves.length > 1 && LAST_CLICKED_ELEM == "") { - for (var i = 0; i < CUR_ELEMS.length; i++) { - ST.unhighlight_elem (CUR_ELEMS[i]); - } - document.getElementById('cur-move').innerHTML = elem + " — ?" - ST.highlight_elem (elem); - CUR_ELEMS = [elem]; - CUR_MOVE = ""; - }; - LAST_CLICKED_ELEM = elem; +function play_from_string (game, s) { + var d = game.length + 2; + var p = s.substring(s.lastIndexOf('/') + d); + var lst = convert_python_list ('_', p); + return (new Play (game, [0, 1], [lst[0], lst[1]], + lst[2], lst[3], lst[4], UNAME)); } -function play_py_id (i) { - return (PLAYS[i][2]) -} -function disp_name (uname) { - if (uname == "guest") { return ("You"); } - if (UNAME_TO_NAME_MAP[uname]) { return (UNAME_TO_NAME_MAP[uname]); } - name = CONN.get_name (uname); - UNAME_TO_NAME_MAP[uname] = name; - return (name); -} +// Play lists on display. function new_play_item (game, i) { var li = document.createElement('li'); li.setAttribute ("class", "plays-list-elem"); li.setAttribute ("id", "plays-list-" + game + "-elem-" + i); - var p = PLAYS[i][2]; - var pname = disp_name(PLAYS[i][0]) +" vs " + disp_name(PLAYS[i][1]) + - " (game " + PLAYS[i][2] + ')'; - var bs = '<button class="obt" title="Open game ' + PLAYS[i][2] + - '" onclick="'+ "play_click('" + game + "', " + p + ", " + i + ')">' + - pname + '</button> '; + var pname = disp_name(PLAYS[i].players[0]) +" vs " + + disp_name(PLAYS[i].players[1]) + " (game " + PLAYS[i].pid + ')'; + var bs = '<button class="obt" title="Open game ' + PLAYS[i].pid + + '" onclick="'+ "play_click('" + game + "', " + PLAYS[i].pid + ", " + + i + ')">' + pname + '</button> '; li.innerHTML = bs // +'<a href="#" onclick="'+ "del_play('"+ fn + "')" + '">Delete</a>'; return (li); @@ -180,10 +72,8 @@ PLAYS = convert_python_list ('#', lst); var plist = document.getElementById("plays-list-" + game); while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } - var d = game.length + 2; for (var i = 0; i < PLAYS.length; i++) { - var p = PLAYS[i].substring(PLAYS[i].lastIndexOf('/') + d); - PLAYS[i] = convert_python_list ('_', p); + PLAYS[i] = play_from_string (game, PLAYS[i]); plist.appendChild(new_play_item (game, i)); } if (PLAYS.length == 0) { @@ -212,45 +102,12 @@ document.getElementById ("game-title").innerHTML = game; document.getElementById("game-disp").style.display = "block"; document.getElementById("play-number").innerHTML = "" + play_id; - CUR_PLAY_I = pi; - if (game == "Connect4") { VIEW_MIRROR = 0; } else { - VIEW_MIRROR = (PLAYS[CUR_PLAY_I][0] == UNAME) ? 0 : 1; - } - var info = CONN.open_db (play_py_id (pi)); document.getElementById("suggestions-toggle").style.display = "inline"; - full_redraw (GAME_NAME, info); + CUR_PLAY_I = pi; + PLAYS[CUR_PLAY_I].redraw (disp_name); } -// Apply current move. -function make_move () { - if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } - if (CUR_MOVE == "") return; - var m = parseInt(CUR_MOVE.substring (0, 1)) - 1; - if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer" && PLAYS[CUR_PLAY_I][m] != UNAME.replace("_", "-")) { - alert ("It is your Opponent's move"); - return; - } - if (! SIMPLE_MOVES) { - document.getElementById("working").style.display = "block"; - } - CONN.make_move (CUR_MOVE, play_py_id (CUR_PLAY_I), make_move_continue); -} - -function make_move_continue (info) { - document.getElementById("working").style.display = "none"; - full_redraw (GAME_NAME, info); - var old_li = document.getElementById ("plays-list-" + GAME_NAME + - "-elem-" + CUR_PLAY_I); - var li = new_play_item (GAME_NAME, CUR_PLAY_I); - old_li.parentNode.replaceChild (li, old_li); - if (ST.players.length==1 && PLAYS[CUR_PLAY_I][ST.players[0]]=="computer") { - var mv_time = document.getElementById("speed").value; - suggest_move_async (mv_time, make_move); - } -} - - function del_play (play) { alert ("Deleting " + play); } @@ -260,7 +117,7 @@ li.setAttribute ("class", "opponents-list-elem"); li.setAttribute ("id", "opponent-" + uid); // + "-" + index li.innerHTML = - '<button class="dbt" onclick="new_play_do('+ "'" + uid + "', 0"+ ')">'+ + '<button class="dbt" onclick="new_play_do(' + "'" + uid + "'" + ')">'+ disp_name(uid) + ' (' + uid + ') </button>'; return (li); } @@ -282,7 +139,7 @@ var zeroli = document.createElement('li'); zeroli.setAttribute ("class", "opponents-list-elem"); zeroli.setAttribute ("id", "opponent-" + "-0"); - zeroli.innerHTML = '<button class="dbt" onclick="new_play_do(-1, 0)">' + + zeroli.innerHTML = '<button class="dbt" onclick="new_play_do(-1)">' + 'Play against Yourself</button>'; o.appendChild (zeroli); for (var i = 0; i < FRIENDS.length; i++) { @@ -333,13 +190,6 @@ } } -function svg_string () { - var svg_el = document.getElementById ("svg"); - var svg_s = (new XMLSerializer()).serializeToString(svg_el); - svg_s = svg_s.replace(/onclick="[^\"]*"/g, ""); - return ("'''" + svg_s + "'''"); -} - function show_chess_warning () { document.getElementById("chess-level-warning").style.display = "block"; } @@ -371,10 +221,10 @@ show_chess_warning (); setTimeout("hide_chess_warning ()", 3000); } - new_play_do ("computer", 0); + new_play_do ("computer"); } -function new_play_do (opp_uid, vm) { +function new_play_do (opp_uid) { list_plays (GAME_NAME); document.getElementById("welcome").style.display = "none"; document.getElementById("game-disp").style.display = "none"; @@ -397,12 +247,12 @@ FREE_PLAY_NO = parseInt(info_nbr.substring(0, info_idx)); document.getElementById("play-number").innerHTML = "" + FREE_PLAY_NO; CUR_PLAY_I = PLAYS.length; - VIEW_MIRROR = vm; document.getElementById("game-disp").style.display = "block"; document.getElementById("plays").style.left = "30em"; - var p = [UNAME, opp_uid, FREE_PLAY_NO]; + var p = new Play (GAME_NAME, [0,1], [UNAME, opp_uid], FREE_PLAY_NO, 0, + info_nbr.substring(info_idx+1), UNAME); PLAYS.push(p); - full_redraw (GAME_NAME, info_nbr.substring(info_idx+1)); + p.redraw (disp_name); li = new_play_item (GAME_NAME, CUR_PLAY_I); document.getElementById("plays-list-" + GAME_NAME).appendChild(li); } @@ -421,19 +271,24 @@ }; toggle_suggestions (); toggle_suggestions (); - clear_svg (); + PLAYS[CUR_PLAY_I].clear (); + document.getElementById('cur-move').innerHTML = "none"; if (me_starts) { - var opp = PLAYS[CUR_PLAY_I][1]; - if (PLAYS[CUR_PLAY_I][0] != UNAME) { opp = PLAYS[CUR_PLAY_I][0]; } - new_play_do (opp, 0); + var opp = PLAYS[CUR_PLAY_I].players[1]; + if (PLAYS[CUR_PLAY_I].players[0] != UNAME) { + opp = PLAYS[CUR_PLAY_I].players[0]; + } + new_play_do (opp); } else { - var opp = PLAYS[CUR_PLAY_I][1]; - if (PLAYS[CUR_PLAY_I][0] != UNAME) { opp = PLAYS[CUR_PLAY_I][0]; } + var opp = PLAYS[CUR_PLAY_I].players[1]; + if (PLAYS[CUR_PLAY_I].players[0] != UNAME) { + opp = PLAYS[CUR_PLAY_I].players[0]; + } var me = UNAME; UNAME = opp; - var vm = (GAME_NAME == "Connect4") ? 0 : 1; - new_play_do (me, vm); + new_play_do (me); UNAME = me; + PLAYS[CUR_PLAY_I].cur_player_uid = UNAME; if (opp == "computer") { var mv_time = document.getElementById("speed").value; suggest_move_async (mv_time, make_move); @@ -461,9 +316,10 @@ var fm = function (m) { document.getElementById("working").style.display = "none"; document.getElementById("working").innerHTML = "Working..."; - if (m != "") { show_move (new Move (m)); f() } + if (m != "") { PLAYS[CUR_PLAY_I].show_move (new Move (m)); f() } }; - CONN.suggest (ST.players[0]+1, time, play_py_id (CUR_PLAY_I), fm); + CONN.suggest (PLAYS[CUR_PLAY_I].cur_state.players[0]+1, time, + PLAYS[CUR_PLAY_I].pid, fm); } function suggest_move_click () { Added: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js (rev 0) +++ trunk/Toss/WebClient/Play.js 2011-06-16 17:34:11 UTC (rev 1485) @@ -0,0 +1,197 @@ +// JavaScript Toss Module -- Play (requires Connect.js, State.js) + +var SIMPLE_MOVES = true; + + +// --------- Play Object with Methods -------------- + +// Create a new play, set player names, pid, move and state. +function Play (game, game_players, player_names, pid, move, state_str, uid) { + this.cur_player_uid = uid; + this.game = game; + this.players = {}; + for (var i = 0; i < game_players.length; i++) { + this.players[game_players[i]] = player_names[i]; + } + this.pid = pid; + this.move_nbr = move; + var mirror = 0; + if (game == "Connect4") { mirror = 0; } else { + mirror = (player_names[0] == this.cur_player_uid) ? 0 : 1; + } + this.cur_state = new State (game, state_str, mirror); + + this.ELEM_COUNTERS = {}; + this.CUR_MOVE = ""; + this.CUR_ELEMS = []; + this.LAST_CLICKED_ELEM = ""; + + return (this); +} + +function play_new_state (state_str) { + this.cur_state = new State (this.game, state_str, this.cur_state.mirror); + this.move_nbr = this.move_nbr + 1; +} +Play.prototype.new_state = play_new_state; + +function play_clear () { + this.LAST_CLICKED_ELEM = ""; + this.ELEM_COUNTERS = {}; + this.CUR_MOVE = ""; + this.CUR_ELEMS = []; +} +Play.prototype.clear = play_clear; + +// Full redraw. +function play_redraw (f_disp_name) { + this.clear (); + document.getElementById('cur-move').innerHTML = "none"; + this.cur_state.draw_model (this.game); + + // Functions to substitute players for 0 and 1 in a payoff string. + var win_s = function (pl, un) { + if (pl == un) { return ("You Win!"); } + return (f_disp_name(pl) + " Wins"); + } + var subst_pl = function (pl, str) { + var un = pl.cur_player_uid; + var s = strip (' ', '\n', str); + if (s == "0: 1., 1: -1.") { return (win_s (pl.players[0], un)); } + if (s == "0: -1., 1: 1.") { return (win_s (pl.players[1], un)); } + if (s == "0: 0., 1: 0.") { return ("Tie"); } + var s1 = s.replace (/0:/g, f_disp_name(pl.players[0]) + ":"); + var s2 = s1.replace (/1:/g, f_disp_name(pl.players[1]) + ":"); + var s3 = s2.replace (/1.,/g, "1,"); + var s4 = s3.replace (/0.,/g, "0,"); + var s5 = s4.replace (/1.$/g, "1"); + return (s5.replace (/0.$/g, "0")); + } + + if (! SIMPLE_MOVES) { + document.getElementById("working").style.display = "block"; + } + for (var i = 0; i < this.cur_state.elems.length; i++) { + this.ELEM_COUNTERS[this.cur_state.elems[i].id] = 0; + } + if (this.cur_state.payoff == "") { + document.getElementById('movebt').innerHTML = "Make move:"; + document.getElementById('cur-move').innerHTML = "none"; + } else { + if (SIMPLE_MOVES) { + document.getElementById("board").style.paddingTop = "0em"; + } + document.getElementById("move-info-par").style.display = "none"; + document.getElementById("game-info-par").style.paddingBottom = "0em"; + document.getElementById('payoffs').innerHTML = + "Result: " + subst_pl(this, this.cur_state.payoff); + document.getElementById('payoffs').style.display = "inline"; + document.getElementById('new-play-par').style.display = "block"; + } + document.getElementById("working").style.display = "none"; +} +Play.prototype.redraw = play_redraw; + + +// Helper function: highlight move, unhighlight old, save current. +function play_show_move (m) { + for (var i = 0; i < this.CUR_ELEMS.length; i++) { + this.cur_state.unhighlight_elem (this.CUR_ELEMS[i]); + } + for (var i = 0; i < m.matched.length; i++) { + this.cur_state.highlight_elem (m.matched[i]); + } + if (m.matched_str == "") { + document.getElementById('cur-move').innerHTML = "none"; + } else { + document.getElementById('cur-move').innerHTML = + m.matched_str.replace (/,/g, " — ") + " (" + m.rule + ")" + } + this.CUR_ELEMS = m.matched; + this.CUR_MOVE = m.def_str; +} +Play.prototype.show_move = play_show_move; + + +// Handler for clicks on elements in a play. +function play_handle_click (elem) { + if (ASYNC_ALL_REQ_PENDING != 0) { return; } + var moves = this.cur_state.get_moves (elem, this.LAST_CLICKED_ELEM); + if (moves.length == 0) { + this.LAST_CLICKED_ELEM = ""; + moves = this.cur_state.get_moves (elem, this.LAST_CLICKED_ELEM); + }; + if (moves.length == 0) { // still no moves, unhighlight + for (var i = 0; i < this.CUR_ELEMS.length; i++) { + this.cur_state.unhighlight_elem (this.CUR_ELEMS[i]); + } + this.CUR_ELEMS = []; + this.CUR_MOVE = ""; + this.LAST_CLICKED_ELEM = ""; + } else if (moves.length == 1) { + this.show_move (moves[0]); + this.ELEM_COUNTERS[elem] = 1; + if (SIMPLE_MOVES) { this.move (); }; + } else if (this.LAST_CLICKED_ELEM != "" && this.LAST_CLICKED_ELEM != elem + && moves.length == 2 && moves[0].length > moves[1].length) { + //move fast + this.show_move (moves[1]); + this.ELEM_COUNTERS[elem] = 2; + if (SIMPLE_MOVES) { this.move (); }; + } else if (this.LAST_CLICKED_ELEM != "" && this.LAST_CLICKED_ELEM != elem + && moves.length == 2 && moves[1].length > moves[0].length) { + //move fast + this.show_move (moves[0]); + this.ELEM_COUNTERS[elem] = 1; + if (SIMPLE_MOVES) { this.move (); }; + } else if (moves.length > this.ELEM_COUNTERS[elem]) { + this.show_move (moves[this.ELEM_COUNTERS[elem]]); + this.ELEM_COUNTERS[elem] += 1; + } else if (moves.length > 0) { + this.show_move (moves[0]); + this.ELEM_COUNTERS[elem] = 1; + }; + if (moves.length > 1 && this.LAST_CLICKED_ELEM == "") { + for (var i = 0; i < this.CUR_ELEMS.length; i++) { + this.cur_state.unhighlight_elem (this.CUR_ELEMS[i]); + } + document.getElementById('cur-move').innerHTML = elem + " — ?" + this.cur_state.highlight_elem (elem); + this.CUR_ELEMS = [elem]; + this.CUR_MOVE = ""; + }; + this.LAST_CLICKED_ELEM = elem; +} +Play.prototype.handle_click = play_handle_click; + + +// Apply the current move in a play. +function play_move () { + if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } + if (this.CUR_MOVE == "") return; + var m = parseInt(this.CUR_MOVE.substring (0, 1)) - 1; + if (!isNaN(m) && this.players[m] != this.cur_player_uid && + this.players[m] != "computer" && + this.players[m] != this.cur_player_uid.replace("_", "-")) { + alert ("It is your Opponent's move"); + return; + } + if (! SIMPLE_MOVES) { + document.getElementById("working").style.display = "block"; + } + CONN.make_move (this.CUR_MOVE, this.pid, make_move_continue); +} +Play.prototype.move = play_move; + +function play_move_continue (info, listing_redraw_f, suggest_f, name_f) { + document.getElementById("working").style.display = "none"; + this.new_state (info); + this.redraw (name_f); + listing_redraw_f (this); + if (this.cur_state.players.length == 1 && + this.players[this.cur_state.players[0]] == "computer") { + var mv_time = document.getElementById("speed").value; + suggest_f (mv_time); + } +} +Play.prototype.move_continue = play_move_continue; Modified: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-06-16 07:21:00 UTC (rev 1484) +++ trunk/Toss/WebClient/State.js 2011-06-16 17:34:11 UTC (rev 1485) @@ -4,7 +4,6 @@ var SVG_HEIGHT = 500; var SVG_MARGINX = 50; var SVG_MARGINY = 50; -var VIEW_MIRROR = 0; // ------ Move Object ----- @@ -57,19 +56,22 @@ // Object representing a state of the system (game). -function State (game, info_string) { +function State (game, info_string, mirror) { // We create an SVG box with margins depending on the game. this.game = game; + this.mirror = mirror; var create_svg_box = function (margx, margy, parent_id) { + var svg_e = document.getElementById("svg"); + if (svg_e != null) { svg_e.parentNode.removeChild (svg_e); } + var svg = document.createElementNS('http://www.w3.org/2000/svg','svg'); + svg.setAttribute('id', 'svg'); + document.getElementById(parent_id).appendChild(svg); SVG_MARGINX = margx; SVG_MARGINY = margx; - var svg = document.createElementNS('http://www.w3.org/2000/svg','svg'); - svg.setAttribute('id', 'svg'); var wx = SVG_WIDTH + 2*SVG_MARGINX + 20; var wy = SVG_HEIGHT + 2*SVG_MARGINY + 20; svg.setAttribute('viewBox', '-10 -10 ' + wx + " " + wy); - document.getElementById(parent_id).appendChild(svg); } if (game == "Tic-Tac-Toe" || game == "Concurrent-Tic-Tac-Toe") { @@ -79,9 +81,9 @@ } // Private: Translate position from Model coordinates to SVG coordinates. - var translate_pos = function (pos, minx, miny, width, height) { + var translate_pos = function (pos, minx, miny, width, height, mirror_a) { var x = ((pos[0] - minx) * SVG_WIDTH) / width; - if (VIEW_MIRROR == 0) { + if (mirror_a == 0) { var y = ((pos[1] - miny) * SVG_HEIGHT) / height; } else { var y = ((height - (pos[1] - miny))*SVG_WIDTH) / height; @@ -109,7 +111,8 @@ for (var i = 0; i < l.length; i++) { var e = convert_python_list (';', l[i]); var pos = translate_pos ([parseFloat(e[1]), parseFloat(e[2])], - this.minx, this.miny, this.width, this.height); + this.minx, this.miny, + this.width, this.height, this.mirror); this.elems.push (new Elem (e[0], pos[0], pos[1])); } @@ -132,7 +135,8 @@ args[j] = find_elem (args[j], this.elems); if (args[j] == undefined) { is_undefined = true }; } - if (rel_name[0] != "_" && args_s != "''" && is_undefined == false) { + if (rel_name[0] != "_" && rel_name[0] != "-" && + args_s != "''" && is_undefined == false) { rels.push (new Rel (rel_name, args)); } } Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-16 07:21:00 UTC (rev 1484) +++ trunk/Toss/WebClient/index.html 2011-06-16 17:34:11 UTC (rev 1485) @@ -12,6 +12,7 @@ <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> <script type="text/javascript" src="State.js"> </script> + <script type="text/javascript" src="Play.js"> </script> <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> </head> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-06-16 07:21:00 UTC (rev 1484) +++ trunk/Toss/WebClient/profile.html 2011-06-16 17:34:11 UTC (rev 1485) @@ -10,6 +10,7 @@ <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> <script type="text/javascript" src="State.js"> </script> + <script type="text/javascript" src="Play.js"> </script> <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> </head> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-16 07:21:09
|
Revision: 1484 http://toss.svn.sourceforge.net/toss/?rev=1484&view=rev Author: chalmi Date: 2011-06-16 07:21:00 +0000 (Thu, 16 Jun 2011) Log Message: ----------- sandbox: Chess colors solved Modified Paths: -------------- trunk/Toss/WebClient/msw.html Modified: trunk/Toss/WebClient/msw.html =================================================================== --- trunk/Toss/WebClient/msw.html 2011-06-15 20:32:00 UTC (rev 1483) +++ trunk/Toss/WebClient/msw.html 2011-06-16 07:21:00 UTC (rev 1484) @@ -15,6 +15,7 @@ <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> <script type="text/javascript" src="msw.js"></script> + <!--<script type="text/javascript" src="Model.js"></script>--> </head> <body> @@ -70,6 +71,7 @@ msw_plays(GAME_NAME); var info = CONN.open_db(PLAYS[CUR_PLAY_I][2]); document.getElementById("game-disp").style.display = "block"; + document.getElementById("game-disp").setAttribute ("class", "Game-" + GAME_NAME); full_redraw(GAME_NAME, info); //document.write(info); </script> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-15 20:32:08
|
Revision: 1483 http://toss.svn.sourceforge.net/toss/?rev=1483&view=rev Author: lukaszkaiser Date: 2011-06-15 20:32:00 +0000 (Wed, 15 Jun 2011) Log Message: ----------- Small stability and debugging improvements. Modified Paths: -------------- trunk/Toss/GGP/Makefile trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/ServerGDLTest.in2 trunk/Toss/WebClient/Main.js Modified: trunk/Toss/GGP/Makefile =================================================================== --- trunk/Toss/GGP/Makefile 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/GGP/Makefile 2011-06-15 20:32:00 UTC (rev 1483) @@ -9,13 +9,13 @@ %.black: examples/%.gdl make -C .. - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -d 2 & + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -nocache -d 1 & java -jar gamecontroller-cli.jar play $< 600 10 1 -random 1 -remote 2 toss localhost 8110 1 | grep results killall -v TossServer %.white: examples/%.gdl make -C .. - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -d 2 & + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -nocache -d 1 & java -jar gamecontroller-cli.jar play $< 600 10 1 -random 2 -remote 1 toss localhost 8110 1 | grep results killall -v TossServer Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-15 20:32:00 UTC (rev 1483) @@ -455,7 +455,10 @@ | x when x > 1 -> failwith ("passwd from db: multiple entries for " ^ uid) | _ -> let r = List.hd res in (* r = (uid,_,_,_,pwd) *) Some (r.(4)) in let get_user_name_surname_mail uid = - let res = dbtable ("id='" ^ uid ^ "'") "users" in + let res0 = dbtable ("id='" ^ uid ^ "'") "users" in + let res = if res0 = [] then + dbtable ("id='" ^ (str_replace "-" "_" uid) ^ "'") "users" + else res0 in match List.length res with | 0 -> ("", "", "") | x when x > 1 -> failwith ("get_user_name: multiple entries for " ^ uid) @@ -470,8 +473,10 @@ let list_plays game pl_id = let or_s = "(player1='" ^ pl_id ^ "' or player2='" ^ pl_id ^ "')" in let plays = dbtable ("game='" ^ game ^ "' and " ^ or_s) "cur_states" in + let rpl s = str_replace "_" "-" s in let play_name p = (* p = (pid, g, p1, p2, move, _, _, _, _) *) - "/" ^ p.(1) ^ "_" ^ p.(2) ^ "_" ^ p.(3) ^ "_" ^ p.(0) ^ "_" ^ p.(4) ^ "_" ^ p.(7) in + "/" ^ (rpl p.(1)) ^ "_" ^ (rpl p.(2)) ^ "_" ^ (rpl p.(3)) ^ "_" ^ + (rpl p.(0)) ^ "_" ^ (rpl p.(4)) ^ "_" ^ (rpl p.(7)) in lstr ~sep:"#" (List.map play_name plays) in let user_plays uid = let (name, _, _) = get_user_name_surname_mail uid in @@ -673,45 +678,48 @@ else try Aux.Left (req_handle rstate (Aux.Right (GDLParser.parse_request KIFLexer.lex (Lexing.from_string msg)))) - with Parsing.Parse_error | Lexer.Parsing_error _ -> - Aux.Right (rstate, fun () -> handle_http_post cmd head msg ck) + with Parsing.Parse_error | Lexer.Parsing_error _ | + Failure "lexing: empty token" -> + print_endline (head ^ "\n" ^ cmd); + Aux.Right (rstate, fun () -> handle_http_post cmd head msg ck) + - - (* ------- Full Request Handler (both Html and Generic Toss) ------- *) let rec read_in_line in_ch = let line_in = let rec nonempty () = let line_in = input_line in_ch in - if line_in = "" || line_in = "\r" then nonempty () + if line_in = "" || line_in = "\r" then + try nonempty () with End_of_file -> "" else line_in in nonempty () in let line_in_len = String.length line_in in + if line_in_len = 0 then ("", None) else (* TODO: who needs escaping? *) - let line_in = - if line_in.[line_in_len-1] <> '\r' then + let line_in = + if line_in.[line_in_len-1] <> '\r' then (* String.escaped *) line_in - else + else (* String.escaped *) (String.sub line_in 0 (line_in_len-1)) in - match Aux.input_if_http_message line_in in_ch with - | Some (head, msg, cookies) -> - if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" msg; - let ck = List.map (fun (k, v) -> (strip_ws k, strip_ws v)) cookies in - ("HTTP", Some (Aux.Left (line_in, head, msg, ck))) - | None -> - if line_in = "COMP" then - let res = Marshal.from_channel in_ch in - if !debug_level > 0 then Printf.printf "COMP, %!"; - ("COMP", Some (Aux.Right res)) - else - (* We put endlines, encoded by '$', back into the message. - TODO: perhaps a "better" solution now that HTTP has one? *) - let line = - String.concat "\n" - (Str.split (Str.regexp "\\$") line_in) in - if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" line; - (line, None) + match Aux.input_if_http_message line_in in_ch with + | Some (head, msg, cookies) -> + if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" msg; + let ck = List.map (fun (k, v) -> (strip_ws k, strip_ws v)) cookies in + ("HTTP", Some (Aux.Left (line_in, head, msg, ck))) + | None -> + if line_in = "COMP" then + let res = Marshal.from_channel in_ch in + if !debug_level > 0 then Printf.printf "COMP, %!"; + ("COMP", Some (Aux.Right res)) + else + (* We put endlines, encoded by '$', back into the message. + TODO: perhaps a "better" solution now that HTTP has one? *) + let line = + String.concat "\n" + (Str.split (Str.regexp "\\$") line_in) in + if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" line; + (line, None) let full_req_handle rstate in_ch out_ch = @@ -727,6 +735,7 @@ flush out_ch; (new_rstate, continue) in match read_in_line in_ch with + | ("", None) -> print_endline "Empty line."; (rstate, true) | (line, Some (Aux.Right (f, x))) when line = "COMP" -> (match Unix.fork () with | 0 (* child *) -> Modified: trunk/Toss/Server/ServerGDLTest.in2 =================================================================== --- trunk/Toss/Server/ServerGDLTest.in2 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/Server/ServerGDLTest.in2 2011-06-15 20:32:00 UTC (rev 1483) @@ -50,4 +50,4 @@ Content-type: text/acl Content-length: 41 -(STOP MATCH.3316980891 (NOOP (MARK 3 2))) +(STOP MATCH.3316980891 (NOOP (MARK 3 2))) \ No newline at end of file Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/WebClient/Main.js 2011-06-15 20:32:00 UTC (rev 1483) @@ -227,7 +227,7 @@ if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } if (CUR_MOVE == "") return; var m = parseInt(CUR_MOVE.substring (0, 1)) - 1; - if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { + if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer" && PLAYS[CUR_PLAY_I][m] != UNAME.replace("_", "-")) { alert ("It is your Opponent's move"); return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-14 07:07:38
|
Revision: 1482 http://toss.svn.sourceforge.net/toss/?rev=1482&view=rev Author: chalmi Date: 2011-06-14 07:07:32 +0000 (Tue, 14 Jun 2011) Log Message: ----------- Play pre model Tic-Tac-Toe -> ok, Chess -> colors problem Modified Paths: -------------- trunk/Toss/WebClient/msw.html Modified: trunk/Toss/WebClient/msw.html =================================================================== --- trunk/Toss/WebClient/msw.html 2011-06-13 07:21:40 UTC (rev 1481) +++ trunk/Toss/WebClient/msw.html 2011-06-14 07:07:32 UTC (rev 1482) @@ -65,11 +65,12 @@ <script type="text/javascript"> UNAME = "michal"; - CUR_PLAY_I = 4; - msw_plays("Tic-Tac-Toe"); + CUR_PLAY_I = 0; + GAME_NAME = "Chess"; + msw_plays(GAME_NAME); var info = CONN.open_db(PLAYS[CUR_PLAY_I][2]); document.getElementById("game-disp").style.display = "block"; - full_redraw("Tic-Tac-Toe", info); + full_redraw(GAME_NAME, info); //document.write(info); </script> </body> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-13 07:21:48
|
Revision: 1481 http://toss.svn.sourceforge.net/toss/?rev=1481&view=rev Author: chalmi Date: 2011-06-13 07:21:40 +0000 (Mon, 13 Jun 2011) Log Message: ----------- msw: Play premodel working with errors Modified Paths: -------------- trunk/Toss/WebClient/msw.html trunk/Toss/WebClient/msw.js Modified: trunk/Toss/WebClient/msw.html =================================================================== --- trunk/Toss/WebClient/msw.html 2011-06-13 05:51:18 UTC (rev 1480) +++ trunk/Toss/WebClient/msw.html 2011-06-13 07:21:40 UTC (rev 1481) @@ -20,6 +20,20 @@ <body> <div id="main"> +<span id="topright"> + Speed: <select id="speed"> + <option class="speed_val" value="1">1s</option> + <option class="speed_val" value="2">2s</option> + <option class="speed_val" value="3">3s</option> + <option class="speed_val" value="4">4s</option> + <option class="speed_val" value="5">5s</option> + <option class="speed_val" value="10">10s</option> + <option class="speed_val" value="15">15s</option> + <option class="speed_val" value="30">30s</option> + <option class="speed_val" value="60">60s</option> + </select> + <button id="logoutbt" onclick="logout()">Logout</button> +</span> <div id="game-disp"> <p id="game-info-par"> <span id="game-title"></span> @@ -51,7 +65,7 @@ <script type="text/javascript"> UNAME = "michal"; - CUR_PLAY_I = 2; + CUR_PLAY_I = 4; msw_plays("Tic-Tac-Toe"); var info = CONN.open_db(PLAYS[CUR_PLAY_I][2]); document.getElementById("game-disp").style.display = "block"; Modified: trunk/Toss/WebClient/msw.js =================================================================== --- trunk/Toss/WebClient/msw.js 2011-06-13 05:51:18 UTC (rev 1480) +++ trunk/Toss/WebClient/msw.js 2011-06-13 07:21:40 UTC (rev 1481) @@ -19,3 +19,153 @@ var lst = CONN.list_plays (game, UNAME); msw_list_plays_string (game, lst); } + +function msw_make_move_continue (info) { + document.getElementById("working").style.display = "none"; + full_redraw (GAME_NAME, info); + //var old_li = document.getElementById ("plays-list-" + GAME_NAME + + // "-elem-" + CUR_PLAY_I); + //var li = new_play_item (GAME_NAME, CUR_PLAY_I); + //old_li.parentNode.replaceChild (li, old_li); + if (ST.players.length==1 && PLAYS[CUR_PLAY_I][ST.players[0]]=="computer") { + var mv_time = document.getElementById("speed").value; + suggest_move_async (mv_time, msw_make_move); + } +} + +function msw_state_draw_model (game) { + var draw_background = function (game) { + var x = SVG_MARGINX; + var y = SVG_MARGINY; + var w = SVG_WIDTH + 2 * x; + var h = SVG_HEIGHT + 2 * x; + var bg = SHAPES.background_svg (game, 0, 0, w, h, []); + if (bg != undefined) {document.getElementById("svg").appendChild(bg);} + } + + // Draw the element [elem]. + var draw_elem = function (game, elem) { + if (game != "Connect4") { + var r = SHAPES.rect ( + elem.x, elem.y, 2 * SHAPES.elem_size_x, 2 * SHAPES.elem_size_y, + [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], + ["onclick", ("msw_handle_elem_click('" + elem.id + "')")]]); + document.getElementById("svg").appendChild(r); + } else { + var circ = SHAPES.circle ( + elem.x, elem.y, 30, + [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], + ["onclick", "msw_handle_elem_click('" + elem.id + "')"]]); + document.getElementById("svg").appendChild(circ); + } + } + + + // Draw relation [rel_name] between elements [args]. + function draw_rel (game, rel) { + if (rel.args.length == 1) { + var ihatrs = [["id", "pred_" + rel.args[0].id + "_" + rel.name], + ["onclick","msw_handle_elem_click('"+rel.args[0].id+"')"]] + var pos = [rel.args[0].x, rel.args[0].y]; + var f = SHAPES.rel_svg (game, pos[0],pos[1],20,20, rel.name,ihatrs); + if (f != undefined) { + document.getElementById("svg").appendChild(f); + } else { + var circ = SHAPES.circle ( + pos[0], pos[1], SHAPES.elem_size_x - 10, + [["id", "pred_" + rel.args[0].id + "_" + rel.name], + ["class", "model-pred-" + rel.name], + ["stroke-width", (SHAPES.elem_size_x / 10) + 2], + ["onclick", ("msw_handle_elem_click('"+rel.args[0].id+"')")]]); + document.getElementById("svg").appendChild(circ); + } + } + if (rel.args.length == 2) { + if (rel.name == "E") { + var l = SHAPES.line (rel.args[0].x, rel.args[0].y, + rel.args[1].x, rel.args[1].y, + [["class", "model-edge-E"]]); + document.getElementById("svg").appendChild(l); + } + } + } + + // Main draw_model function. + var sqrt = Math.round (Math.sqrt (this.elems.length)); + if (sqrt * sqrt == this.elems.length) { // perhaps a grid + SHAPES.elem_size_x = SVG_WIDTH / (2.0 * (sqrt-1)); + SHAPES.elem_size_y = SVG_HEIGHT / (2.0 * (sqrt-1)); + } else { + SHAPES.elem_size_x = SVG_WIDTH / 20; + SHAPES.elem_size_y = SVG_HEIGHT / 20; + } + draw_background (game); + for (var i = 0; i < this.elems.length; i++) { + draw_elem (game, this.elems[i]); + } + for (var i = 0; i < this.rels.length; i++) { + draw_rel (game, this.rels[i]); + } +} +State.prototype.draw_model = msw_state_draw_model; + +function msw_handle_elem_click (elem) { + if (ASYNC_ALL_REQ_PENDING != 0) { return; } + var moves = ST.get_moves (elem, LAST_CLICKED_ELEM); + if (moves.length == 0) { + LAST_CLICKED_ELEM = ""; + moves = ST.get_moves (elem, LAST_CLICKED_ELEM); + }; + if (moves.length == 0) { // still no moves, unhighlight + for (var i = 0; i < CUR_ELEMS.length; i++) { + ST.unhighlight_elem (CUR_ELEMS[i]); + } + CUR_ELEMS = []; + CUR_MOVE = ""; + LAST_CLICKED_ELEM = ""; + } else if (moves.length == 1) { + show_move (moves[0]); + ELEM_COUNTERS[elem] = 1; + if (SIMPLE_MOVES) { msw_make_move (); }; + } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast + && moves.length == 2 && moves[0].length > moves[1].length) { + show_move (moves[1]); + ELEM_COUNTERS[elem] = 2; + if (SIMPLE_MOVES) { msw_make_move (); }; + } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast + && moves.length == 2 && moves[1].length > moves[0].length) { + show_move (moves[0]); + ELEM_COUNTERS[elem] = 1; + if (SIMPLE_MOVES) { msw_make_move (); }; + } else if (moves.length > ELEM_COUNTERS[elem]) { + show_move (moves[ELEM_COUNTERS[elem]]); + ELEM_COUNTERS[elem] += 1; + } else if (moves.length > 0) { + show_move (moves[0]); + ELEM_COUNTERS[elem] = 1; + }; + if (moves.length > 1 && LAST_CLICKED_ELEM == "") { + for (var i = 0; i < CUR_ELEMS.length; i++) { + ST.unhighlight_elem (CUR_ELEMS[i]); + } + document.getElementById('cur-move').innerHTML = elem + " — ?" + ST.highlight_elem (elem); + CUR_ELEMS = [elem]; + CUR_MOVE = ""; + }; + LAST_CLICKED_ELEM = elem; +} + +function msw_make_move () { + if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } + if (CUR_MOVE == "") return; + var m = parseInt(CUR_MOVE.substring (0, 1)) - 1; + if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { + alert ("It is your Opponent's move"); + return; + } + if (! SIMPLE_MOVES) { + document.getElementById("working").style.display = "block"; + } + CONN.make_move (CUR_MOVE, play_py_id (CUR_PLAY_I), msw_make_move_continue); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-13 05:51:29
|
Revision: 1480 http://toss.svn.sourceforge.net/toss/?rev=1480&view=rev Author: chalmi Date: 2011-06-13 05:51:18 +0000 (Mon, 13 Jun 2011) Log Message: ----------- Msw's sandbox Added Paths: ----------- trunk/Toss/WebClient/msw.html trunk/Toss/WebClient/msw.js Added: trunk/Toss/WebClient/msw.html =================================================================== --- trunk/Toss/WebClient/msw.html (rev 0) +++ trunk/Toss/WebClient/msw.html 2011-06-13 05:51:18 UTC (rev 1480) @@ -0,0 +1,62 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> + <title>tPlay</title> + <meta name="Description" + content="Play the best strategic games online with a nice interface." /> + <meta http-equiv="X-UA-Compatible" content="chrome=1" /> + <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> + <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> + <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> + <script type="text/javascript" src="crypto-sha256.js"> </script> + <script type="text/javascript" src="Connect.js"> </script> + <script type="text/javascript" src="State.js"> </script> + <script type="text/javascript" src="Main.js"> </script> + <script type="text/javascript" src="Login.js"> </script> + <script type="text/javascript" src="msw.js"></script> +</head> + +<body> + +<div id="main"> +<div id="game-disp"> + <p id="game-info-par"> + <span id="game-title"></span> + <span id="play-nbr-info" style="display:none;"> + (game <span id="play-number">?</span>) + </span> + <span id="payoffs" style="display:none;">Not Finished Yet</span> + </p> + + <p id="new-play-par"> + <button id="new_game_me" class="bt" onclick="play_anew(true)"> + New Game (You Start) + </button> + <button id="new_game_opp" class="bt" onclick="play_anew(false)"> + New Game (Opponent Starts) + </button> + </p> + + <p id="move-info-par"> + <button id="movebt" class="bt" onclick="make_move ()">Make move:</button> + <span id="cur-move">none</span> + <button id="sugbt" class="bt" onclick="suggest_move_click()"> + Suggest + </button> + </p> + <div id="board"><div id="working">Working...</div></div> +</div> +</div> + +<script type="text/javascript"> + UNAME = "michal"; + CUR_PLAY_I = 2; + msw_plays("Tic-Tac-Toe"); + var info = CONN.open_db(PLAYS[CUR_PLAY_I][2]); + document.getElementById("game-disp").style.display = "block"; + full_redraw("Tic-Tac-Toe", info); + //document.write(info); +</script> +</body> +</html> Added: trunk/Toss/WebClient/msw.js =================================================================== --- trunk/Toss/WebClient/msw.js (rev 0) +++ trunk/Toss/WebClient/msw.js 2011-06-13 05:51:18 UTC (rev 1480) @@ -0,0 +1,21 @@ +function msw_list_plays_string (game, lst) { + PLAYS = convert_python_list ('#', lst); + //var plist = document.getElementById("plays-list-" + game); + //while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } + var d = game.length + 2; + for (var i = 0; i < PLAYS.length; i++) { + var p = PLAYS[i].substring(PLAYS[i].lastIndexOf('/') + d); + PLAYS[i] = convert_python_list ('_', p); + //plist.appendChild(new_play_item (game, i)); + } + /*if (PLAYS.length == 0) { + document.getElementById("plays-list-" + game).style.display = "none"; + } else { + document.getElementById("plays-list-" + game).style.display = "block"; + }*/ +} + +function msw_plays (game) { + var lst = CONN.list_plays (game, UNAME); + msw_list_plays_string (game, lst); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2011-06-12 11:08:49
|
Revision: 1479 http://toss.svn.sourceforge.net/toss/?rev=1479&view=rev Author: chalmi Date: 2011-06-12 11:08:43 +0000 (Sun, 12 Jun 2011) Log Message: ----------- Msw's experiments Modified Paths: -------------- trunk/Toss/WebClient/Connect.js Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-11 13:38:53 UTC (rev 1478) +++ trunk/Toss/WebClient/Connect.js 2011-06-12 11:08:43 UTC (rev 1479) @@ -46,6 +46,8 @@ } return (resp) } + + this.s = sync_server_msg;//Just a copy of above for public usage // Send [msg] to server asynchronously, ignore response text. var async_server_msg = function (msg, count, f) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-11 13:39:01
|
Revision: 1478 http://toss.svn.sourceforge.net/toss/?rev=1478&view=rev Author: lukaszkaiser Date: 2011-06-11 13:38:53 +0000 (Sat, 11 Jun 2011) Log Message: ----------- Send play state data with play list. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-11 01:03:18 UTC (rev 1477) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-11 13:38:53 UTC (rev 1478) @@ -160,7 +160,7 @@ let client = ref init_state -let lstr l = "[" ^ (String.concat ", " l) ^ "]" +let lstr ?(sep=",") l = "[" ^ (String.concat sep l) ^ "]" let split_list ?(bound=None) pat s = let r = Str.regexp_string pat in @@ -471,13 +471,13 @@ let or_s = "(player1='" ^ pl_id ^ "' or player2='" ^ pl_id ^ "')" in let plays = dbtable ("game='" ^ game ^ "' and " ^ or_s) "cur_states" in let play_name p = (* p = (pid, g, p1, p2, move, _, _, _, _) *) - "/" ^ p.(1) ^ "_" ^ p.(2) ^ "_" ^ p.(3) ^ "_" ^ p.(0) ^ "_" ^ p.(4) in - lstr (List.map play_name plays) in + "/" ^ p.(1) ^ "_" ^ p.(2) ^ "_" ^ p.(3) ^ "_" ^ p.(0) ^ "_" ^ p.(4) ^ "_" ^ p.(7) in + lstr ~sep:"#" (List.map play_name plays) in let user_plays uid = let (name, _, _) = get_user_name_surname_mail uid in - let app_plays plays g = plays ^ "$" ^ (list_plays g uid) in + let app_plays plays g = plays ^ "@" ^ (list_plays g uid) in let plays = List.fold_left app_plays "" !DB.tGAMES in - uid ^ "$" ^ name ^ plays in + uid ^ "@" ^ name ^ plays in let get_free_id () = (DB.count_table dbFILE "cur_states") + 1 in let db_cur_insert game p1 p2 pid move toss loc info svg_str = DB.insert_table dbFILE "cur_states" Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-11 01:03:18 UTC (rev 1477) +++ trunk/Toss/WebClient/Login.js 2011-06-11 13:38:53 UTC (rev 1478) @@ -53,7 +53,7 @@ document.getElementById("nosvg").style.display = "block"; } else { var udata = CONN.plays (); - if (udata != "") { setup_user (udata.split("$")) }; + if (udata != "") { setup_user (udata.split("@")) }; } if (window.location.href.indexOf("?simple=true") > 0) { SIMPLE_SET = true; Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-11 01:03:18 UTC (rev 1477) +++ trunk/Toss/WebClient/Main.js 2011-06-11 13:38:53 UTC (rev 1478) @@ -177,7 +177,7 @@ } function list_plays_string (game, lst) { - PLAYS = convert_python_list (',', lst); + PLAYS = convert_python_list ('#', lst); var plist = document.getElementById("plays-list-" + game); while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } var d = game.length + 2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-11 01:03:24
|
Revision: 1477 http://toss.svn.sourceforge.net/toss/?rev=1477&view=rev Author: lukaszkaiser Date: 2011-06-11 01:03:18 +0000 (Sat, 11 Jun 2011) Log Message: ----------- Corrections to whitespace bugs. Modified Paths: -------------- trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Main.js Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-10 23:37:14 UTC (rev 1476) +++ trunk/Toss/WebClient/Connect.js 2011-06-11 01:03:18 UTC (rev 1477) @@ -20,8 +20,9 @@ // Convert a string [str] representing python list to array and return it. // WARNING: we use [sep] as separator, it must not occur in list elements! -function convert_python_list (sep, str) { +function convert_python_list (sep, str_in) { var res_arr = []; + var str = strip(' ', '\n', str_in); res_arr = strip('[', ']', str).split(sep); if (res_arr.length == 1 && res_arr[0] == "") { return ([]); } for (i = 0; i < res_arr.length; i++) { Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-10 23:37:14 UTC (rev 1476) +++ trunk/Toss/WebClient/Main.js 2011-06-11 01:03:18 UTC (rev 1477) @@ -42,7 +42,8 @@ } // Substitute players for 0 and 1 in a payoff string. -function subst_pl (s) { +function subst_pl (str) { + var s = strip (' ', '\n', str); if (s == "0: 1., 1: -1.") { return (win_s (0)); } if (s == "0: -1., 1: 1.") { return (win_s (1)); } if (s == "0: 0., 1: 0.") { return ("Tie"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-10 23:37:20
|
Revision: 1476 http://toss.svn.sourceforge.net/toss/?rev=1476&view=rev Author: lukaszkaiser Date: 2011-06-10 23:37:14 +0000 (Fri, 10 Jun 2011) Log Message: ----------- Small warning correction. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-06-10 23:29:58 UTC (rev 1475) +++ trunk/Toss/Arena/Arena.ml 2011-06-10 23:37:14 UTC (rev 1476) @@ -1003,7 +1003,7 @@ let can_modify_game = function - AddElem _ -> true + | AddElem _ -> true | AddRel _ -> true | DelElem _ -> true | DelRel _ -> true @@ -1049,5 +1049,6 @@ | SetTime _ -> false (* TODO: rethink when working on dyns *) | GetTime -> false | SetState _ -> true + | GetState -> false + | SetModel _ -> true | GetModel -> false - | GetState -> false This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-10 23:30:04
|
Revision: 1475 http://toss.svn.sourceforge.net/toss/?rev=1475&view=rev Author: lukaszkaiser Date: 2011-06-10 23:29:58 +0000 (Fri, 10 Jun 2011) Log Message: ----------- Small styling improvements. Modified Paths: -------------- trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-10 17:38:57 UTC (rev 1474) +++ trunk/Toss/WebClient/Style.css 2011-06-10 23:29:58 UTC (rev 1475) @@ -19,6 +19,27 @@ font-family: Verdana, 'TeXGyreHerosRegular', sans; } +#nosvg { + display: none; + position: fixed; + left: 0px; + right: 0px; + top: 5em; + min-width: 20em; + width: 60%; + margin-left: auto; + margin-right: auto; + color: #fff1d4; + background-color: #400827; + font-weight: bold; + padding: 2em; + border: 1px solid #260314; +} + +#nosvg a { + color: #f5f2ef; +} + .bt { border-color: #260314; border-radius: 4px; @@ -107,7 +128,6 @@ } .game-picspan { - display: none; position: absolute; top: 50%; left: 0px; @@ -497,6 +517,7 @@ list-style: none; padding-left: 1.5em; margin-top: 0.5em; + padding-bottom: 1em; } #opponents, #chess-level-warning { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-10 17:38:57 UTC (rev 1474) +++ trunk/Toss/WebClient/index.html 2011-06-10 23:29:58 UTC (rev 1475) @@ -173,8 +173,7 @@ </div> -<div id="nosvg" - style="border: 1px solid #260314; padding-left: 1em; display: none;"> +<div id="nosvg"> <p style="padding-left: 1.2em; font-size: 1.2em;"><b>SVG Support Missing</b></p> <p>Your browser does not seem to support SVG, which is <b>necessary</b> to enjoy tPlay. @@ -249,11 +248,12 @@ <ul class="plays-list" id="plays-list-Tic-Tac-Toe"> <li style="display: none;"/> </ul> - <p class="game-par"> + <p class="game-par" style="display: none;"> <button onclick="new_play('Concurrent-Tic-Tac-Toe')" class="boldobt">Concurrent-Tic-Tac-Toe</button> </p> - <ul class="plays-list" id="plays-list-Concurrent-Tic-Tac-Toe"> + <ul class="plays-list" style="display: none;" + id="plays-list-Concurrent-Tic-Tac-Toe"> <li style="display: none;"/> </ul> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |