Skip to content

Ziagl/tiled-map-generator

Repository files navigation

tiled-map-generator

A map generator for Tiled Map Editor (https://www.mapeditor.org/) files.

Sample of generated maps inside Tiled Map Editor:

Type: CONTINENTS_ISLANDS, Size: TINY Alt text

Sample code to create map

const fs = require('fs');
const tmg = require('@ziagl/tiled-map-generator');

// generate a new map
let generator = new tmg.Generator();
generator.generateMap(tmg.MapType.CONTINENTS_ISLANDS, tmg.MapSize.TINY);
const [map, rows, columns] = generator.exportMap();

// convert this map into a 2d array
let converter = new tmg.Converter();

// option 1: store it in a new json file based on example.json
const data = fs.readFileSync('example.json', 'utf8');
const result = converter.convertToTiled(map, rows, columns, data);

// option 2: create a new json string without template
const result = converter.generateTiledJson(map, rows, columns, 'tileset.png', 32, 34, 416, 34, 13, 13, "#ffffff");

fs.writeFileSync('map.json', result, 'utf-8', (err) => {
    if (err) {
        console.error('Error while writing map file:', err);
    }
});

// print out map as debug output on console
console.log(generator.print());

All possible map types as example images:

Type: ARCHIPELAGO, Size: TINY Alt text

Type: CONTINENTS, Size: TINY Alt text

Type: HIGHLAND, Size: TINY Alt text

Type: INLAND_SEA, Size: TINY Alt text

Type: ISLANDS, Size: TINY Alt text

Type: LAKES, Size: TINY Alt text

Type: SMALL_CONTINENTS, Size: TINY Alt text

Type: SUPER_CONTINENT, Size: TINY Alt text

About

A map generator for Tiled Map Editor files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published