habitants-map-generator

0.0.1 • Public • Published

Example

var Tile = require('habitants-tile');
var tiles = {};
 
// These are your own creations
var mapTemplate = require('./mapdata/map.json');
var tileTemplates = require('./mapdata/tiletypes.json');
 
// Just loop over the 2D array and create tiles with locations, referenced by geokey! i.e '4:8', '32:89'
mapTemplate.forEach(function (row, yi) {
    row.forEach(function (tileType, xi) {
        var tileTemplate = tileTemplates[tileType];
        tileTemplate.location = {
            x: xi,
            y: yi
        };
        var tile = new Tile(tileTemplate);
        tiles[tile.toString()] = tile;
    });
});
 
// Check some out!
console.log(tiles['1:1'], tiles['2:4'], tiles['5:7']);
{ blocking: false,
blocked: false,
type'grassland',
style: 'grass',
impedance: 1,
opacity: 0.02,
location: { x: 1, y: 1 },
units: [] }
 
{ blocking: false,
blocked: false,
type'grassland',
style: 'grass',
impedance: 1,
opacity: 0.02,
location: { x: 2, y: 4 },
units: [] }
 
{ blocking: false,
blocked: false,
type'grassland',
style: 'grass',
impedance: 1,
opacity: 0.02,
location: { x: 5, y: 7 },
units: [] }

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    1

Package Sidebar

Install

npm i habitants-map-generator

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • alexander-daniel