Created
July 10, 2021 17:44
-
-
Save sleepycrow/d547d5daddbd7bd695ee9111b52235b7 to your computer and use it in GitHub Desktop.
A Tiled extension for exporting CyTube MMO format maps.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* koton.js | |
* | |
* A Tiled (https://www.mapeditor.org/) extension for exporting CyTube MMO format maps. | |
* | |
* Usage: | |
* 1) Create a new map with two tile layers - "map" and "collision". On "map", | |
* just draw the map, and on "collision" - with any tile - draw over the tiles | |
* that the player shouldn't be able to pass through. | |
* 2) When done, export the map as a 'koton map format (*.js)' file. | |
* 3) Copy the contents of the newly generated file, then paste them into your | |
* into your map's 'tilemap' key | |
*/ | |
/* global tiled, FileInfo, TextFile */ | |
tiled.registerMapFormat("cymmo", { | |
name: "cytube mmo map format", | |
extension: "js", | |
write: (map, fileName) => { | |
var output = {}; | |
var file = new TextFile(fileName, TextFile.WriteOnly); | |
file.writeLine("{"); | |
for(let i = 0; i < map.layerCount; i++){ | |
const layer = map.layerAt(i); | |
const collisionLayer = (layer.name == 'collision'); | |
if(!layer.isTileLayer) continue; | |
file.writeLine('\t"' + layer.name + '": ['); | |
for (let y = 0; y < layer.height; y++) { | |
var row = []; | |
for (let x = 0; x < layer.width; x++) { | |
var tile = layer.tileAt(x, y); | |
let tId = (tile != null ? tile.id + 1 : 0); | |
if(collisionLayer) | |
tId = (tId > 0 ? 1 : 0); | |
row.push(tId); | |
} | |
file.writeLine('\t\t[' + row.join(',') + ']' + (y < layer.height-1 ? ',' : '')); | |
} | |
file.writeLine('\t]' + (i < map.layerCount-1 ? ',' : '')); | |
} | |
file.writeLine('}'); | |
file.commit(); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment