Changing tiled extension to supported javascript.
This commit is contained in:
parent
4959a01ac6
commit
e4e07ac11c
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "Copying extension to tiled directory"
|
||||||
|
cp "json_export_tool.mjs" "$HOME/.config/tiled/extensions/."
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
var customMapFormat = {
|
||||||
|
name: "Custom map format",
|
||||||
|
extension: "custom",
|
||||||
|
|
||||||
|
write: function(map, fileName)
|
||||||
|
{
|
||||||
|
var file = new TextFile(fileName, TextFile.WriteOnly);
|
||||||
|
|
||||||
|
file.writeLine("{");
|
||||||
|
file.writeLine(" \"MapWidth\": " + map.width + ",");
|
||||||
|
file.writeLine(" \"MapHeight\": " + map.height + ",");
|
||||||
|
file.writeLine("");
|
||||||
|
|
||||||
|
for(var i = 0; i < map.layerCount; i++)
|
||||||
|
{
|
||||||
|
var layer = map.layerAt(i);
|
||||||
|
|
||||||
|
if(layer.isTileLayer)
|
||||||
|
{
|
||||||
|
file.writeLine(" \"" + layer.name + "\": [");
|
||||||
|
|
||||||
|
for(var cell_y = 0; cell_y < layer.height; ++cell_y)
|
||||||
|
{
|
||||||
|
file.write(" ");
|
||||||
|
|
||||||
|
for (var cell_x = 0; cell_x < layer.width; ++cell_x)
|
||||||
|
{
|
||||||
|
file.write(" " + layer.cellAt(cell_x, cell_y).tileId)
|
||||||
|
if(cell_x < layer.width - 1 || cell_y < layer.height - 1)
|
||||||
|
file.write(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
file.writeLine("");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i < map.layerCount - 1)
|
||||||
|
file.writeLine(" ],");
|
||||||
|
else
|
||||||
|
file.writeLine(" ]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write("}");
|
||||||
|
file.commit();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tiled.registerMapFormat("custom", customMapFormat)
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
#!/usr/bin/bash
|
|
||||||
|
|
||||||
echo "Creating \"~/.tiled\" directory"
|
|
||||||
mkdir -p $HOME/.tiled/
|
|
||||||
|
|
||||||
echo "Copying extension to tiled directory"
|
|
||||||
cp "json_export_tool.py" "$HOME/.tiled/"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Don't forget to activate python in tiled !"
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
from tiled import *
|
|
||||||
|
|
||||||
class Json_Export_Tool(Plugin):
|
|
||||||
@classmethod
|
|
||||||
def nameFilter(cls):
|
|
||||||
return "Json files (*.json)"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def shortName(cls):
|
|
||||||
return "json"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def write(cls, tileMap, fileName):
|
|
||||||
with open(fileName, 'w') as fileHandle:
|
|
||||||
print("{", file=fileHandle)
|
|
||||||
print(f' "MapWidth": {tileMap.width()},', file=fileHandle)
|
|
||||||
print(f' "MapHeight": {tileMap.height()},\n', file=fileHandle)
|
|
||||||
|
|
||||||
for i in range(tileMap.layerCount()):
|
|
||||||
if isTileLayerAt(tileMap, i):
|
|
||||||
tileLayer = tileLayerAt(tileMap, i)
|
|
||||||
print(f' "{tileLayer.name()}": [', file=fileHandle)
|
|
||||||
for cell_y in range(tileLayer.height()):
|
|
||||||
row = []
|
|
||||||
for cell_x in range(tileLayer.width()):
|
|
||||||
row.append(tileLayer.cellAt(cell_x, cell_y).tile().id())
|
|
||||||
print(" " + ", ".join(str(tile) for tile in row) + ("," if cell_y != (tileLayer.height() - 1) else ""), file=fileHandle)
|
|
||||||
print(" ]," if i != (tileMap.layerCount() - 1) else " ]", file=fileHandle)
|
|
||||||
print("}", file=fileHandle)
|
|
||||||
|
|
||||||
return True
|
|
||||||
Loading…
Reference in New Issue