Skip to content

Commit

Permalink
Merge d944e4c into ad80016
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-nguyen committed Oct 21, 2018
2 parents ad80016 + d944e4c commit 6ea0c90
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 70 deletions.
13 changes: 0 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Build and minify React client
FROM node:carbon AS client
WORKDIR /
WORKDIR /client
ADD client/package.json .
RUN npm install
ADD client .
RUN npm run build

# Build server
FROM golang:alpine AS server
WORKDIR /app
Expand All @@ -21,11 +12,7 @@ RUN go build -o server; cp server /app
# Copy build to final stage
FROM alpine
RUN apk add --update --no-cache ca-certificates
WORKDIR /app/build
COPY --from=client /client/public/ .
WORKDIR /app
# ENV dependencies
ADD .env .
COPY server/service-account.json .
COPY --from=server /app/server .

Expand Down
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@ deps:
(cd server ; go get -u github.com/golang/dep/cmd/dep ; dep ensure)
(cd client ; npm install )

# Starts the client
# Build and minify client
.PHONY: bundle
bundle:
(cd ./client ; npm run build)

# Build and run Bumper in daemon mode
.PHONY: bumper
DATABASE_URL=https://bumperdevdb.firebaseio.com
SERVER_PORT=9090
bumper:
docker stop bumper 2>&1 || true
docker build -t bumper .
docker run -d --rm \
--name bumper \
-e DATABASE_URL=$(DATABASE_URL) \
-e PORT=$(SERVER_PORT) \
-p 9090:$(SERVER_PORT) \
bumper

# Starts the client (dev server on port 8080)
.PHONY: client
client:
(cd ./client ; npm start)

# Starts the server (exposed on port 9090)
.PHONY: server
server:
(cd ./server ; PORT=8081 ; gin -p 9090 -a 8081 -i run main.go)
(cd ./server ; DATABASE_URL=$(DATABASE_URL) PORT=8081 gin -p $(SERVER_PORT) -a 8081 -i run main.go)
1 change: 0 additions & 1 deletion client/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
registerTesterUpdateEvent,
} from './database/database';


const address = process.env.NODE_ENV === 'production'
? 'bumper.ubclaunchpad.com'
: 'localhost:9090';
Expand Down
31 changes: 27 additions & 4 deletions client/components/GameObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export function drawGame(data, canvas) {

// Create a new object arrays with the positions translated.
const junk = data.junk.map((j) => {
if (!j.position) {
return {
position: { x: 0, y: 0 },
color: 'black',
};
}

const newPosition = {
x: j.position.x + objectXTranslation,
y: j.position.y + objectYTranslation,
Expand All @@ -56,6 +63,14 @@ export function drawGame(data, canvas) {
});

const holes = data.holes.map((h) => {
if (!h.position) {
return {
position: { x: 0, y: 0 },
radius: 0,
isAlive: false,
};
}

const newPosition = {
x: h.position.x + objectXTranslation,
y: h.position.y + objectYTranslation,
Expand All @@ -68,6 +83,14 @@ export function drawGame(data, canvas) {
});

const players = data.players.map((p) => {
if (!p.position) {
return {
position: { x: 0, y: 0 },
color: 'black',
angle: 0,
};
}

if (p.name !== '' && p.id !== data.player.id) {
const newPosition = {
x: p.position.x + objectXTranslation,
Expand Down Expand Up @@ -255,28 +278,28 @@ export function drawWalls(player, arena, canvas) {
if (player.position.x < (canvas.width / 2)) {
ctx.beginPath();
ctx.rect(0, 0, 10, arena.height);
ctx.fillStyle = 'yellow';
ctx.fillStyle = 'grey';
ctx.fill();
ctx.closePath();
}
if (player.position.x > arena.width - (canvas.width / 2)) {
ctx.beginPath();
ctx.rect(canvas.width - 10, 0, 10, arena.height);
ctx.fillStyle = 'yellow';
ctx.fillStyle = 'grey';
ctx.fill();
ctx.closePath();
}
if (player.position.y < (canvas.height / 2)) {
ctx.beginPath();
ctx.rect(0, 0, arena.width, 10);
ctx.fillStyle = 'yellow';
ctx.fillStyle = 'grey';
ctx.fill();
ctx.closePath();
}
if (player.position.y > arena.height - (canvas.height / 2)) {
ctx.beginPath();
ctx.rect(0, canvas.height - 10, arena.width, 10);
ctx.fillStyle = 'yellow';
ctx.fillStyle = 'grey';
ctx.fill();
ctx.closePath();
}
Expand Down
2 changes: 1 addition & 1 deletion client/components/Leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class Leaderboard extends React.Component {
{
this.props.players.map(p => (
p.name &&
<tr>
<tr key={p.name}>
<td><Flag code={p.country} height={20} /></td>
<td>{p.name}</td>
<td>{p.points}</td>
Expand Down
1 change: 0 additions & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import ReactDOM from 'react-dom';

import App from './App';

console.log(process.env.NODE_ENV);
ReactDOM.render(<App />, document.getElementById('app'));
27 changes: 0 additions & 27 deletions docker-compose.dev.yml

This file was deleted.

7 changes: 0 additions & 7 deletions docker-compose.yml

This file was deleted.

15 changes: 1 addition & 14 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,15 @@ import (
"os"
"time"

"github.com/joho/godotenv"
"github.com/ubclaunchpad/bumper/server/arena"
"github.com/ubclaunchpad/bumper/server/database"
"github.com/ubclaunchpad/bumper/server/game"
"github.com/ubclaunchpad/bumper/server/models"
)

func main() {
if err := godotenv.Load("../.env"); err != nil {
log.Println("Error loading environment variables from parent directory")
log.Print("Try current directory... ")

if err := godotenv.Load(); err != nil {
log.Println("Cannot load environment variables")
} else {
log.Println("Success")
}
}

rand.Seed(time.Now().UTC().UnixNano())

arena.MessageChannel = make(chan models.Message)
game := game.CreateGame()

Expand All @@ -35,11 +24,9 @@ func main() {
log.Println("DBClient not initialized correctly")
}

http.Handle("/", http.FileServer(http.Dir("./build")))
http.Handle("/connect", game)
game.StartGame()

log.Println("Server URL: " + os.Getenv("SERVER_URL"))
log.Println("Starting server on localhost:" + os.Getenv("PORT"))
log.Println(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}

0 comments on commit 6ea0c90

Please sign in to comment.