Skip to content

Commit

Permalink
added both rocketcrab buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerkrewson committed Sep 6, 2020
1 parent fd8ebbe commit 6845cbb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"style-loader": "^1.2.1",
"uuid": "^8.3.0",
"webpack": "^4.44.0",
"webpack-cli": "^3.3.12"
},
Expand Down
13 changes: 13 additions & 0 deletions src/client/components/Lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default class Lobby extends Component {
});
};

var requestTransferToRocketcrab = () => {
// TODO: disable the button after it is clicked in case there is delay

this.props.server.requestTransferToRocketcrab();
};

// display how many more players are needed to start the game
var playersNeededMessage = "";
var notReady = false;
Expand Down Expand Up @@ -49,6 +55,13 @@ export default class Lobby extends Component {
<p>Players:</p>
<PlayerList players={this.props.players} />
<p>{playersNeededMessage}</p>
{!this.props.server.ROCKETCRAB_MODE && (
<div>
<SOButton onClick={requestTransferToRocketcrab}>
Transfer to 🚀🦀
</SOButton>
</div>
)}
<div>
<SOButton
onClick={() => {
Expand Down
9 changes: 9 additions & 0 deletions src/client/pages/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import Replace from "../components/Replace";

export default class MainMenu extends Component {
render() {
var goToRocketCrab = function () {
window.location.href =
"https://rocketcrab.com/transfer/tk-snakeout";
};
var goToJoinGame = function () {
this.props.changePage(JoinGame);
};
Expand Down Expand Up @@ -45,6 +49,11 @@ export default class MainMenu extends Component {

return (
<div className="main-menu noformrefresh">
<p>
<SOButton onClick={goToRocketCrab.bind(this)}>
Play on 🚀🦀
</SOButton>
</p>
<p>
<SOButton onClick={goToJoinGame.bind(this)}>
Join Game
Expand Down
8 changes: 8 additions & 0 deletions src/client/utils/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function Connection(onStateUpdate) {
onStateUpdate(data);
});

this.socket.on("transferToRocketcrab", function (link) {
window.location.href = link;
});

this.socket.on("disconnect", function () {
//refresh the page
location.reload();
Expand Down Expand Up @@ -87,6 +91,10 @@ Connection.prototype.tryReplace = function (data) {
this.send("tryReplace", data);
};

Connection.prototype.requestTransferToRocketcrab = function () {
this.send("requestTransferToRocketcrab", {});
};

Connection.prototype.send = function (event, data) {
this.socket.emit(event, data);
};
Expand Down
12 changes: 12 additions & 0 deletions src/server/app/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Snakeout Game
//

var uuidv4 = require("uuid").v4;

var Round = require("./round");
var Player = require("./player");

Expand All @@ -13,6 +15,7 @@ function Game(code, onEmpty) {
this.inProgress = false;
this.viewingResults = false;
this.currentRound;
this.uuid = uuidv4();

this.currentId = 1;
this.currentRoundNum = 1;
Expand Down Expand Up @@ -72,6 +75,15 @@ Game.prototype.initPlayer = function (newPlayer) {
newPlayer.socket.on("disconnect", function () {
self.onPlayerDisconnect(newPlayer);
});
newPlayer.socket.on("requestTransferToRocketcrab", () => {
this.sendToAll(
"transferToRocketcrab",
"https://rocketcrab.com/transfer/tk-snakeout/" +
this.uuid +
"/?name=" +
newPlayer.name
);
});
};

Game.prototype.onPlayerDisconnect = function (playerThatLeft) {
Expand Down

0 comments on commit 6845cbb

Please sign in to comment.