<commit_before>var Tilelayer = require('./Tilelayer'),
    Objectlayer = require('./Objectlayer'),
    Tile = require('./Tile'),
    Tileset = require('./Tileset'),
    TilemapParser = require('./TilemapParser'),
    utils = require('../utils'),
    C = require('../constants');

/**
 * Tiled map that represents an entire tile map with multiple layers or object groups.
 * Often it is easier to create a tilemap using the object factor on a world, rather
 * than doing it manually yourself.
 *
 * @class Tilemap
 * @constructor
 * @param {Phaser.Game} game - Game reference to the currently running game.
 * @param {string} [key] - The name of the tiledmap, this is usually the filename without the extension.
 * @param {Phaser.Group|Phaser.SpriteBatch} [group] - Group to add the tilemap to.
 */
function Tilemap(game, key, group) {
    Phaser.Group.call(this, game, group, key);

    var data = TilemapParser.parse(game, key);

    this.type = Phaser.TILEMAP;

    /**
     * The key of this map data in the Phaser.Cache.
     *
     * @property key
     * @type String
     */
    this.key = key;

    if (data === null) {
        return;
    }

    this.size = new Phaser.Point(data.width, data.height);

    /**
     * @property {number} tileWidth - The base width of the tiles in the map (in pixels).
     */
    this.tileWidth = data.tilewidth;

    /**
     * @property {number} tileHeight - The base height of the tiles in the map (in pixels).
     */
    this.tileHeight = data.tileheight;

    /**
     * @property {number} scaledTileWidth - The scaled width of the tiles in the map (in pixels).
     */
    this.scaledTileWidth = this.tileWidth;

    /**
     * @property {number} scaledTileHeight - The scaled height of the tiles in the map (in pixels).
     */
    this.scaledTileHeight = this.tileHeight;

    /**
     * @property {string} orientation - The orientation of the map data (as specified in Tiled), usually 'orthogonal'.
     */
    this.orientation = data.orientation;

    /**
     * @property {number} format - The format of the map data, either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.
     */
    this.format = data.format;

    /**
     * @property {number} version - The version of the map data (as specified in Tiled, usually 1).
     */
    this.version = data.version;

    /**
     * @property {object} properties - Map specific properties as specified in Tiled.
     */
    this.properties = utils.parseTiledProperties(data.properties);

    /**
     * @property {number} widthInPixels - The width of the map in pixels based on width * tileWidth.
     */
    this.widthInPixels = data.width * data.tilewidth;

    /**
     * @property {number} heightInPixels - The height of the map in pixels based on height * tileHeight.
     */
    this.heightInPixels = data.height * data.tileheight;

    /**
     * @property {array} layers - An array of Tilemap layer data.
     */
    this.layers = [];

    /**
     * @property {array} tilesets - An array of Tilesets.
     */
    this.tilesets = [];

    /**
     * @property {array} objects - An array of Tiled Object Layers.
     */
    this.objects = [];

    /**
     * @property {array} images - An array of Tiled Image Layers.
     */
    this.images = [];

    /**
     * @property {array} collideIndexes - An array of tile indexes that collide.
     */
    this.collideIndexes = [];

    /**
     * @property {array} collision - An array of collision data (polylines, etc).
     */
    // this.collision = data.collision;

    /**
     * @property {number} currentLayer - The current layer.
     */
    this.currentLayer = 0;

    /**
     * @property {array} debugMap - Map data used for debug values only.
     */
    this.debugMap = [];

    this.preventingRecalculate = false;
    this.needToRecalculate = null;

    // tell when camera scale is modified
    this._camScaleX = 0;
    this._camScaleY = 0;

    // should all layers do a full rerender?
    this.dirty = true;

    // update the world bounds
    this.game.world.setBounds(0, 0, this.widthInPixels, this.heightInPixels);

    // create each tileset
    for(var t = 0, tl = data.tilesets.length; t < tl; ++t) {
        var ts = data.tilesets[t];
        this.tilesets.push(new Tileset(game, key, ts));
    }

    // create each layer
    for(var i = 0, il = data.layers.length; i < il; ++i) {
        var lyr,
            ldata = data.layers[i];

        switch(ldata.type) {
            case 'tilelayer':
                lyr = new Tilelayer(game, this, ldata, this.layers.length);
                this.layers.push(lyr);

                // calculate the tile faces
                this.calculateFaces(this.layers.length - 1);
                break;

            case 'objectgroup':
                lyr = new Objectlayer(game, this, ldata, this.objects.length);
                this.objects.push(lyr);
                break;

            case 'imagelayer':
                lyr = game.add.sprite(ldata.x, ldata.y, utils.cacheKey(key, 'layer', ldata.name), null, this);
<commit_msg>Addition: if x/y else offsetx/offsety<commit_after>var Tilelayer = require('./Tilelayer'),
    Objectlayer = require('./Objectlayer'),
    Tile = require('./Tile'),
    Tileset = require('./Tileset'),
    TilemapParser = require('./TilemapParser'),
    utils = require('../utils'),
    C = require('../constants');

/**
 * Tiled map that represents an entire tile map with multiple layers or object groups.
 * Often it is easier to create a tilemap using the object factor on a world, rather
 * than doing it manually yourself.
 *
 * @class Tilemap
 * @constructor
 * @param {Phaser.Game} game - Game reference to the currently running game.
 * @param {string} [key] - The name of the tiledmap, this is usually the filename without the extension.
 * @param {Phaser.Group|Phaser.SpriteBatch} [group] - Group to add the tilemap to.
 */
function Tilemap(game, key, group) {
    Phaser.Group.call(this, game, group, key);

    var data = TilemapParser.parse(game, key);

    this.type = Phaser.TILEMAP;

    /**
     * The key of this map data in the Phaser.Cache.
     *
     * @property key
     * @type String
     */
    this.key = key;

    if (data === null) {
        return;
    }

    this.size = new Phaser.Point(data.width, data.height);

    /**
     * @property {number} tileWidth - The base width of the tiles in the map (in pixels).
     */
    this.tileWidth = data.tilewidth;

    /**
     * @property {number} tileHeight - The base height of the tiles in the map (in pixels).
     */
    this.tileHeight = data.tileheight;

    /**
     * @property {number} scaledTileWidth - The scaled width of the tiles in the map (in pixels).
     */
    this.scaledTileWidth = this.tileWidth;

    /**
     * @property {number} scaledTileHeight - The scaled height of the tiles in the map (in pixels).
     */
    this.scaledTileHeight = this.tileHeight;

    /**
     * @property {string} orientation - The orientation of the map data (as specified in Tiled), usually 'orthogonal'.
     */
    this.orientation = data.orientation;

    /**
     * @property {number} format - The format of the map data, either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.
     */
    this.format = data.format;

    /**
     * @property {number} version - The version of the map data (as specified in Tiled, usually 1).
     */
    this.version = data.version;

    /**
     * @property {object} properties - Map specific properties as specified in Tiled.
     */
    this.properties = utils.parseTiledProperties(data.properties);

    /**
     * @property {number} widthInPixels - The width of the map in pixels based on width * tileWidth.
     */
    this.widthInPixels = data.width * data.tilewidth;

    /**
     * @property {number} heightInPixels - The height of the map in pixels based on height * tileHeight.
     */
    this.heightInPixels = data.height * data.tileheight;

    /**
     * @property {array} layers - An array of Tilemap layer data.
     */
    this.layers = [];

    /**
     * @property {array} tilesets - An array of Tilesets.
     */
    this.tilesets = [];

    /**
     * @property {array} objects - An array of Tiled Object Layers.
     */
    this.objects = [];

    /**
     * @property {array} images - An array of Tiled Image Layers.
     */
    this.images = [];

    /**
     * @property {array} collideIndexes - An array of tile indexes that collide.
     */
    this.collideIndexes = [];

    /**
     * @property {array} collision - An array of collision data (polylines, etc).
     */
    // this.collision = data.collision;

    /**
     * @property {number} currentLayer - The current layer.
     */
    this.currentLayer = 0;

    /**
     * @property {array} debugMap - Map data used for debug values only.
     */
    this.debugMap = [];

    this.preventingRecalculate = false;
    this.needToRecalculate = null;

    // tell when camera scale is modified
    this._camScaleX = 0;
    this._camScaleY = 0;

    // should all layers do a full rerender?
    this.dirty = true;

    // update the world bounds
    this.game.world.setBounds(0, 0, this.widthInPixels, this.heightInPixels);

    // create each tileset
    for(var t = 0, tl = data.tilesets.length; t < tl; ++t) {
        var ts = data.tilesets[t];
        this.tilesets.push(new Tileset(game, key, ts));
    }

    // create each layer
    for(var i = 0, il = data.layers.length; i < il; ++i) {
        var lyr,
            ldata = data.layers[i];

        switch(ldata.type) {
            case 'tilelayer':
                lyr = new Tilelayer(game, this, ldata, this.layers.length);
                this.layers.push(lyr);

                // calculate the tile faces
                this.calculateFaces(this.layers.length - 1);
                break;

            case 'objectgroup':
                lyr = new Objectlayer(game, this, ldata, this.objects.length);
                this.objects.push(lyr);
                break;

            case 'imagelayer':
                var x = ldata.x ? ldata.x : ldata.offsetx;
				var y = ldata.y ? ldata.y : ldata.offsety;
                lyr = game.add.sprite(x, y, utils.cacheKey(key, 'layer', ldata.name), null, this);

{'fraction_non_alphanumeric': 0.12414266117969822, 'fraction_numerical': 0.001763668430335097, 'mean_word_length': 2.20873939012889, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5176664', 'n_tokens_mistral': 3155, 'n_tokens_neox': 3037, 'n_words': 944}