Adding game IDs and New/Join Game navigation.

logins
Thomas Hintz 5 years ago
parent 5e8be6e416
commit dd38ed5615

@ -22,6 +22,10 @@ import { connect } from 'react-redux'
import { GroupBox, Row, Col, Button } from '../widgets.jsx' import { GroupBox, Row, Col, Button } from '../widgets.jsx'
import { startOrJoinGame } from '../start/actions.js' 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' import NewGame from '../new-game/NewGame.jsx'
@ -43,18 +47,30 @@ class JoinGame extends React.Component {
} }
handleBack = e => { handleBack = e => {
this.setState({ screen: JoinGameScreens.list }); if (this.state.screen === JoinGameScreens.details) {
this.setState({ screen: JoinGameScreens.list });
} else {
this.props.start();
}
} }
handleJoinAsExisting = e => { handleJoinAsExisting = e => {
this.props.startOrJoinGame({ type: 'join-as-existing', this.props.startOrJoinGame({ type: 'join-as-existing',
playerName: e.target.text, playerName: e.target.text,
gameId: this.state.game.id,
gameName: this.state.game.name }); gameName: this.state.game.name });
} }
render() { render() {
return ( return (
<GroupBox title='Join Game'> <GroupBox title={(
<Fragment>
<a href="#" onClick={this.handleBack}>
<FontAwesomeIcon icon={faArrowCircleLeft} />
</a>
Join Game
</Fragment>
)}>
<Row> <Row>
<Col width='12'> <Col width='12'>
{this.state.screen === JoinGameScreens.list ? {this.state.screen === JoinGameScreens.list ?
@ -65,8 +81,8 @@ class JoinGame extends React.Component {
<a href='#' onClick={() => this.handleClickGame(g)}>{g.name}</a> <a href='#' onClick={() => this.handleClickGame(g)}>{g.name}</a>
</li>))} </li>))}
</ul>) </ul>)
: (<Fragment> : (
<p><a href="#" onClick={this.handleBack}>back to games</a></p> <Fragment>
<h3><b>Game:</b> {this.state.game.name}</h3> <h3><b>Game:</b> {this.state.game.name}</h3>
<h4>Join as existing player:</h4> <h4>Join as existing player:</h4>
<ul> <ul>
@ -81,7 +97,9 @@ class JoinGame extends React.Component {
button={'Join'} button={'Join'}
showGameName={false} showGameName={false}
gameName={this.state.game.name} gameName={this.state.game.name}
gameId={this.state.game.id}
type={'join-game'} type={'join-game'}
hideBack={true}
title={'Join as New Player'} /> title={'Join as New Player'} />
</Fragment>)} </Fragment>)}
</Col> </Col>
@ -93,5 +111,5 @@ class JoinGame extends React.Component {
export default connect( export default connect(
state => state.start.start, state => state.start.start,
{ startOrJoinGame } { startOrJoinGame, start }
)(JoinGame) )(JoinGame)

@ -22,6 +22,10 @@ import { connect } from 'react-redux'
import { GroupBox, Row, Col, Button } from '../widgets.jsx' import { GroupBox, Row, Col, Button } from '../widgets.jsx'
import { startOrJoinGame } from '../start/actions.js' 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 { class NewGame extends React.Component {
constructor(props) { constructor(props) {
@ -29,6 +33,7 @@ class NewGame extends React.Component {
this.state = { this.state = {
playerName: '', playerName: '',
checkedColor: props.colors[0], checkedColor: props.colors[0],
gameId: typeof props.gameId === 'undefined' ? -1 : props.gameId,
gameName: props.gameName || '' gameName: props.gameName || ''
}; };
} }
@ -48,10 +53,21 @@ class NewGame extends React.Component {
this.props.startOrJoinGame(Object.assign({ type: this.props.type }, this.state)); this.props.startOrJoinGame(Object.assign({ type: this.props.type }, this.state));
} }
handleBack = e => {
this.props.start();
}
render() { render() {
let playerNameInput; let playerNameInput;
return ( return (
<GroupBox title={this.props.title}> <GroupBox title={!this.props.hideBack ? (
<Fragment>
<a href="#" onClick={this.handleBack}>
<FontAwesomeIcon icon={faArrowCircleLeft} />
</a>
{this.props.title}
</Fragment>
) : this.props.title}>
<form onSubmit={this.handleSubmit}> <form onSubmit={this.handleSubmit}>
<Row> <Row>
<Col width='12'> <Col width='12'>
@ -100,5 +116,5 @@ class NewGame extends React.Component {
export default connect( export default connect(
null, null,
{ startOrJoinGame } { startOrJoinGame, start }
)(NewGame) )(NewGame)

@ -79,7 +79,8 @@
(last-ui-action initform: #f accessor: player-last-ui-action))) (last-ui-action initform: #f accessor: player-last-ui-action)))
(define-class <game> () (define-class <game> ()
((players initform: '() accessor: game-players) ((id initform: 0 accessor: game-id)
(players initform: '() accessor: game-players)
(messages initform: '() accessor: game-messages) (messages initform: '() accessor: game-messages)
(otbs initform: '() accessor: game-otbs) (otbs initform: '() accessor: game-otbs)
(used-otbs initform: '() accessor: game-used-otbs) (used-otbs initform: '() accessor: game-used-otbs)
@ -97,7 +98,8 @@
(last-ui-action initform: #f accessor: game-last-ui-action))) (last-ui-action initform: #f accessor: game-last-ui-action)))
(define-class <app> () (define-class <app> ()
((games initform: '() accessor: app-games))) ((games initform: '() accessor: app-games)
(last-game-id initform: 0 accessor: last-game-id)))
(define (player->sexp player) (define (player->sexp player)
`((cash . ,(player-cash player)) `((cash . ,(player-cash player))
@ -139,6 +141,10 @@
(define *app* (make <app>)) (define *app* (make <app>))
(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 sid (make-parameter #f))
(define session-cookie-name (make-parameter "awful-cookie")) (define session-cookie-name (make-parameter "awful-cookie"))
(define session-cookie-setter (make-parameter (define session-cookie-setter (make-parameter
@ -624,6 +630,7 @@
(games . ((games . ,(list->vector (games . ((games . ,(list->vector
(map (lambda (game) (map (lambda (game)
`((name . ,(game-name game)) `((name . ,(game-name game))
(id . ,(game-id game))
(colors . ,(list->vector (colors . ,(list->vector
(map symbol->string (game-colors game)))) (map symbol->string (game-colors game))))
(players . ,(list->vector (players . ,(list->vector
@ -868,6 +875,7 @@
(game (make <game> 'colors (filter (cut neq? <> color) (game (make <game> 'colors (filter (cut neq? <> color)
'(green red blue yellow black)) '(green red blue yellow black))
'name (alist-ref 'gameName msg) 'name (alist-ref 'gameName msg)
'id (next-game-id *app*)
'otbs (setup-otbs) 'otbs (setup-otbs)
'operating-expenses (setup-operating-expenses) 'operating-expenses (setup-operating-expenses)
'farmers-fates (setup-farmers-fates))) 'farmers-fates (setup-farmers-fates)))
@ -882,7 +890,8 @@
((string=? type "join-game") ((string=? type "join-game")
(let* ((color (string->symbol (alist-ref 'checkedColor msg))) (let* ((color (string->symbol (alist-ref 'checkedColor msg)))
(name (alist-ref 'gameName 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*))) (app-games *app*)))
(player (add-player-to-game game (player (add-player-to-game game
color color
@ -895,7 +904,8 @@
((string=? type "join-as-existing") ((string=? type "join-as-existing")
(let* ((name (alist-ref 'gameName msg)) (let* ((name (alist-ref 'gameName msg))
(pname (alist-ref 'playerName 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*))) (app-games *app*)))
(player (find (lambda (p) (string=? (player-name p) pname)) (player (find (lambda (p) (string=? (player-name p) pname))
(game-players game)))) (game-players game))))
@ -1024,14 +1034,14 @@
;; (define *otbs* (setup-otbs)) ;; (define *otbs* (setup-otbs))
(define *awful-thread* #f) (define *awful-thread* #f)
(define (run-awful) ; for emacs interactive development (define (run-awful) ; for interactive development
(set! *awful-thread* (set! *server-thread*
(make-thread (make-thread
(lambda () (lambda ()
(start-server) (start-server)
;; (awful-start (lambda () (void)) port: 8080) ;; (awful-start (lambda () (void)) port: 8080)
))) )))
(thread-start! *awful-thread*)) (thread-start! *server-thread*))
(define (strip-tags sxml #!key (para-space #f)) (define (strip-tags sxml #!key (para-space #f))
(apply (apply
@ -1684,4 +1694,5 @@
;; bug: loans is buggy when negative cash ;; bug: loans is buggy when negative cash
;; bug: dice shows no value when landing on christmas vacation ;; bug: dice shows no value when landing on christmas vacation
;; hide Join Game when no games to join ;; 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

@ -732,3 +732,7 @@ $intro-time: 6s;
.credits img { .credits img {
height: 34px; } height: 34px; }
.fa-arrow-circle-left {
cursor: pointer;
margin-right: 0.5rem; }

Loading…
Cancel
Save