Skip to content

Commit

Permalink
Working on passing defaults and fixing packages
Browse files Browse the repository at this point in the history
  • Loading branch information
drewry committed Jun 10, 2018
1 parent 335783b commit 1f047b4
Show file tree
Hide file tree
Showing 8 changed files with 721 additions and 763 deletions.
4 changes: 1 addition & 3 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fs = require('fs');
const path = require('path');
const Nomina = require('nomina');
const nomina = new Nomina();
const rootDir = path.join(__dirname, '..');
const libDir = path.join(rootDir, 'lib');
const home = process.env.HOME || process.env.USERPROFILE;
Expand All @@ -28,7 +29,4 @@ if (fs.existsSync(userPath)) {
defaults = require(path.join(libDir, 'defaults-default'));
}

// add themes from nomina
defaults.themes = Nomina.getThemes();

module.exports = defaults;
10 changes: 8 additions & 2 deletions lib/dominia.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const Generator = require('./generator');
const defaults = require('./defaults');
const { measurements } = defaults;

class Dominia {
constructor(opts = {}) {
this.opts = opts;
this.defaults = opts.defaults || defaults;
this.defaultsNomina = opts.defaultsNomina;
}

generate(opts = {}) {
opts = Object.assign(this.opts, opts);
const { size } = opts;

this.generator = new Generator();
this.generator = new Generator({
defaults: this.defaults,
defaultsNomina: this.defaultsNomina,
});

switch (size) {
case 'hamlet':
Expand Down Expand Up @@ -144,6 +148,7 @@ class Dominia {

// used to recursively generate localities based on population
generateLocalities(popCount = 0, localities = []) {
const { measurements } = this.defaults;
const multiplier = 1.3;
const maxPop = popCount * 0.7;
let locality;
Expand Down Expand Up @@ -192,6 +197,7 @@ class Dominia {

// used to recursively generate demesnes based on population
generateDemesnes(popCount = 0, demesnes = []) {
const { measurements } = this.defaults;
const multiplier = 1.3;
let maxPop = popCount * 0.7;
let demesne;
Expand Down
14 changes: 11 additions & 3 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ const Resources = require(path.join(libDir, 'resources'));
const defaults = require(path.join(libDir, 'defaults'));

class Generator {
constructor(opts = {}) {
this.defaults = opts.defaults || defaults;
this.names = new Names({
defaults: this.defaults,
defaultsNomina: opts.defaultsNomina,
});
}

primitive(opts = {}) {
const { version } = pinfo;
const { scale, size } = opts;

// generate name
const nameOpts = Object.assign(opts, {});
const name = Names.generate(nameOpts);
const name = this.names.generate(nameOpts);

// generate population
const popOpts = Object.assign(opts, {});
Expand All @@ -29,7 +37,7 @@ class Generator {
const geography = Geography.generate(geoOpts);

// generate prosperity
const prosperity = opts.prosperity || defaults.prosperity.sample();
const prosperity = opts.prosperity || this.defaults.prosperity.sample();

// set the primitive
let primitive = {
Expand All @@ -44,7 +52,7 @@ class Generator {

// generate demographics if locality
if (scale === 'locality') {
const terrain = opts.terrain || defaults.terrains.sample();
const terrain = opts.terrain || this.defaults.terrains.sample();
const resources = opts.resources || Resources.generate({ terrain });

// demographic opts
Expand Down
11 changes: 8 additions & 3 deletions lib/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ const Nomina = require('nomina');
const defaults = require('./defaults');

class Names {
static generate(opts = {}) {
const theme = opts.theme || defaults.themes.sample();
constructor(opts = {}) {
this.defaults = opts.defaults || defaults;
this.nomina = new Nomina({ defaults: opts.defaultsNomina });
}

generate(opts = {}) {
const theme = opts.theme || this.nomina.getThemes().sample();

const name = Nomina.generate({
const name = this.nomina.generate({
theme,
type: 'dominia',
});
Expand Down
5 changes: 4 additions & 1 deletion lib/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ 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 Nomina = require('nomina');
const nomina = new Nomina();
const themes = nomina.getThemes();
const { measurements } = defaults;

const wizard = (outputDir) => {
Expand All @@ -31,7 +34,7 @@ const wizard = (outputDir) => {
},

theme: {
info: colors.cyan('What theme would you like?') + colors.white(` (${defaults.themes.join(' | ')})`),
info: colors.cyan('What theme would you like?') + colors.white(` (${themes.join(' | ')})`),
required: false,
},

Expand Down
Loading

0 comments on commit 1f047b4

Please sign in to comment.