Adding game IDs and New/Join Game navigation.
This commit is contained in:
@@ -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 (
|
||||
<GroupBox title='Join Game'>
|
||||
<GroupBox title={(
|
||||
<Fragment>
|
||||
<a href="#" onClick={this.handleBack}>
|
||||
<FontAwesomeIcon icon={faArrowCircleLeft} />
|
||||
</a>
|
||||
Join Game
|
||||
</Fragment>
|
||||
)}>
|
||||
<Row>
|
||||
<Col width='12'>
|
||||
{this.state.screen === JoinGameScreens.list ?
|
||||
@@ -65,8 +81,8 @@ class JoinGame extends React.Component {
|
||||
<a href='#' onClick={() => this.handleClickGame(g)}>{g.name}</a>
|
||||
</li>))}
|
||||
</ul>)
|
||||
: (<Fragment>
|
||||
<p><a href="#" onClick={this.handleBack}>back to games</a></p>
|
||||
: (
|
||||
<Fragment>
|
||||
<h3><b>Game:</b> {this.state.game.name}</h3>
|
||||
<h4>Join as existing player:</h4>
|
||||
<ul>
|
||||
@@ -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'} />
|
||||
</Fragment>)}
|
||||
</Col>
|
||||
@@ -93,5 +111,5 @@ class JoinGame extends React.Component {
|
||||
|
||||
export default connect(
|
||||
state => state.start.start,
|
||||
{ startOrJoinGame }
|
||||
{ startOrJoinGame, start }
|
||||
)(JoinGame)
|
||||
|
||||
@@ -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 (
|
||||
<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}>
|
||||
<Row>
|
||||
<Col width='12'>
|
||||
@@ -100,5 +116,5 @@ class NewGame extends React.Component {
|
||||
|
||||
export default connect(
|
||||
null,
|
||||
{ startOrJoinGame }
|
||||
{ startOrJoinGame, start }
|
||||
)(NewGame)
|
||||
|
||||
@@ -79,7 +79,8 @@
|
||||
(last-ui-action initform: #f accessor: player-last-ui-action)))
|
||||
|
||||
(define-class <game> ()
|
||||
((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 <app> ()
|
||||
((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 <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 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 <game> '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
|
||||
|
||||
@@ -732,3 +732,7 @@ $intro-time: 6s;
|
||||
|
||||
.credits img {
|
||||
height: 34px; }
|
||||
|
||||
.fa-arrow-circle-left {
|
||||
cursor: pointer;
|
||||
margin-right: 0.5rem; }
|
||||
|
||||
Reference in New Issue
Block a user