-
Notifications
You must be signed in to change notification settings - Fork 24
/
videogame-format.js
47 lines (36 loc) · 1.01 KB
/
videogame-format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// <reference types="@mapeditor/tiled-api" />
/*
* videogame-format.js
*
* This extension adds the 'videogame map format' type to the Export As menu,
* which can be used to generate matrix maps as used by the Scene.build()
* method from the videogame library (https://github.com/diogoeichert/videogame)
*/
tiled.registerMapFormat("videogame", {
name: "videogame map format",
extension: "json",
write: (map, fileName) => {
for (let i = 0; i < map.layerCount; ++i) {
const layer = map.layerAt(i);
if (!layer.isTileLayer) {
continue;
}
var file = new TextFile(fileName, TextFile.WriteOnly);
file.writeLine("[");
for (let y = 0; y < layer.height; ++y) {
const row = [];
for (let x = 0; x < layer.width; ++x) {
const tile = layer.tileAt(x, y);
let id = " ";
if (tile) {
id = FileInfo.baseName(tile.imageFileName);
}
row.push(`"${id}"`);
}
file.writeLine("\t[" + row.join(", ") + "],");
}
file.writeLine("]");
file.commit();
}
},
});