Comparing version 0.2.0 to 0.3.0
37
index.js
@@ -20,2 +20,4 @@ const generator = require('./src/generator') | ||
* @property {Object} [areaInfo] Info object for area manifest. Defaults to object with respawnInterval property set to 60. | ||
* @property {string} [genericRoomTitle] A title to be used for all of the rooms in your generated area. Defaults to 'An Empty Room'. | ||
* @property {string} [genericRoomDesc] A description to be used for all of the rooms in your generated area. Defaults to 'There is nothing particularly interesting about this place.' | ||
* @property {string} [type] The 'type' of map creator to use. This must be the name of a ROT-js Map constructor. Defaults to 'Uniform'. | ||
@@ -26,8 +28,2 @@ * @property {number} [roomDugPercentage] Percentage in decimal of map coordinates to be turned into rooms. Defaults to 0.25 (25%). | ||
/** | ||
* @typedef {Function} AsyncFunction | ||
* @returns {Promise} | ||
* @async | ||
*/ | ||
module.exports = { | ||
@@ -37,6 +33,5 @@ /** | ||
* @param {AxolemmaOptions} [options] | ||
* @param {AsyncFunction} [promptAsync] | ||
* @async | ||
* @param {Boolean} [giveCallback] | ||
*/ | ||
async generate (options = {}, promptAsync = resolveTrue) { | ||
generate (options = {}, giveCallback) { | ||
const configuredOptions = Object.assign({}, | ||
@@ -51,14 +46,16 @@ getOptions(), | ||
let goAhead = false | ||
while (!goAhead) { | ||
const {graphic, rooms} = generator(configuredOptions) | ||
console.log(`Generated an area with ${rooms.length} rooms.\n${graphic}`) | ||
goAhead = await promptAsync(graphic, rooms.length) | ||
if (goAhead) { | ||
const yaml = parse(configuredOptions, rooms) | ||
if (writeToFile) { | ||
write(yaml, configuredOptions) | ||
} | ||
return { graphic, rooms, yaml } | ||
const {graphic, rooms} = generator(configuredOptions) | ||
console.log(`Generated an area with ${rooms.length} rooms.\n${graphic}`) | ||
if (giveCallback) { | ||
return {graphic, rooms, buildCallback} | ||
} | ||
return buildCallback(configuredOptions.writeToFile) | ||
function buildCallback(shouldWrite) { | ||
const yaml = parse(configuredOptions, rooms) | ||
if (shouldWrite) { | ||
write(yaml, configuredOptions) | ||
} | ||
return { graphic, rooms, yaml } | ||
} | ||
@@ -65,0 +62,0 @@ }, |
{ | ||
"name": "axolemma", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A tool to procedurally generate areas compatible with the Ranvier MUD engine.", | ||
"main": "index.js", | ||
"bin": { | ||
"axolemma": "bin/axolemma" | ||
}, | ||
"scripts": { | ||
"test": "mocha ./**/*.spec.js", | ||
"test": "mocha ./src/**/*.spec.js", | ||
"lint": "standard ./**/*.js --fix" | ||
@@ -25,3 +28,7 @@ }, | ||
"js-yaml": "^3.10.0", | ||
"rot-js": "^0.6.5" | ||
"loglevel": "^1.6.1", | ||
"pretty-print": "^1.1.0", | ||
"requires-node-version": "^1.0.0", | ||
"rot-js": "^0.6.5", | ||
"rxjs": "^5.5.6" | ||
}, | ||
@@ -28,0 +35,0 @@ "devDependencies": { |
@@ -14,2 +14,12 @@ Axolemma | ||
Axolemma is usable as a CLI tool and can also be used as a library. | ||
To use it as a CLI tool, navigate to the working directory where you would like Axolemma to generate the map files, and type `axolemma`. | ||
Axolemma will ask a series of questions and, as a result, generate an area for you. | ||
![screenshot](./screenshot.png) | ||
Here is a recipe for using Axolemma programmatically: | ||
```javascript | ||
@@ -19,13 +29,18 @@ // Require-able like any other library. | ||
Axolemma.generate({ // Programmatically pass in options | ||
const {graphic, rooms, yaml} = Axolemma.generate({ // Programmatically pass in options | ||
type: 'Digger' // Uses ROT-js well-documented map generation algorithms. | ||
writeToFile: true // Can write YAML definitions to file for static persistence | ||
}).then(function(data) { // Returns an await-able Promise | ||
const {graphic, rooms, yaml} = data | ||
console.log(graphic) // Returns an old-school ASCII map of your area. | ||
console.log(yaml) // Returns parsed YAML. | ||
return rooms.map( | ||
roomDef => new Room(roomDef) // Returns Ranvier-compatible room definitions. | ||
) | ||
}) | ||
// Returns an old-school ASCII map of your area. | ||
console.log(graphic) | ||
// Returns YAML string. | ||
console.log(yaml) | ||
// Returns Ranvier-compatible room definitions. | ||
const newRooms = rooms.map( | ||
roomDef => new Room(roomDef) | ||
); | ||
``` | ||
@@ -37,3 +52,3 @@ | ||
Your `.axolemmaconfig` can be either a JavaScript module or a JSON file. Axolemma will crawl up the tree to find the file so it can be in the root of your Ranvier bundle, the root of your fork of Ranvier, or even in your home directory. | ||
Your `.axolemmaconfig` can be either a JavaScript module or a JSON file. Axolemma will crawl up the directory tree to find the file so it can be in the root directory of your Ranvier bundle, the root of your fork of Ranvier, or even in your user home directory. It will use the 'nearest' config it finds, so you can have multiple configurations at different nesting levels. | ||
@@ -57,2 +72,4 @@ Configuration precedence goes as follows: | ||
* @property {Object} [areaInfo] Info object for area manifest. Defaults to object with respawnInterval property set to 60. | ||
* @property {string} [genericRoomTitle] A title to be used for all of the rooms in your generated area. Defaults to 'An Empty Room'. | ||
* @property {string} [genericRoomDesc] A description to be used for all of the rooms in your generated area. Defaults to 'There is nothing particularly interesting about this place.' | ||
* @property {string} [type] The 'type' of map creator to use. This must be the name of a ROT-js Map constructor. Defaults to 'Uniform'. | ||
@@ -59,0 +76,0 @@ * @property {number} [roomDugPercentage] Percentage in decimal of map coordinates to be turned into rooms. Defaults to 0.25 (25%). |
@@ -13,3 +13,3 @@ const findConfig = require('find-config') | ||
*/ | ||
getOptions() { | ||
getOptions () { | ||
const configFinderOptions = { | ||
@@ -20,5 +20,18 @@ home: true, | ||
const axConfig = require(findConfig('.axolemmaconfig', configFinderOptions)) || {} | ||
const pkg = require(findConfig('package.json', configFinderOptions)) || {} | ||
console.log({axConfig, pkg}) | ||
const axConfigPath = findConfig('.axolemmaconfig', configFinderOptions); | ||
const pkgPath = findConfig('package.json', configFinderOptions); | ||
let axConfig = {} | ||
let pkg = {} | ||
if (axConfigPath) { | ||
axConfig = require(axConfigPath) | ||
} | ||
if (pkgPath) { | ||
pkg = require(pkgPath) | ||
} | ||
const pkgConfig = typeof pkg.axolemma === 'object' | ||
? pkg.axolemma | ||
: {} | ||
return Object.assign({}, | ||
@@ -29,2 +42,2 @@ axConfig, | ||
} | ||
} | ||
} |
@@ -19,4 +19,14 @@ const ROT = require('rot-js') | ||
roomDugPercentage = 0.25, | ||
dugPercentage = 0.25, | ||
timeLimit = 60 * 1000, | ||
mapperOptions = {} | ||
mapperOptions = {}, | ||
genericRoomTitle = 'An Empty Room', | ||
genericRoomDesc = 'There is nothing particularly interesting about this place.', | ||
roomHeightMaximum, | ||
roomHeightMinimum, | ||
roomWidthMaximum, | ||
roomWidthMinimum, | ||
corridorLengthMinimum, | ||
corridorLengthMaximum, | ||
regularity | ||
} = options | ||
@@ -32,12 +42,29 @@ | ||
const _mapperOptions = Object.assign({}, mapperOptions, { | ||
roomDugPercentage, timeLimit | ||
roomHeightMaximum, | ||
roomHeightMinimum, | ||
roomWidthMaximum, | ||
roomWidthMinimum, | ||
corridorLengthMinimum, | ||
corridorLengthMaximum, | ||
regularity, | ||
dugPercentage, | ||
roomDugPercentage, | ||
timeLimit, | ||
genericRoomTitle, | ||
genericRoomDesc | ||
}) | ||
const mapper = new Mapper(width, height, _mapperOptions) | ||
const map = new Map2D({width, height}) | ||
const map = new Map2D({ | ||
title: genericRoomTitle, | ||
description: genericRoomDesc, | ||
width, | ||
height | ||
}) | ||
try { | ||
map.create(mapper) | ||
} catch (error) { | ||
console.log(`Error when creating map. Please ensure options are correct for ROT-js map type ${type}.`) | ||
throw error | ||
const msg = `Error when creating map. Please ensure options are correct for ROT-js map type ${type}.` | ||
console.log(msg) | ||
throw error || msg | ||
} | ||
@@ -44,0 +71,0 @@ |
@@ -6,2 +6,3 @@ const Room = require('./room') | ||
constructor (config = {}) { | ||
this.config = config | ||
const {height, width, zLevel = 0} = config | ||
@@ -30,3 +31,8 @@ this.height = height | ||
if (value) return // Already done. | ||
const room = new Room() | ||
const title = this.config.title | ||
const description = this.config.description | ||
const room = new Room({ | ||
title, | ||
description | ||
}) | ||
this.map[x][y] = room | ||
@@ -33,0 +39,0 @@ room.setCoordinates(x, y, this.zLevel) |
const dashify = require('dashify') | ||
module.exports = class Room { | ||
constructor () { | ||
this.title = 'An Empty Room' | ||
this.description = 'There is nothing particularly interesting about this place.' | ||
constructor (config) { | ||
this.title = config.title | ||
this.description = config.description | ||
this.x = NaN | ||
@@ -8,0 +8,0 @@ this.y = NaN |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
154521
15
337
83
8
+ Addedloglevel@^1.6.1
+ Addedpretty-print@^1.1.0
+ Addedrequires-node-version@^1.0.0
+ Addedrxjs@^5.5.6
+ Addedansi-styles@0.2.03.2.1(transitive)
+ Addedas-array@2.0.0(transitive)
+ Addedchalk@0.3.02.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfeedback@0.3.2(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedlodash@2.2.1(transitive)
+ Addedloglevel@1.9.2(transitive)
+ Addedpretty-print@1.1.0(transitive)
+ Addedrequires-node-version@1.0.0(transitive)
+ Addedrxjs@5.5.12(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsymbol-observable@1.0.1(transitive)