Created
September 17, 2023 16:54
-
-
Save Enichan/a03faad508f4dc0d4757864415e47d62 to your computer and use it in GitHub Desktop.
Tiny Tiled Map Editor binary exporter plugin
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
var binaryFormat = { | |
name: "jRPG binary format", | |
extension: "bin", | |
write: function(map, fileName) { | |
var m = { | |
width: map.width, | |
height: map.height, | |
layers: [] | |
}; | |
var arr = new Uint16Array(map.width * map.height * map.layerCount + 3); | |
var index = 0; | |
arr[index++] = map.width; | |
arr[index++] = map.height; | |
arr[index++] = map.layerCount; | |
for (var i = 0; i < map.layerCount; ++i) { | |
var layer = map.layerAt(i); | |
if (layer.isTileLayer) { | |
for (y = 0; y < map.height; y++) { | |
for (x = 0; x < map.width; x++) { | |
var id = 0; | |
var tile = layer.tileAt(x, y); | |
if (tile !== null) { | |
id = tile.id + 1; | |
} | |
arr[index++] = id; | |
} | |
} | |
} | |
} | |
var bin = new BinaryFile(fileName, BinaryFile.WriteOnly); | |
bin.write(arr.buffer); | |
bin.commit(); | |
}, | |
} | |
tiled.registerMapFormat("jRPG", binaryFormat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment