From dd38ed561568df70496fecea3eb0b01f5f0cc14e Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Fri, 7 Feb 2020 10:37:21 -0800 Subject: [PATCH] Adding game IDs and New/Join Game navigation. --- src/components/join-game/JoinGame.jsx | 28 ++++++++++++++++++++++----- src/components/new-game/NewGame.jsx | 20 +++++++++++++++++-- src/server/farm.scm | 27 ++++++++++++++++++-------- src/style.scss | 4 ++++ 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/components/join-game/JoinGame.jsx b/src/components/join-game/JoinGame.jsx index d9abfba..aeb010e 100644 --- a/src/components/join-game/JoinGame.jsx +++ b/src/components/join-game/JoinGame.jsx @@ -22,6 +22,10 @@ import { connect } from 'react-redux' import { GroupBox, Row, Col, Button } from '../widgets.jsx' import { startOrJoinGame } from '../start/actions.js' +import { start } from '../app/actions.js' + +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { faArrowCircleLeft } from '@fortawesome/free-solid-svg-icons' import NewGame from '../new-game/NewGame.jsx' @@ -43,18 +47,30 @@ class JoinGame extends React.Component { } handleBack = e => { - this.setState({ screen: JoinGameScreens.list }); + if (this.state.screen === JoinGameScreens.details) { + this.setState({ screen: JoinGameScreens.list }); + } else { + this.props.start(); + } } handleJoinAsExisting = e => { this.props.startOrJoinGame({ type: 'join-as-existing', playerName: e.target.text, + gameId: this.state.game.id, gameName: this.state.game.name }); } render() { return ( - + + + + + Join Game + + )}> {this.state.screen === JoinGameScreens.list ? @@ -65,8 +81,8 @@ class JoinGame extends React.Component { this.handleClickGame(g)}>{g.name} ))} ) - : ( -

back to games

+ : ( +

Game: {this.state.game.name}

Join as existing player:

    @@ -81,7 +97,9 @@ class JoinGame extends React.Component { button={'Join'} showGameName={false} gameName={this.state.game.name} + gameId={this.state.game.id} type={'join-game'} + hideBack={true} title={'Join as New Player'} /> )} @@ -93,5 +111,5 @@ class JoinGame extends React.Component { export default connect( state => state.start.start, - { startOrJoinGame } + { startOrJoinGame, start } )(JoinGame) diff --git a/src/components/new-game/NewGame.jsx b/src/components/new-game/NewGame.jsx index 0dc72be..259a1bc 100644 --- a/src/components/new-game/NewGame.jsx +++ b/src/components/new-game/NewGame.jsx @@ -22,6 +22,10 @@ import { connect } from 'react-redux' import { GroupBox, Row, Col, Button } from '../widgets.jsx' import { startOrJoinGame } from '../start/actions.js' +import { start } from '../app/actions.js' + +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { faArrowCircleLeft } from '@fortawesome/free-solid-svg-icons' class NewGame extends React.Component { constructor(props) { @@ -29,6 +33,7 @@ class NewGame extends React.Component { this.state = { playerName: '', checkedColor: props.colors[0], + gameId: typeof props.gameId === 'undefined' ? -1 : props.gameId, gameName: props.gameName || '' }; } @@ -48,10 +53,21 @@ class NewGame extends React.Component { this.props.startOrJoinGame(Object.assign({ type: this.props.type }, this.state)); } + handleBack = e => { + this.props.start(); + } + render() { let playerNameInput; return ( - + + + + + {this.props.title} + + ) : this.props.title}>
    @@ -100,5 +116,5 @@ class NewGame extends React.Component { export default connect( null, - { startOrJoinGame } + { startOrJoinGame, start } )(NewGame) diff --git a/src/server/farm.scm b/src/server/farm.scm index c51a0b3..7078526 100644 --- a/src/server/farm.scm +++ b/src/server/farm.scm @@ -79,7 +79,8 @@ (last-ui-action initform: #f accessor: player-last-ui-action))) (define-class () - ((players initform: '() accessor: game-players) + ((id initform: 0 accessor: game-id) + (players initform: '() accessor: game-players) (messages initform: '() accessor: game-messages) (otbs initform: '() accessor: game-otbs) (used-otbs initform: '() accessor: game-used-otbs) @@ -97,7 +98,8 @@ (last-ui-action initform: #f accessor: game-last-ui-action))) (define-class () - ((games initform: '() accessor: app-games))) + ((games initform: '() accessor: app-games) + (last-game-id initform: 0 accessor: last-game-id))) (define (player->sexp player) `((cash . ,(player-cash player)) @@ -139,6 +141,10 @@ (define *app* (make )) +(define (next-game-id app) + (set! (last-game-id app) (+ (last-game-id app) 1)) + (- (last-game-id app) 1)) + (define sid (make-parameter #f)) (define session-cookie-name (make-parameter "awful-cookie")) (define session-cookie-setter (make-parameter @@ -624,6 +630,7 @@ (games . ((games . ,(list->vector (map (lambda (game) `((name . ,(game-name game)) + (id . ,(game-id game)) (colors . ,(list->vector (map symbol->string (game-colors game)))) (players . ,(list->vector @@ -868,6 +875,7 @@ (game (make 'colors (filter (cut neq? <> color) '(green red blue yellow black)) 'name (alist-ref 'gameName msg) + 'id (next-game-id *app*) 'otbs (setup-otbs) 'operating-expenses (setup-operating-expenses) 'farmers-fates (setup-farmers-fates))) @@ -882,7 +890,8 @@ ((string=? type "join-game") (let* ((color (string->symbol (alist-ref 'checkedColor msg))) (name (alist-ref 'gameName msg)) - (game (find (lambda (g) (string=? (game-name g) name)) + (id (alist-ref 'gameId msg)) + (game (find (lambda (g) (= (game-id g) id)) (app-games *app*))) (player (add-player-to-game game color @@ -895,7 +904,8 @@ ((string=? type "join-as-existing") (let* ((name (alist-ref 'gameName msg)) (pname (alist-ref 'playerName msg)) - (game (find (lambda (g) (string=? (game-name g) name)) + (id (alist-ref 'gameId msg)) + (game (find (lambda (g) (= (game-id g) id)) (app-games *app*))) (player (find (lambda (p) (string=? (player-name p) pname)) (game-players game)))) @@ -1024,14 +1034,14 @@ ;; (define *otbs* (setup-otbs)) (define *awful-thread* #f) -(define (run-awful) ; for emacs interactive development - (set! *awful-thread* +(define (run-awful) ; for interactive development + (set! *server-thread* (make-thread (lambda () (start-server) ;; (awful-start (lambda () (void)) port: 8080) ))) - (thread-start! *awful-thread*)) + (thread-start! *server-thread*)) (define (strip-tags sxml #!key (para-space #f)) (apply @@ -1684,4 +1694,5 @@ ;; bug: loans is buggy when negative cash ;; bug: dice shows no value when landing on christmas vacation ;; hide Join Game when no games to join -;; livestock bonus card causes "you gained $0" to show every turn +;; livestock bonus card (or anytime holding a card?) causes "you +;; gained $0" to show every turn diff --git a/src/style.scss b/src/style.scss index 75f3bdd..661d619 100644 --- a/src/style.scss +++ b/src/style.scss @@ -732,3 +732,7 @@ $intro-time: 6s; .credits img { height: 34px; } + +.fa-arrow-circle-left { + cursor: pointer; + margin-right: 0.5rem; }