Comparing version 0.4.1 to 0.5.0
16
index.js
@@ -24,3 +24,4 @@ const generator = require('./src/generator') | ||
* @property {number} [roomDugPercentage] Percentage in decimal of map coordinates to be turned into rooms. Defaults to 0.25 (25%). | ||
* @property {timeLimit} [number] Amount of ms to wait for the ROT-js map generator algorithms to complete before giving up. Defaults to 60,000 (one minute). | ||
* @property {number} [timeLimit] Amount of ms to wait for the ROT-js map generator algorithms to complete before giving up. Defaults to 60,000 (one minute). | ||
* @property {Object} [weightedRoomsTable] A table of room ids to their title, description, and "weight" as used by the ROT-js RNG. | ||
*/ | ||
@@ -40,10 +41,13 @@ | ||
const { | ||
writeToFile = false, | ||
areaTitle = 'Generated Area', | ||
areaInfo = {} | ||
} = configuredOptions | ||
const manifest = { | ||
title: options.areaTitle || 'Generated Area', | ||
info: typeof areaInfo === 'object' ? areaInfo : null | ||
title: areaTitle || 'Generated Area', | ||
info: areaInfo && typeof areaInfo === 'object' ? areaInfo : {} | ||
} | ||
const { | ||
writeToFile = false | ||
} = configuredOptions | ||
@@ -50,0 +54,0 @@ const {graphic, rooms} = generator(configuredOptions) |
{ | ||
"name": "axolemma", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "A tool to procedurally generate areas compatible with the Ranvier MUD engine.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -81,2 +81,50 @@ Axolemma | ||
## Room Templates & Weighted Tables | ||
As of version 0.5.0, it is possible to use Axolemma to procedurally generate an area with multiple kinds of rooms. See `examples/template-areas/json` for the full example, but it works like this: | ||
```javascript | ||
// .axolemmaconfig.js | ||
module.exports = { | ||
type: 'Digger', | ||
areaTitle: 'Abandoned Mines', | ||
// ... more options | ||
// You could probably inline this but I like to keep 'em separated. | ||
weightedRoomsTable: require('./rooms-table') | ||
} | ||
// rooms-table.js | ||
// These numbers are arbitrary. | ||
// Lower = more rare, higher = more common. | ||
// You could use any scale you want, these numbers could be | ||
// 10, 50, 100. Feel free to get more granular. | ||
const COMMON = 5 | ||
const UNCOMMON = 3 | ||
const RARE = 1 | ||
module.exports = { | ||
mineshaft: { | ||
weight: UNCOMMON, | ||
title: 'Abandoned Mineshaft', | ||
description: 'A dark pit looms below you, boarded over by loose planks. The walls around you bear the marks of generations worth of pickaxes.' | ||
}, | ||
minefloor: { | ||
weight: COMMON, | ||
// ... | ||
}, | ||
oredeposit: { | ||
weight: RARE, | ||
// ... | ||
} | ||
}; | ||
``` | ||
Based on this example, Axolemma will output an area with rooms featuring the properties specified in room-table.js. While it is pseudo-random, approximately 1 out of every 9 rooms will be an ore deposit, 3 out of 9 will be mineshafts, and 5 out of 9 will be a boring floor with rocks on it. | ||
Future goals for this include adding arbitrary properties to the room templates, so that one could specify which NPCs are in a room, which scripts, and more. | ||
## Misc. | ||
@@ -92,2 +140,2 @@ | ||
See the `examples` directory for code snippets that can be used to make Axolemma play nice with Ranvier. | ||
See the `examples` directory for code snippets that can be used to make Axolemma play nice with Ranvier, and additional how-tos. |
@@ -30,3 +30,4 @@ const ROT = require('rot-js') | ||
corridorLengthMaximum, | ||
regularity | ||
regularity, | ||
weightedRoomsTable, | ||
} = options | ||
@@ -53,3 +54,3 @@ | ||
genericRoomTitle, | ||
genericRoomDesc | ||
genericRoomDesc, | ||
}) | ||
@@ -62,3 +63,4 @@ | ||
width, | ||
height | ||
height, | ||
weightedRoomsTable | ||
}) | ||
@@ -65,0 +67,0 @@ try { |
@@ -0,1 +1,3 @@ | ||
const ROT = require('rot-js') | ||
const Room = require('./room') | ||
@@ -27,17 +29,59 @@ const {noop} = require('../util') | ||
create (mapper) { | ||
let id = 0 | ||
mapper.create((x, y, value) => { | ||
if (value) return // Already done. | ||
const title = this.config.title | ||
const description = this.config.description | ||
const room = new Room({ | ||
title, | ||
description | ||
}) | ||
this.map[x][y] = room | ||
room.setCoordinates(x, y, this.zLevel) | ||
room.setId(id++) | ||
const creationCallback = this.config.weightedRoomsTable | ||
? this.weightedCreation.bind(this) | ||
: this.defaultCreation.bind(this) | ||
this._id = 0; | ||
mapper.create(creationCallback) | ||
} | ||
defaultCreation (x, y, value) { | ||
if (value) return // Already done. | ||
const { title, description } = this.config | ||
const room = new Room({ | ||
title, | ||
description | ||
}) | ||
this.map[x][y] = room | ||
room.setCoordinates(x, y, this.zLevel) | ||
room.setId(this._id++) | ||
} | ||
weightedCreation (x, y, value) { | ||
if (value) return // Already done. | ||
const pick = ROT.RNG.getWeightedValue(this.getWeightedTable()) | ||
const { | ||
title = this.config.title, | ||
description = this.config.description | ||
} = this.config.weightedRoomsTable[pick]; | ||
const room = new Room({ | ||
title, | ||
description | ||
}) | ||
this.map[x][y] = room | ||
room.setCoordinates(x, y, this.zLevel) | ||
room.setId(this._id++) | ||
} | ||
getWeightedTable () { | ||
if (!this._weightedTable){ | ||
this._weightedTable = {} | ||
for (const [id, def] of Object.entries(this.config.weightedRoomsTable)) { | ||
if (!def.weight) { | ||
console.log('Invalid or missing weight for ', id) | ||
continue; | ||
} | ||
this._weightedTable[id] = def.weight | ||
} | ||
} | ||
return this._weightedTable | ||
} | ||
iterate (roomCallback = noop, rowCallback = noop) { | ||
@@ -44,0 +88,0 @@ for (const row of this.map) { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
21
139
160744
456
8
1