(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" />
"use strict";

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

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