-
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.
Refactoring to match eslint and adding version
- Loading branch information
Showing
17 changed files
with
1,569 additions
and
176 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"plugins": [ | ||
"import" | ||
], | ||
"rules": { | ||
"import/no-dynamic-require": 0, | ||
"import/newline-after-import": 0, | ||
"no-extend-native": 0, | ||
"func-names": 0, | ||
"no-bitwise": 0, | ||
"global-require": 0, | ||
"max-len": 0, | ||
"no-param-reassign": 0, | ||
"no-underscore-dangle": 0, | ||
"class-methods-use-this": 0 | ||
} | ||
} |
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
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
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
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
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
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
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
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,125 +1,24 @@ | ||
const fs = require('fs'); | ||
const program = require('commander'); | ||
const questions = require('questions'); | ||
const numeral = require('numeral'); | ||
const colors = require('colors/safe'); | ||
const path = require('path'); | ||
const rootDir = path.join(__dirname, '..'); | ||
const libDir = path.join(rootDir, 'lib'); | ||
const pinfo = require(path.join(rootDir, 'package.json')); | ||
const Dominia = require(path.join(libDir, 'dominia')); | ||
const Saver = require(path.join(libDir, 'saver')); | ||
const Renderer = require(path.join(libDir, 'renderer')); | ||
const defaults = require(path.join(libDir, 'defaults')); | ||
const logo = fs.readFileSync(path.join(rootDir, 'logo.txt'), { encoding: 'utf-8' }); | ||
const { measurements } = defaults; | ||
const wizard = require(path.join(libDir, 'wizard')); | ||
|
||
// program basics | ||
program | ||
.version(pinfo.version, '-v, --version') | ||
.description(pinfo.description) | ||
.option('-i, --input <file>', 'input *.dom file') | ||
.option('-o, --output <dir>', 'output directory') | ||
.option('-r, --renderer <renderer>', 'which render to use default or json') | ||
.parse(process.argv); | ||
|
||
let { input, output, renderer } = program; | ||
let dominia; | ||
|
||
const themes = ['asian', 'classical', 'medieval', 'nirimsese', 'scottish']; | ||
|
||
// check the input | ||
if (input !== undefined) { | ||
dominia = Saver.load(input); | ||
Renderer.render(dominia, renderer); | ||
// load a file or go through the wizard | ||
if (program.input !== undefined) { | ||
const dominia = Saver.load(program.input); | ||
Renderer.output(dominia); | ||
} else { | ||
|
||
// output welcome | ||
console.log('\n' + colors.cyan(logo) + '\n'); | ||
|
||
// define a default output dir | ||
if (output === undefined) output = '.'; | ||
|
||
// ask a few questions | ||
questions.askMany({ | ||
size: { | ||
info: colors.cyan('What size domain do you want to generate?') + colors.white(' (' + Object.keys(measurements.sizes).join(' | ') + ')'), | ||
required: false | ||
}, | ||
|
||
population: { | ||
info: colors.cyan('Would you like to specify the population?') + colors.white(' ex: input 50,000 (people)'), | ||
required: false | ||
}, | ||
|
||
theme: { | ||
info: colors.cyan('What theme would you like?') + colors.white(' (' + themes.join(' | ') + ')'), | ||
required: false | ||
}, | ||
|
||
name: { | ||
info: colors.cyan('Would you like to use an existing name?') + colors.white(' ex: Allaria, leave blank to generate'), | ||
required: false | ||
}, | ||
|
||
prosperity: { | ||
info: colors.cyan('Would you like to specify the prosperity?') + colors.white(' (' + defaults.prosperity.join(' | ') + ')'), | ||
required: false | ||
}, | ||
|
||
terrain: { | ||
info: colors.cyan('Would you like to specify the terrain?') + colors.white(' (' + defaults.terrains.join(' | ') + ')'), | ||
required: false | ||
}, | ||
|
||
resources: { | ||
info: colors.cyan('Would you like to specify the resources?') + colors.white(' separate with comma (' + defaults.resources.join(' | ') + ')'), | ||
required: false | ||
}, | ||
|
||
density: { | ||
info: colors.cyan('Would you like to specify the density?') + colors.white(' ex: input 75 (people per sqmi)'), | ||
required: false | ||
}, | ||
|
||
land: { | ||
info: colors.cyan('Would you like to specify the total land area?') + colors.white(' ex: input 1,000,000 (sqmi)'), | ||
required: false | ||
}, | ||
}, (opts) => { | ||
|
||
// manage the opts | ||
opts.size = (opts.size === '') ? undefined : opts.size.toLowerCase(); | ||
opts.name = (opts.name === '') ? undefined : opts.name; | ||
opts.theme = (opts.theme === '') ? undefined : opts.theme.toLowerCase(); | ||
opts.population = (opts.population === '') ? undefined : numeral(opts.population).value(); | ||
opts.density = (opts.density === '') ? undefined : numeral(opts.density).value(); | ||
opts.land = (opts.land === '') ? undefined : numeral(opts.land).value(); | ||
opts.terrain = (opts.terrain === '') ? undefined : opts.terrain; | ||
opts.resources = (opts.resources === '') ? undefined : opts.resources.split(', '); | ||
|
||
/* Calculations: | ||
* L = 10 sqmi | ||
* P = 500 people | ||
* D = 50 people per sqmi | ||
* | ||
* Formulas: | ||
* L = P / D ex: 10 = 500 / 50 | ||
* P = D * L ex: 500 = 50 * 10 | ||
* D = P / L ex: 50 = 500 / 10 | ||
*/ | ||
// calculate land from pop and density | ||
if ((opts.land === undefined) && opts.population && opts.density) opts.land = opts.population / opts.density; | ||
|
||
// calculate pop from land and density | ||
if ((opts.population === undefined) && opts.land && opts.density) opts.population = opts.land * opts.density; | ||
|
||
// calculate density from land and population | ||
if ((opts.density === undefined) && opts.land && opts.population) opts.density = opts.population / opts.land; | ||
|
||
// generate | ||
dominia = new Dominia(opts).generate(); | ||
Renderer.render(dominia, renderer); | ||
Saver.finish(output, 'Would you like to save your domain? (y | n)', dominia, dominia.name); | ||
}); | ||
} | ||
wizard(program.output); | ||
} |
Oops, something went wrong.