Skip to content

Commit

Permalink
Merge pull request #1 from seanohue/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Sean authored Mar 3, 2018
2 parents 0d738b7 + 3417351 commit d9aa3ea
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 45 deletions.
115 changes: 92 additions & 23 deletions bin/axolemma
Original file line number Diff line number Diff line change
@@ -1,40 +1,109 @@
#!/usr/bin/env node

const cli = require('commander')
const inquirer = require('inquirer')
const semver = require('semver')
const {Subject} = require('rxjs')
const requiresNode = require('requires-node-version')
const {bold, green, blue, red} = require('chalk')

if (semver.lt(process.version,'8.0.0')) {
console.log(red(`Axolemma supports Node ${bold('v8.0.0')} or higher.`))
console.log(red(`You are currently using ${bold(process.version)}.`))
return process.exit(1)
}
requiresNode('8.0.0')

const {version} = require('../package.json')

const ax = require('../')
const {isAlphanumeric} = require('./validation')


const {isAlphanumeric, isNumber} = require('./validation')

cli.version('0.1.0')
cli.version(version)
cli.on('--help', () => {
console.log(blue(`Type ${bold(green('axolemma'))} to start creating.`))
})

const prompts = new Subject()
inquirer.prompt(prompts).ui.process.subscribe(console.log, console.log, function(answers){
console.log(answers)
ax.generate(answers) // Eventually this will be done during the prompts, and user will be prompted to approve of the generated map.
})
const {Separator} = inquirer

const questions = [

/** General area metadata **/
{
type: 'input',
name: 'areaTitle',
message: blue('What would you like to title this area?'),
validate: isAlphanumeric,
},
{
type: 'confirm',
name: 'customizeAreaInfo',
message(answers) {
const {areaTitle = 'this area'} = answers
return blue(`Would you like to further customize ${areaTitle}? (e.g., the default mob respawn rate)`)
}
},
{
type: 'input',
name: 'respawnTime',
message(answers) {
const {areaTitle = 'this area'} = answers
return blue(`What should the default respawn rate be for ${areaTitle}? (in seconds)`)
},
when(answers) {
return Boolean(answers.customizeAreaInfo)
},
validate: isNumber,
default: 60
},

/** Area generation algo. input **/
{
type: 'input',
name: 'width',
message(answers) {
const {areaTitle = 'this area'} = answers
return blue(`What is the maximum width (x coordinate) of ${areaTitle}?`);
},
validate: isNumber,
default: 10
},
{
type: 'input',
name: 'height',
message(answers) {
const {areaTitle = 'this area'} = answers
return blue(`What is the maximum height (y coordinate) of ${areaTitle}?`);
},
validate: isNumber,
default: 10
},
{
type: 'input',
name: 'depth',
message(answers) {
const {areaTitle = 'this area'} = answers
return blue(`What is the maximum depth (z coordinate) of ${areaTitle}?`);
},
validate: isNumber,
default: 10,
when: false // Not supported yet.
},
{
type: 'list',
name: 'type',
message: blue('What generation algorithm would you like to use?'),
choices: [
new Separator('-- Mazes --'),
'DividedMaze',
'IceyMaze',
'EllerMaze',
new Separator('-- Dungeons --'),
'Digger',
'Uniform',
'Rogue',
new Separator('-- Other --'),
'Arena',
'Cellular'
]
}
]

inquirer.prompt(questions)
.then(console.log)
.catch(console.error)

prompts.next({
type: 'input',
name: 'areaTitle',
message: blue('What would you like to title this area?'),
validate: isAlphanumeric,
})

prompts.complete()
5 changes: 4 additions & 1 deletion bin/validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
isAlphanumeric(input) {
const alphanumeric = /^[0-9a-zA-Z]+$/
return input.match(alphanumeric)
return Boolean(input.match(alphanumeric)) || 'Please enter an alphanumeric string.'
},
isNumber(input) {
return !isNaN(parseInt(input, 10)) || 'Please enter a number.'
}
}
59 changes: 39 additions & 20 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"dashify": "^1.0.0",
"find-config": "^1.0.0",
"js-yaml": "^3.10.0",
"rot-js": "^0.6.5"
"loglevel": "^1.6.1",
"requires-node-version": "^1.0.0",
"rot-js": "^0.6.5",
"rxjs": "^5.5.6"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down

0 comments on commit d9aa3ea

Please sign in to comment.