(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/// <reference path="../../typescript/typescriptAPI/TypeScriptAPIPlugin.d.ts" />

SupCore.system.registerPlugin("typescriptAPI", "Sup.TileMap", {
    code: "namespace Sup {\r\n  export class TileMap extends Asset {\r\n    getWidth() { return this.__inner.getWidth(); }\r\n    getHeight() { return this.__inner.getHeight(); }\r\n    getPixelsPerUnit() { return this.__inner.getPixelsPerUnit(); }\r\n    getLayerCount() { return this.__inner.data.layers.length; }\r\n\r\n    setTileAt(layer, x, y, value, flipX, flipY, angle) {\r\n      let tileSet = player.getOuterAsset(this.__inner.data.tileSetId);\r\n      let tilesPerRow = tileSet.__inner.data.texture.image.width / tileSet.__inner.data.grid.width;\r\n      if (value == -1) this.__inner.setTileAt(layer, x, y, 0);\r\n      else {\r\n        flipX = (flipX) ? flipX : false;\r\n        flipY = (flipY) ? flipY : false;\r\n        angle = (angle) ? angle : 0;\r\n        this.__inner.setTileAt(layer, x, y, [value % tilesPerRow, window.Math.floor(value / tilesPerRow), flipX, flipY, angle]);\r\n      }\r\n      return this;\r\n    }\r\n    getTileAt(layer, x, y) {\r\n      let tileSet = player.getOuterAsset(this.__inner.data.tileSetId);\r\n      let tilesPerRow = tileSet.__inner.data.texture.image.width / tileSet.__inner.data.grid.width;\r\n      let tilesPerColumn = tileSet.__inner.data.texture.image.height / tileSet.__inner.data.grid.height;\r\n      let transform = this.__inner.getTileAt(layer, x, y);\r\n      if (transform === 0) return -1;\r\n\r\n      let tileX = transform[0]; let tileY = transform[1];\r\n      if (tileX === -1 || tileY === -1 || tileY >= tilesPerColumn ||\r\n      (tileX === tilesPerRow - 1 && tileY === tilesPerColumn - 1))\r\n        return -1;\r\n\r\n      return tileY * tilesPerRow + tileX;\r\n    }\r\n    getTileTransformAt(layer, x, y) {\r\n      let tileSet = player.getOuterAsset(this.__inner.data.tileSetId);\r\n      let tilesPerRow = tileSet.__inner.data.texture.image.width / tileSet.__inner.data.grid.width;\r\n      let transform = this.__inner.getTileAt(layer, x, y);\r\n      return { \"flipX\": transform[2], \"flipY\": transform[3], \"angle\": transform[4] };\r\n    }\r\n  }\r\n}\r\n",
    defs: "declare namespace Sup {\r\n  class TileMap extends Asset {\r\n    getWidth(): number;\r\n    getHeight(): number;\r\n    getPixelsPerUnit(): number;\r\n    getLayerCount(): number;\r\n\r\n    setTileAt(layer: number, x: number, y: number, value: number, flipX?: boolean, flipY?: boolean, angle?: number): TileMap;\r\n    getTileAt(layer: number, x: number, y: number): number;\r\n    getTileTransformAt(layer: number, x: number, y: number): { flipX: boolean; flipY: boolean; angle: number; };\r\n  }\r\n}\r\n"
});
SupCore.system.registerPlugin("typescriptAPI", "Sup.TileSet", {
    code: "namespace Sup {\r\n  export class TileSet extends Asset {\r\n    getWidth() { return this.__inner.data.texture.image.width; }\r\n    getHeight() { return this.__inner.data.texture.image.height; }\r\n    getGridSize() { return { width: this.__inner.data.grid.width, height: this.__inner.data.grid.height }; }\r\n\r\n    getTileProperties(tile) {\r\n      let tilesPerRow = this.__inner.data.texture.image.width / this.__inner.data.grid.width;\r\n\r\n      let x = tile % tilesPerRow;\r\n      let y = window.Math.floor(tile / tilesPerRow);\r\n      let properties = this.__inner.data.tileProperties[x + \"_\" + y];\r\n      properties = (properties) ? properties : {};\r\n      return properties;\r\n    }\r\n    setTileProperty(tile, propertyName, propertyValue) {\r\n      let tilesPerRow = this.__inner.data.texture.image.width / this.__inner.data.grid.width;\r\n\r\n      let x = tile % tilesPerRow;\r\n      let y = window.Math.floor(tile / tilesPerRow);\r\n      let properties = this.__inner.data.tileProperties[x + \"_\" + y];\r\n      properties = (properties) ? properties : {};\r\n      if (propertyValue != null) {\r\n        this.__inner.data.tileProperties[x + \"_\" + y][propertyName] = propertyValue;\r\n      } else if (this.__inner.data.tileProperties[x + \"_\" + y][propertyName] != null) {\r\n        delete this.__inner.data.tileProperties[x + \"_\" + y][propertyName];\r\n      }\r\n    }\r\n  }\r\n}\r\n",
    defs: "declare namespace Sup {\r\n  class TileSet extends Asset {\r\n    getWidth(): number;\r\n    getHeight(): number;\r\n    getGridSize(): { width: number; height; number };\r\n    getTileProperties(tile: number): { [key:string]: string; };\r\n    setTileProperty(tile: number, propertyName: string, propertyValue: string);\r\n  }\r\n}\r\n"
});
SupCore.system.registerPlugin("typescriptAPI", "TileMapRenderer", {
    code: "namespace Sup {\r\n  export class TileMapRenderer extends Sup.ActorComponent {\r\n    constructor(actor: Actor, pathOrAsset: string|TileMap) {\r\n      super(actor);\r\n      this.__inner = new SupEngine.componentClasses.TileMapRenderer(this.actor.__inner);\r\n      if (pathOrAsset != null) { this.setTileMap(pathOrAsset, true); }\r\n      this.__inner.__outer = this;\r\n      this.actor.tileMapRenderer = this;\r\n    }\r\n    destroy() {\r\n      this.actor.tileMapRenderer = null;\r\n      super.destroy();\r\n    }\r\n\r\n    getTileMap() { return this.__inner.tileMap.__outer; }\r\n    setTileMap(pathOrAsset: string|TileMap, replaceTileSet) {\r\n      let tileMap = (typeof pathOrAsset === \"string\") ? get(pathOrAsset, TileMap) : <TileMap>pathOrAsset;\r\n      this.__inner.setTileMap(tileMap.__inner);\r\n      replaceTileSet = (replaceTileSet) ? replaceTileSet : true;\r\n      if (replaceTileSet) { this.__inner.setTileSet( player.getOuterAsset(tileMap.__inner.data.tileSetId).__inner ); }\r\n      return this;\r\n    }\r\n\r\n    getTileSet() { return this.__inner.tileSet.__outer; }\r\n    setTileSet(pathOrAsset: string|TileSet) {\r\n      let tileSet = (typeof pathOrAsset === \"string\") ? get(pathOrAsset, TileSet) : <TileSet>pathOrAsset;\r\n      this.__inner.setTileSet(tileSet.__inner);\r\n      return this;\r\n    }\r\n\r\n    getLayerOpacity(layer) { return this.__inner.layerMeshes[layer].material.opacity; }\r\n    setLayerOpacity(layer, opacity) { this.__inner.layerMeshes[layer].material.opacity = opacity; return this; }\r\n  }\r\n}\r\n",
    defs: "declare namespace Sup {\r\n  class TileMapRenderer extends ActorComponent {\r\n    constructor(actor: Actor, pathOrAsset?: string|TileMap);\r\n    getTileMap(): TileMap;\r\n    setTileMap(pathOrAsset?: string|TileMap, replaceTileSet?: boolean); TileMapRenderer;\r\n    getTileSet(): TileSet;\r\n    setTileSet(pathOrAsset?: string|TileSet): TileMapRenderer;\r\n    getLayerOpacity(layer: number): number;\r\n    setLayerOpacity(layer: number, opacity: number): TileMapRenderer;\r\n  }\r\n}",
    exposeActorComponent: { propertyName: "tileMapRenderer", className: "Sup.TileMapRenderer" }
});

},{}]},{},[1]);
