Initial public release.
This commit is contained in:
94
src/components/start/Start.jsx
Normal file
94
src/components/start/Start.jsx
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2020 Thomas Hintz
|
||||
//
|
||||
// This file is part of the Alpha Centauri Farming project.
|
||||
//
|
||||
// The Alpha Centauri Farming project is free software: you can
|
||||
// redistribute it and/or modify it under the terms of the GNU General
|
||||
// Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// The Alpha Centauri Farming project is distributed in the hope that
|
||||
// it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Alpha Centauri Farming project. If not, see
|
||||
// <https://www.gnu.org/licenses/>.
|
||||
|
||||
import React, { Fragment } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
|
||||
import { GroupBox, Row, Col } from '../widgets.jsx'
|
||||
import { startOrJoinGame } from './actions.js'
|
||||
|
||||
const JoinGameScreens = { list: 'list', details: 'details' };
|
||||
|
||||
class JoinGameComp extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
screen: JoinGameScreens.list,
|
||||
game: null
|
||||
};
|
||||
}
|
||||
|
||||
handleClickGame = game => {
|
||||
this.setState({ screen: JoinGameScreens.details,
|
||||
game: game
|
||||
});
|
||||
}
|
||||
|
||||
handleBack = e => {
|
||||
this.setState({ screen: JoinGameScreens.list });
|
||||
}
|
||||
|
||||
handleJoinAsExisting = e => {
|
||||
this.props.startOrJoinGame({ type: 'join-as-existing',
|
||||
playerName: e.target.text,
|
||||
gameName: this.state.game.name });
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<GroupBox title='Join Game'>
|
||||
<Row>
|
||||
<Col width='12'>
|
||||
{this.state.screen === JoinGameScreens.list ?
|
||||
(<ul>
|
||||
{this.props.games
|
||||
.map((g, i) =>
|
||||
(<li key={i}>
|
||||
<a href='#' onClick={() => this.handleClickGame(g)}>{g.name}</a>
|
||||
</li>))}
|
||||
</ul>)
|
||||
: (<Fragment>
|
||||
<p><a href="#" onClick={this.handleBack}>back to games</a></p>
|
||||
<h3><b>Game:</b> {this.state.game.name}</h3>
|
||||
<h4>Join as existing player:</h4>
|
||||
<ul>
|
||||
{this.state.game.players.map((p, i) =>
|
||||
(<li key={i}>
|
||||
<a href='#' onClick={this.handleJoinAsExisting}>
|
||||
{p}
|
||||
</a>
|
||||
</li>))}
|
||||
</ul>
|
||||
<NewGame colors={this.state.game.colors}
|
||||
button={'Join'}
|
||||
showGameName={false}
|
||||
gameName={this.state.game.name}
|
||||
type={'join-game'}
|
||||
title={'Join as New Player'} />
|
||||
</Fragment>)}
|
||||
</Col>
|
||||
</Row>
|
||||
</GroupBox>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const JoinGame = connect(
|
||||
null,
|
||||
{ startOrJoinGame }
|
||||
)(JoinGameComp)
|
||||
20
src/components/start/actionTypes.js
Normal file
20
src/components/start/actionTypes.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2020 Thomas Hintz
|
||||
//
|
||||
// This file is part of the Alpha Centauri Farming project.
|
||||
//
|
||||
// The Alpha Centauri Farming project is free software: you can
|
||||
// redistribute it and/or modify it under the terms of the GNU General
|
||||
// Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// The Alpha Centauri Farming project is distributed in the hope that
|
||||
// it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Alpha Centauri Farming project. If not, see
|
||||
// <https://www.gnu.org/licenses/>.
|
||||
|
||||
export const SET_START_GAMES = 'set-start-games';
|
||||
export const START_OR_JOIN_GAME = 'start-or-join-game';
|
||||
31
src/components/start/actions.js
Normal file
31
src/components/start/actions.js
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2020 Thomas Hintz
|
||||
//
|
||||
// This file is part of the Alpha Centauri Farming project.
|
||||
//
|
||||
// The Alpha Centauri Farming project is free software: you can
|
||||
// redistribute it and/or modify it under the terms of the GNU General
|
||||
// Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// The Alpha Centauri Farming project is distributed in the hope that
|
||||
// it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Alpha Centauri Farming project. If not, see
|
||||
// <https://www.gnu.org/licenses/>.
|
||||
|
||||
import { SET_START_GAMES, START_OR_JOIN_GAME } from './actionTypes.js'
|
||||
|
||||
export { setStartGames, startOrJoinGame }
|
||||
|
||||
function setStartGames(games) {
|
||||
return { type: SET_START_GAMES,
|
||||
games };
|
||||
}
|
||||
|
||||
function startOrJoinGame(msg) {
|
||||
return { type: START_OR_JOIN_GAME,
|
||||
msg };
|
||||
}
|
||||
37
src/components/start/reducers.js
Normal file
37
src/components/start/reducers.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2020 Thomas Hintz
|
||||
//
|
||||
// This file is part of the Alpha Centauri Farming project.
|
||||
//
|
||||
// The Alpha Centauri Farming project is free software: you can
|
||||
// redistribute it and/or modify it under the terms of the GNU General
|
||||
// Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// The Alpha Centauri Farming project is distributed in the hope that
|
||||
// it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Alpha Centauri Farming project. If not, see
|
||||
// <https://www.gnu.org/licenses/>.
|
||||
|
||||
import { SET_START_GAMES, START_OR_JOIN_GAME } from './actionTypes.js'
|
||||
import { SCREENS } from '../../constants.js'
|
||||
|
||||
const initialState = {
|
||||
start: { games: [] },
|
||||
msg: null
|
||||
};
|
||||
|
||||
export default function(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case SET_START_GAMES:
|
||||
return { ...state, start: { ...state.start, games: action.games }};
|
||||
case START_OR_JOIN_GAME:
|
||||
return { ...state, msg: action.msg };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user