Skip to content

Commit

Permalink
Add basic server response modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jaythomas committed Mar 19, 2018
1 parent 4a219fc commit d5b3c7d
Show file tree
Hide file tree
Showing 37 changed files with 563 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ rules:
no-trailing-spaces: error
no-undef: error
no-undef-init: error
no-undefined: error
no-undefined: off
no-underscore-dangle: error
no-unexpected-multiline: error
no-unmodified-loop-condition: error
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

## Overview

**Status: currently in development.**

This is the server-side and client-side applications for playing Junkyard Brawl in your favorite device's browser.
The backend server is written in nodejs and the frontend is written with [Vue.js](https://vuejs.org/) and bundled with [webpack](https://webpack.js.org/).

Expand Down
5 changes: 4 additions & 1 deletion client/.pug-lintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ module.exports = {
],
requireStrictEqualityOperators: true,
validateAttributeQuoteMarks: '"',
validateAttributeSeparator: ', ',
validateAttributeSeparator: {
separator: ', ',
multiLineSeparator: ',\n '
},
validateDivTags: true,
validateExtensions: true,
validateIndentation: 2,
Expand Down
8 changes: 2 additions & 6 deletions client/.stylelintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rules:
block-opening-brace-space-after: always-single-line
block-opening-brace-space-before: always
color-hex-case: lower
#color-hex-length: long
color-hex-length: null
color-no-invalid-hex: true
comment-empty-line-before: null
comment-no-empty: true
Expand Down Expand Up @@ -135,11 +135,7 @@ rules:
selector-pseudo-element-colon-notation: single
selector-pseudo-element-no-unknown: true
selector-type-case: lower
selector-type-no-unknown:
- true
- ignoreTypes:
- /^w(d|m|t)-/
- chart-trade-dropdown
selector-type-no-unknown: null
shorthand-property-no-redundant-values: true
string-no-newline: true
unit-case: lower
Expand Down
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"webpack-dev-server": "^2.9.3"
},
"dependencies": {
"uikit": "^3.0.0-beta.40",
"vue": "^2.4.2",
"vue-router": "^2.7.0"
}
Expand Down
8 changes: 8 additions & 0 deletions client/src/components/game-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('./game-info.scss')

module.exports = require('vue').component('game-info', {
props: {
score: Number
},
template: require('./game-info.pug')()
})
10 changes: 10 additions & 0 deletions client/src/components/game-info.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.game-info
div
span.label Time:
span.value 4:57
div
span.label Turns:
span.value 23
div
span.label Score:
span.value {{ score }}
19 changes: 19 additions & 0 deletions client/src/components/game-info.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.game-info {
border-bottom: 1px solid #555;
padding-bottom: 1em;
text-align: center;

> div {
display: inline-block;
width: 200px;

.label {
margin-right: 5px;
}

.value {
font-weight: bold;
}
}
}

8 changes: 8 additions & 0 deletions client/src/components/game-modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('./game-modal.scss')

module.exports = require('vue').component('game-modal', {
props: {
score: Number
},
template: require('./game-modal.pug')()
})
6 changes: 6 additions & 0 deletions client/src/components/game-modal.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.game-modal
.overlay
.content
.title You won!
.score Score: {{ score }}
button.uk-button.uk-button-default(@click="newGame()", type="button") New game
48 changes: 48 additions & 0 deletions client/src/components/game-modal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@import 'compass/css3/border-radius';
@import 'compass/css3/box-shadow';
@import 'variables';

.game-modal {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;

.overlay {
background-color: rgba(darken($color-background, 10%), 0.9);
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
z-index: 1;
}

.content {
background-color: rgba($color-background, 0.9);
bottom: 0;
height: 200px;
left: 0;
margin: auto;
padding: 1em;
position: absolute;
right: 0;
text-align: center;
top: 0;
width: 400px;
z-index: 2;

@include border-radius(10px);
@include box-shadow(5px 5px 20px rgba(black, 0.8));

.title {
font-size: 1.8em;
padding: 0.5em;
}

.score {
padding: 0.5em;
}
}
}
79 changes: 55 additions & 24 deletions client/src/components/game.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
// View model's "this
// View model's "this"
let vm = null
// Websocket instance
let ws = null

module.exports = require('vue').component('game', {
data,
methods: {

addBot: function addBot() {
console.log('(local) adding bot!')
ws.send(JSON.stringify(['player:bot']))
},
start: function start() {
console.log('(local) starting game!')
ws.send(JSON.stringify(['game:start']))
},
stop: function stop() {
console.log('(local) stopping game!')
ws.send(JSON.stringify(['game:stop']))
}
},
mounted,
template: require('./game.pug')()
Expand All @@ -15,6 +26,28 @@ module.exports = require('vue').component('game', {
function data() {
return {
activityLog: [],
opponents: [
{
name: 'Kevin',
maxHp: 10,
hp: 10,
discard: [
{
id: 'grab',
type: 'counter'
},
{
type: 'unknown'
}
]
},
{
name: 'Jimbo',
maxHp: 10,
hp: 12,
discard: []
}
],
player: {
hand: [
{
Expand All @@ -32,50 +65,48 @@ function data() {
id: 'a-gun',
name: 'A Gun',
type: 'unstoppable'
},
{
type: 'unknown'
}
],
hp: 8,
maxHp: 10
}
},
score: 12,
started: null,
stopped: null
}
}

function mounted() {
vm = this
ws = new WebSocket('ws://localhost:4000')
ws = new WebSocket(`ws://localhost:4000/${vm.$route.params.gameId}`)
ws.onopen = onOpen
ws.onmessage = onMessage
}

function onOpen() {
ws.send(JSON.stringify([
'player:join',
{
gameId: vm.$route.params.gameId,
player: {
name: 'Bob' + Math.floor(Math.random() * 1e3)
}
ws.send(JSON.stringify(['player:join', {
player: {
name: 'Bob' + Math.floor(Math.random() * 1e3)
}
]))
}]))
}

function onMessage({ data: msg }) {
const [code, message, payload] = JSON.parse(msg)
const [code, payload] = JSON.parse(msg)
const codes = {
'player:joined': () => {
ws.send(JSON.stringify(['game:start']))
},
'player:status': () => {
console.log(vm)
vm.player.hand = payload.player.hand
}
'game:no-survivors': () => (vm.stopped = payload.stopped),
'game:started': () => (vm.started = payload.started),
'game:stopped': () => (vm.stopped = payload.stopped),
'game:winner': () => (vm.stopped = payload.stopped)
}

if (payload.player) {
vm.player.hand = payload.player.hand
}

if (codes[code]) {
codes[code]()
}

console.log(code, message, payload)
console.log(code, payload)
}
9 changes: 8 additions & 1 deletion client/src/components/game.pug
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
div
p game page/component
game-modal(:score="score", v-if="stopped")
game-info(:score="score")
div(v-for="opponent in opponents")
p {{ opponent.name }}
opponent-discard(:discard="opponent.discard")
player-hand(:hand="player.hand")
button(@click="start", type="button", v-if="!started") Start
button(@click="stop", type="button", v-if="started && !stopped") Stop
button(@click="addBot", type="button") Add bot
8 changes: 8 additions & 0 deletions client/src/components/home.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module.exports = require('vue').component('home', {
methods: {
randomGameName
},
template: require('./home.pug')()
})

// Guaranteed random
function randomGameName() {
return '511fax'
}
3 changes: 2 additions & 1 deletion client/src/components/home.pug
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
div
p This is the main page (written in pug)
p Create a new game
router-link(:to="{ name: 'game', params: { gameId: randomGameName() }}")
button.uk-button.uk-button-default(type="button") Create a new game
8 changes: 8 additions & 0 deletions client/src/components/opponent-card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('./opponent-card.scss')

module.exports = require('vue').component('opponent-card', {
props: {
card: Object
},
template: require('./opponent-card.pug')()
})
5 changes: 5 additions & 0 deletions client/src/components/opponent-card.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.opponent-card(:class="{ flipped: card.name }")
.back
.front
p {{ card.name }}
p {{ card.type.toUpperCase() }}
57 changes: 57 additions & 0 deletions client/src/components/opponent-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@import 'compass/css3/transform';
@import 'compass/css3/transition';
@import 'variables';

.opponent-card {
display: inline-block;
height: 150px;
margin: 1em 2em;
position: relative;
width: 100px;

@include transition(opacity 0.5s);

.front, .back {
background-color: $color-card-background;
border-radius: 5px;
bottom: 0;
color: $color-text-dark;
height: 100%;
left: 0;
position: absolute;
right: 0;
top: 0;
width: 100%;

@include backface-visibility(hidden);
@include transform(translateZ(0));
@include transition(transform 0.6s);
@include transform-style(preserve-3d);
}


.back {
background-image: url('../img/card_backside.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: 100%;
font-size: 12px;
}

.front {
@include transform(rotateY(-180deg));
background-position: center;
background-repeat: no-repeat;
background-size: 90%;
}

&.flipped {
.back {
@include transform(rotateY(180deg));
}

.front {
@include transform(rotateY(0deg));
}
}
}
Loading

0 comments on commit d5b3c7d

Please sign in to comment.