-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from seanohue/develop
Develop
- Loading branch information
Showing
4 changed files
with
139 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters