X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=scribe%2Fscribe.jsx;h=78155949f782174a6ff40d2a80c7b5948f715868;hp=e7654b417eba2dfdc746a07d91f2a021de4bf2bb;hb=e7e45fef427d3d76f7f88ca919c73e28de5a301b;hpb=e52910fa1933db903b039a0f4f32b6470b3100d4 diff --git a/scribe/scribe.jsx b/scribe/scribe.jsx index e7654b4..7815594 100644 --- a/scribe/scribe.jsx +++ b/scribe/scribe.jsx @@ -1,8 +1,8 @@ function team_symbol(team) { if (team === "+") - return "🞥"; + return "+"; else - return "🞇"; + return "o"; } function undisplay(element) { @@ -26,7 +26,9 @@ const events = new EventSource("events"); events.onerror = function(event) { if (event.target.readyState === EventSource.CLOSED) { + setTimeout(() => { add_message("danger", "Connection to server lost."); + }, 1000); } }; @@ -77,14 +79,31 @@ events.addEventListener("game-state", event => { * Game and supporting classes * *********************************************************/ +function copy_to_clipboard(id) +{ + const tmp = document.createElement("input"); + tmp.setAttribute("value", document.getElementById(id).innerHTML); + document.body.appendChild(tmp); + tmp.select(); + document.execCommand("copy"); + document.body.removeChild(tmp); +} + function GameInfo(props) { if (! props.id) return null; return (
-

{props.id}

- Invite a friend to play by sending this URL: {props.url} + {props.id} + {" "} + Share this link to invite a friend:{" "} + {props.url} + {" "} +
); } @@ -130,7 +149,7 @@ function PlayerInfo(props) { return (
-

Players

+ Players: {props.player.name} {props.player.team ? ` (${props.player.team})` : ""} {props.first_move ? "" : " "} @@ -165,147 +184,59 @@ function Square(props) { ); } -class Board extends React.Component { - render_square(i,j) { - const value = this.props.squares[i][j]; +function MiniGrid(props) { + function grid_square(j) { + const value = props.squares[j]; return ( this.props.onClick(i,j)} + active={props.active} + onClick={() => props.onClick(j)} /> ); } - render() { - return ( -
-
- {this.render_square(0,0)} - {this.render_square(0,1)} - {this.render_square(0,2)} - {" "} - {this.render_square(1,0)} - {this.render_square(1,1)} - {this.render_square(1,2)} - {" "} - {this.render_square(2,0)} - {this.render_square(2,1)} - {this.render_square(2,2)} -
-
- {this.render_square(0,3)} - {this.render_square(0,4)} - {this.render_square(0,5)} - {" "} - {this.render_square(1,3)} - {this.render_square(1,4)} - {this.render_square(1,5)} - {" "} - {this.render_square(2,3)} - {this.render_square(2,4)} - {this.render_square(2,5)} -
-
- {this.render_square(0,6)} - {this.render_square(0,7)} - {this.render_square(0,8)} - {" "} - {this.render_square(1,6)} - {this.render_square(1,7)} - {this.render_square(1,8)} - {" "} - {this.render_square(2,6)} - {this.render_square(2,7)} - {this.render_square(2,8)} -
- -
-
- -
- {this.render_square(3,0)} - {this.render_square(3,1)} - {this.render_square(3,2)} - {" "} - {this.render_square(4,0)} - {this.render_square(4,1)} - {this.render_square(4,2)} - {" "} - {this.render_square(5,0)} - {this.render_square(5,1)} - {this.render_square(5,2)} -
-
- {this.render_square(3,3)} - {this.render_square(3,4)} - {this.render_square(3,5)} - {" "} - {this.render_square(4,3)} - {this.render_square(4,4)} - {this.render_square(4,5)} - {" "} - {this.render_square(5,3)} - {this.render_square(5,4)} - {this.render_square(5,5)} -
-
- {this.render_square(3,6)} - {this.render_square(3,7)} - {this.render_square(3,8)} - {" "} - {this.render_square(4,6)} - {this.render_square(4,7)} - {this.render_square(4,8)} - {" "} - {this.render_square(5,6)} - {this.render_square(5,7)} - {this.render_square(5,8)} -
+ return ( +
+ {grid_square(0)} + {grid_square(1)} + {grid_square(2)} + {grid_square(3)} + {grid_square(4)} + {grid_square(5)} + {grid_square(6)} + {grid_square(7)} + {grid_square(8)} +
+ ); +} -
-
+class Board extends React.Component { + mini_grid(i) { + const squares = this.props.squares[i]; + return ( + this.props.onClick(i,j)} + /> + ); + } -
- {this.render_square(6,0)} - {this.render_square(6,1)} - {this.render_square(6,2)} - {" "} - {this.render_square(7,0)} - {this.render_square(7,1)} - {this.render_square(7,2)} - {" "} - {this.render_square(8,0)} - {this.render_square(8,1)} - {this.render_square(8,2)} -
-
- {this.render_square(6,3)} - {this.render_square(6,4)} - {this.render_square(6,5)} - {" "} - {this.render_square(7,3)} - {this.render_square(7,4)} - {this.render_square(7,5)} - {" "} - {this.render_square(8,3)} - {this.render_square(8,4)} - {this.render_square(8,5)} -
-
- {this.render_square(6,6)} - {this.render_square(6,7)} - {this.render_square(6,8)} - {" "} - {this.render_square(7,6)} - {this.render_square(7,7)} - {this.render_square(7,8)} - {" "} - {this.render_square(8,6)} - {this.render_square(8,7)} - {this.render_square(8,8)} + render() { + return ( +
+
+ {this.mini_grid(0)} + {this.mini_grid(1)} + {this.mini_grid(2)} + {this.mini_grid(3)} + {this.mini_grid(4)} + {this.mini_grid(5)} + {this.mini_grid(6)} + {this.mini_grid(7)} + {this.mini_grid(8)}
-
); } @@ -337,7 +268,7 @@ class Game extends React.Component { game_info: {}, player_info: {}, other_players: [], - squares: Array(9).fill(null).map(() => Array(9).fill(null)), + squares: [...Array(9)].map(() => Array(9).fill(null)), moves: 0, next_to_play: "+" };