Skip to content
This repository was archived by the owner on May 24, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,css}]
[*.{js,css,js.default}]
indent_size = 2
indent_style = space
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ data
public/out
public/lib

config.js
config.client.js
config.server.js
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.PHONY: all install clean cards score js
all: install clean cards score js
all: install cards score js

node := ${CURDIR}/node_modules
all_sets := ${CURDIR}/data/AllSets.json
traceur := ${node}/.bin/traceur
config := config.js

client_config := config.client.js
server_config := config.server.js

${traceur}: install

Expand Down Expand Up @@ -32,14 +34,16 @@ ${all_sets}:
curl -so ${all_sets} https://mtgjson.com/json/AllSets.json

score:
-node src/make score #ignore errors
-node src/make score

js: ${traceur} ${all_sets} ${config}
js: ${traceur} ${all_sets} ${client_config}
${traceur} --out public/lib/app.js public/src/init.js

# "order-only" prerequisite
${config}: | ${config}.default
${client_config}: | ${client_config}.default
cp $| $@
${server_config}: | ${server_config}.default
cp $| $@

run: js
run: js ${server_config}
node run
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# drafts.ninja
# drafts.ninja [![Stories in Ready](https://badge.waffle.io/arxanas/drafts.ninja.png?label=ready&title=Ready)](https://waffle.io/arxanas/drafts.ninja) [![Gitter chat](https://badges.gitter.im/arxanas/drafts.ninja.png)](https://gitter.im/arxanas/drafts.ninja)

[drafts.ninja](http://drafts.ninja) is a fork of aeosynth's `draft` project. It
supports all of the features of `draft` and more. Here are some of the
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const CONFIG = require('./config')
const CONFIG = require('./config.server')

var http = require('http')
var eio = require('engine.io')
Expand Down
20 changes: 20 additions & 0 deletions config.client.js.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let d = React.DOM

export let STRINGS = {
BRANDING: {
SITE_NAME: ['drafts', 'ninja'],
DEFAULT_USERNAME: 'ninja',
},

PAGE_SECTIONS: {
MOTD: null, // message of the day; can be a React element

FOOTER: d.div({},
d.strong({}, 'drafts.ninja'),
' is a fork of the ',
d.code({}, 'draft'),
' project by aeosynth. Contributions welcome! ',
d.a({ href: 'https://github.com/arxanas/drafts.ninja' },
'https://github.com/arxanas/drafts.ninja')),
},
}
4 changes: 0 additions & 4 deletions config.js.default

This file was deleted.

8 changes: 8 additions & 0 deletions config.server.js.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
PORT: 1337,
STRINGS: {
BRANDING: {
DEFAULT_USERNAME: 'ninja',
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"node-fetch": "^1.0.3",
"send": "^0.11.1",
"traceur": "0.0.65",
"utils": "git://github.com/aeosynth/utils"
"utils": "git://github.com/arxanas/utils"
},
"devDependencies": {
"normalize.css": "^3.0.1",
Expand Down
1 change: 0 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<meta charset="utf-8">
<title>drafts.ninja</title>
<link rel="stylesheet" href="lib/normalize.css">
<!-- https://github.com/driftyco/ionicons/issues/129 -->
<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css">
Expand Down
6 changes: 4 additions & 2 deletions public/src/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from '../lib/utils'
import EventEmitter from '../lib/ee'
import {STRINGS} from './config'

function message(msg) {
let args = JSON.parse(msg)
Expand All @@ -11,7 +12,7 @@ let App = {

state: {
id: null,
name: 'ninja',
name: STRINGS.BRANDING.DEFAULT_USERNAME,

numUsers: 0,
numPlayers: 0,
Expand All @@ -35,7 +36,8 @@ let App = {
packs: 3,

bots: true,
timer: true,
useTimer: true,
timerLength: 40, // seconds

beep: false,
chat: true,
Expand Down
13 changes: 10 additions & 3 deletions public/src/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ let events = {
App.send('readyToStart', e.target.checked)
},
start() {
let {bots, timer} = App.state
let options = [bots, timer]
let {bots, useTimer, timerLength} = App.state
let options = {bots, useTimer, timerLength}
App.send('start', options)
},
pack(cards) {
Expand Down Expand Up @@ -390,6 +390,13 @@ function Key(groups, sort) {
return o
}

function sortLandsBeforeNonLands(lhs, rhs) {
let isLand = x => x.type.toLowerCase().indexOf('land') !== -1
let lhsIsLand = isLand(lhs)
let rhsIsLand = isLand(rhs)
return rhsIsLand - lhsIsLand
}

export function getZone(zoneName) {
let zone = Zones[zoneName]

Expand All @@ -401,7 +408,7 @@ export function getZone(zoneName) {
let {sort} = App.state
let groups = _.group(cards, sort)
for (let key in groups)
_.sort(groups[key], 'color', 'cmc', 'name')
_.sort(groups[key], sortLandsBeforeNonLands, 'color', 'cmc', 'name')

groups = Key(groups, sort)

Expand Down
4 changes: 2 additions & 2 deletions public/src/components/deck-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Lands() {
let inputs = BASICS.map(cardName =>
d.td({},
d.input({
className: 'num-lands',
className: 'number',
min: 0,
onChange: App._emit('land', zoneName, cardName),
type: 'number',
Expand All @@ -27,7 +27,7 @@ function Lands() {
let suggest = d.tr({},
d.td({}, 'deck size'),
d.td({}, d.input({
className: 'num-lands',
className: 'number',
min: 0,
onChange: App._emit('deckSize'),
type: 'number',
Expand Down
17 changes: 16 additions & 1 deletion public/src/components/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,22 @@ export default React.createClass({
let startControls = d.div({},
d.div({}, `Format: ${App.state.format}`),
LBox('bots', 'bots'),
LBox('timer', 'timer'),
d.div({},
d.label({},
d.input({
type: 'checkbox',
checkedLink: App.link('useTimer'),
}), ' use '),
d.label({},
d.input({
className: 'number',
disabled: !App.state.useTimer,
min: 0,
max: 60,
step: 5,
type: 'number',
valueLink: App.link('timerLength'),
}), '-second timer')),
d.div({}, startButton, readyReminderText))

return d.fieldset({ className: 'start-controls fieldset' },
Expand Down
6 changes: 3 additions & 3 deletions public/src/components/grid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from '../../lib/utils'
import App from '../app'
import {getZone} from '../cards'
import {Spaced} from './spacer'
let d = React.DOM

export default React.createClass({
Expand Down Expand Up @@ -30,9 +31,8 @@ function zone(zoneName) {
})))

return d.div({ className: 'zone' },
d.h1({},
d.h1({}, Spaced(
d.span({}, zoneName),
d.span({ className: 'spacer-dot' }),
d.span({}, `${cards.length} ${cards.length === 1 ? 'card' : 'cards' }`)),
d.span({}, `${cards.length} ${cards.length === 1 ? 'card' : 'cards' }`))),
items)
}
40 changes: 20 additions & 20 deletions public/src/components/lobby.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import _ from '../../lib/utils'
import {STRINGS} from '../config'
import App from '../app'
import data from '../data'
import Chat from './chat'
import {RBox} from './checkbox'
import {Spaced} from './spacer'
let d = React.DOM

export default React.createClass({
Expand All @@ -13,32 +15,29 @@ export default React.createClass({
App.send('join', 'lobby')
},
render() {
document.title = STRINGS.BRANDING.SITE_NAME.join('.')

return d.div({ className: 'container' },
d.div({ className: 'lobby' },
d.header({},
d.h1({ className: 'lobby-header' },
d.span({}, 'drafts'),
d.span({ className: 'spacer-dot' }),
d.span({}, 'ninja'))),
d.p({}, `${App.state.numUsers}
${App.state.numUsers === 1 ? 'user' : 'users'}
connected;
${App.state.numPlayers}
${App.state.numPlayers === 1 ? 'player' : 'players'}
playing
${App.state.numActiveGames}
${App.state.numActiveGames === 1 ? 'game' : 'games'}`),
Spaced(...STRINGS.BRANDING.SITE_NAME))),

d.p({},
Spaced(
`${App.state.numUsers}
${App.state.numUsers === 1 ? 'user' : 'users'}
connected`,
`${App.state.numPlayers}
${App.state.numPlayers === 1 ? 'player' : 'players'}
playing
${App.state.numActiveGames}
${App.state.numActiveGames === 1 ? 'game' : 'games'}`)),
d.p({ className: 'error' }, App.err),
Create(),
Join(),
Motd(),
d.div({},
d.strong({}, 'drafts.ninja'),
' is a fork of the ',
d.code({}, 'draft'),
' project by aeosynth. Contributions welcome! ',
d.a({ href: 'https://github.com/arxanas/drafts.ninja' },
'https://github.com/arxanas/drafts.ninja'))),
STRINGS.PAGE_SECTIONS.FOOTER),
Chat())
}
})
Expand Down Expand Up @@ -92,10 +91,11 @@ function content() {
}

function Motd() {
if (App.state.motd)
let motd = STRINGS.PAGE_SECTIONS.MOTD
if (motd)
return d.fieldset({ className: 'fieldset' },
d.legend({ className: 'legend' }, 'News'),
d.div({ dangerouslySetInnerHTML: { '__html': App.state.motd } }))
d.div({}, motd))
}

function Create() {
Expand Down
11 changes: 11 additions & 0 deletions public/src/components/spacer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let d = React.DOM

export function Spaced(...elements) {
let parts = []
for (let part of elements) {
parts.push(d.span({}, part))
parts.push(d.span({ className: 'spacer-dot' }))
}
parts.splice(-1, 1)
return parts
}
1 change: 1 addition & 0 deletions public/src/config.js
1 change: 1 addition & 0 deletions public/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default {
"Limited Edition Alpha": "LEA"
},
other: {
"Eternal Masters": "EMA",
"Magic Origins": "ORI",
"Modern Masters 2015": "MM2",
"Tempest Remastered": "TPR",
Expand Down
10 changes: 5 additions & 5 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ input[type=button]:disabled:active, button:disabled:active {
box-shadow: 0 0 1px 0 black inset;
}

.number {
width: 50px;
}

/** Container of inputs that share a border. **/

.connected-container, .connected-column {
Expand Down Expand Up @@ -159,7 +163,7 @@ input[type=button]:disabled:active, button:disabled:active {
.spacer-dot:after {
content: "\00b7";
display: inline-block;
width: 25px;
width: 0.75em;
text-align: center;
}

Expand Down Expand Up @@ -396,10 +400,6 @@ input[type=button]:disabled:active, button:disabled:active {
flex-shrink: 0;
}

.num-lands {
width: 50px;
}

.deck-settings tr:first-of-type {
text-align: center;
}
Expand Down
Loading