neilpopham

See https://www.lexaloffle.com/bbs/?pid=75111#p

Apr 23rd, 2020
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var customMapFormat = {
  2.     name: "PICO-8 Map Format",
  3.     extension: "p8",
  4.     write: function(map, fileName) {
  5.         var layer = map.layerAt(0);
  6.          var m = 'pico-8 cartridge // http://www.pico-8.com\n'
  7.             + 'version 21\n'
  8.             + '__lua__\n'
  9.             + '-- Exported from Tiled\n\n'
  10.             + '__gfx__\n\n'
  11.             + '__map__\n';
  12.         for (y = 0; y < layer.height; ++y) {
  13.             for (x = 0; x < layer.width; ++x) {
  14.                 m += (layer.cellAt(x, y).tileId > 0)
  15.                     ? layer.cellAt(x, y).tileId.toString(16).padStart(2, 0)
  16.                     : '00';
  17.             }
  18.             m += '\n'
  19.         }
  20.         var file = new TextFile(fileName, TextFile.WriteOnly);
  21.         file.write(m);
  22.         file.commit();
  23.     },
  24. }
  25.  
  26. tiled.registerMapFormat("pico8", customMapFormat)
Add Comment
Please, Sign In to add comment