diff --git a/client/src/Board.css b/client/src/Board.css index 3f4567d..2481621 100755 --- a/client/src/Board.css +++ b/client/src/Board.css @@ -1,148 +1,154 @@ -.Board { - display: inline-block; - position: absolute; - width: 100%; - overflow: hidden; - height: 100%; -} - -.Display { - display: inline-block; - position: absolute; -} - -.Cards { - display: inline-block; - position: absolute; - text-align: right; - vertical-align: bottom; - padding: 0.5em; - box-sizing: border-box; - max-height: 100%; - max-width: 100%; -} - -.Stack { - position: relative; - display: inline-block; -} - -.Stack:not(:first-child) { - margin-left: -3em; - transition: margin-left 1s ease-in-out 0.25s; -} - -.Stack > * { - transition: margin-left 1s ease-in-out 0.25s, margin-right 1s ease-in-out 0.25s; -} - -.Development:hover, -.Placard:hover, -.Resource:hover { - filter: brightness(150%); -} - -.Game { - display: inline-flex; - flex-direction: column; - width: 20em; - opacity: 0.7; - z-index: 100; - overflow: hidden; -} - -.Game > *:not(:last-child) { - margin-bottom: 0.5em; -} - -.Chat { - padding: 0.5em; -} - -.Chat > * { - width: 100%; -} - -.Chat > :first-child { - max-height: 30vh; - overflow-y: scroll; -} - -.Players { - padding: 0.5em; -} - -.PlayerName { - padding: 0.5em; -} - -#ChatList { - scroll-behavior: smooth; -} - -.Players > * { - width: 100%; -} - -.Players .nameInput { - flex-grow: 1; -} - -.Stack > *:not(:first-child) { - margin-left: -4.5em; -} - -.Hand { - min-height: calc(7.2em + 0.5em); -} - -.Hand:hover .Stack:hover > *:not(:first-child) { - margin-left: -2em; -} - -.Hand:hover .Stack:hover:not(:last-child) > *:last-child { - margin-right: 3em; -} - -.Placard { - position: relative; - width: 9.4em; - height: 11.44em; - background-position: center; - background-repeat: no-repeat; - background-size: cover; - margin: 0.25em; - display: inline-block; -} - -.Development { - position: relative; - display: inline-block; - width: 4.9em; - height: 7.2em; - background-position: center; - background-repeat: no-repeat; - background-size: cover; - margin: 0.25em; -} - -.Resource { - position: relative; - width: 4.9em; - height: 7.2em; - display: inline-block; - background-position: center; - background-repeat: no-repeat; - background-size: cover; - margin: 0.25em; -} - -.Statistics > div:nth-child(2) { - display: flex; - flex-direction: row; - border: 1px solid black; -} - -.Statistics div:nth-child(2) div { - padding: 0.25em 0.5em; -} +.Board { + display: inline-block; + position: absolute; + width: 100%; + overflow: hidden; + height: 100%; +} + +.Display { + display: inline-block; + position: absolute; +} + +.Cards { + display: inline-block; + position: absolute; + text-align: right; + vertical-align: bottom; + padding: 0.5em; + box-sizing: border-box; + max-height: 100%; + max-width: 100%; + opacity: 0.7; +} + +.Stack { + position: relative; + display: inline-block; +} + +.Stack:not(:first-child) { + margin-left: -3em; + transition: margin-left 1s ease-in-out 0.25s; +} + +.Stack > * { + transition: margin-left 1s ease-in-out 0.25s, margin-right 1s ease-in-out 0.25s; +} + +.Development:hover, +.Placard:hover, +.Resource:hover { + filter: brightness(150%); +} + +.Game { + display: inline-flex; + flex-direction: column; + box-sizing: border-box; + width: 20em; + opacity: 0.7; + z-index: 100; + overflow: hidden; +} + +.lobby { + width: calc(100vw - 1em); +} + +.Game > *:not(:last-child) { + margin-bottom: 0.5em; +} + +.Chat { + padding: 0.5em; +} + +.Chat > * { + width: 100%; +} + +.Chat > :first-child { + max-height: 30vh; + overflow-y: scroll; +} + +.Players { + padding: 0.5em; +} + +.PlayerName { + padding: 0.5em; +} + +#ChatList { + scroll-behavior: smooth; +} + +.Players > * { + width: 100%; +} + +.Players .nameInput { + flex-grow: 1; +} + +.Stack > *:not(:first-child) { + margin-left: -4.5em; +} + +.Hand { + min-height: calc(7.2em + 0.5em); +} + +.Hand:hover .Stack:hover > *:not(:first-child) { + margin-left: -2em; +} + +.Hand:hover .Stack:hover:not(:last-child) > *:last-child { + margin-right: 3em; +} + +.Placard { + position: relative; + width: 9.4em; + height: 11.44em; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + margin: 0.25em; + display: inline-block; +} + +.Development { + position: relative; + display: inline-block; + width: 4.9em; + height: 7.2em; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + margin: 0.25em; +} + +.Resource { + position: relative; + width: 4.9em; + height: 7.2em; + display: inline-block; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + margin: 0.25em; +} + +.Statistics > div:nth-child(2) { + display: flex; + flex-direction: row; + border: 1px solid black; +} + +.Statistics div:nth-child(2) div { + padding: 0.25em 0.5em; +} diff --git a/client/src/Board.js b/client/src/Board.js index 9e5a0c2..580e244 100755 --- a/client/src/Board.js +++ b/client/src/Board.js @@ -209,7 +209,9 @@ const Chat = ({ board, promoteGameState }) => { console.log(`Send: ${event.target.value}`); promoteGameState({ chat: { - player: board.game.activePlayer ? board.game.activePlayer : undefined, + player: board.game.activePlayer ? + board.game.activePlayer : + undefined, message: event.target.value } }); @@ -290,7 +292,7 @@ const PlayerName = ({board}) => { const nameKeyPress = (event) => { if (event.key === "Enter") { console.log(`Send: ${name}`); - if (name && name != board.game.activePlayerName) { + if (name != board.game.activePlayerName) { board.setPlayerName(name); } } @@ -313,14 +315,9 @@ const PlayerName = ({board}) => { /* This needs to take in a mechanism to declare the * player's active item in the game */ const Players = ({ board }) => { - const [selected, setSelected] = useState(board.game && board.game.activePlayer ? board.game.activePlayer : ""); + const selected = board.game && board.game.activePlayer ? board.game.activePlayer : ""; const toggleSelected = (key) => { - if (selected === key) { - setSelected(""); - } else { - setSelected(key); - } board.setSelected(selected === key ? "" : key); } @@ -452,12 +449,16 @@ class Board extends React.Component { return res.json(); }).then((game) => { let message; - if (key) { - message = `Player selected ${key}!`; + if (game.status == 'success') { + if (key) { + message = `Player selected ${key}!`; + } else { + message = `Player deselected ${game.activePlayer}!`; + } } else { - message = `Player deselected ${game.activePlayer}!`; + message = game.status; } - console.log (message); + this.updateGame(game); this.setState({ game: game, message: message }); }).catch((error) => { @@ -488,9 +489,18 @@ class Board extends React.Component { } return res.json(); }).then((game) => { - console.log (`Player name set to ${name}!`); + let message; + if (game.status == 'success') { + if (name) { + message = `Player name set to ${name}`; + } else { + message = `Player name cleared.`; + } + } else { + message = game.status; + } this.updateGame(game); - this.setState({ game: game, message: `Player name set to ${name}!`}); + this.setState({ game: game, message: message}); }).catch((error) => { console.error(error); this.setState({message: error.message}); @@ -587,7 +597,7 @@ class Board extends React.Component { }).then((res) => { if (res.status >= 400) { console.log(res); - throw new Error(`Unable to load state`); + throw new Error(`Unable to load game`); } return res.json(); }).then((game) => { @@ -1312,7 +1322,7 @@ class Board extends React.Component {