/**
 * @author       Richard Davey <rich@photonstorm.com>
 * @copyright    2020 Photon Storm Ltd.
 * @license      {@link https://opensource.org/licenses/MIT|MIT License}
 */

var CullBounds = require('./CullBounds');
var RunCull = require('./RunCull');

/**
 * Returns the tiles in the given layer that are within the cameras viewport. This is used internally.
 *
 * @function Phaser.Tilemaps.Components.CullTiles
 * @since 3.50.0
 *
 * @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
 * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to run the cull check against.
 * @param {array} [outputArray] - An optional array to store the Tile objects within.
 * @param {integer} [renderOrder=0] - The rendering order constant.
 *
 * @return {Phaser.Tilemaps.Tile[]} An array of Tile objects.
 */
var CullTiles = function (layer, camera, outputArray, renderOrder)
{
    if (outputArray === undefined) { outputArray = []; }
    if (renderOrder === undefined) { renderOrder = 0; }

    outputArray.length = 0;

    var tilemapLayer = layer.tilemapLayer;

    if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
    {
        //  Camera world view bounds, snapped for scaled tile size
        //  Cull Padding values are given in tiles, not pixels

        var bounds = CullBounds(layer, camera);

        RunCull(layer, bounds, renderOrder, outputArray);
    }

    return outputArray;
};

module.exports = CullTiles;

@@ -1085,13 +1085,179 @@
     
+//  Camera world view bounds, snapped for scaled tile size%0A    //  Cull Padding values are given in tiles, not pixels%0A    var bounds = CullBounds(layer, camera);%0A%0A    
 if (
-!
 tile
@@ -1274,18 +1274,18 @@
 kipCull 
-&&
+%7C%7C
  tilemap
@@ -1308,16 +1308,16 @@
 orX 
+!
 ==
-=
  1 
-&&
+%7C%7C
  til
@@ -1340,17 +1340,17 @@
 FactorY 
-=
+!
 == 1)%0A  
@@ -1365,130 +1365,60 @@
     
-//  Camera world view bounds, snapped for scaled tile size%0A        //  Cull Padding values are given in tiles, not pixels%0A
+bounds.left = 0;%0A        bounds.right = layer.width;
 %0A   
@@ -1426,53 +1426,69 @@
     
-var 
 bounds
- = CullBounds(layer, camera)
+.top = 0;%0A        bounds.bottom = layer.height
 ;%0A
-%0A
     
+%7D%0A%0A
     
@@ -1536,22 +1536,16 @@
 tArray);
-%0A    %7D
 %0A%0A    re

Fix culled tiles return