public/js-roguelike-skeleton/src/lighting-rot.js
function(x, y, tileData){
            var light = this.ambientLight;
            var lighting = this.get(x, y);

            var overlay = function(c1, c2){
                var out = c1.slice();
                for (var i = 0; i < 3; i++) {
                    var a = c1[i],
                        b = c2[i];
                    if(b < 128){
                        out[i] = Math.round(2 * a * b / 255);
                    } else {
                        out[i] = Math.round(255 - 2 * (255 - a) * (255 - b) / 255);
                    }
                }
                return out;
            };

            if(lighting){
                light = ROT.Color.add(this.ambientLight, lighting);
            }

            if(tileData.color){
                var color = ROT.Color.fromString(tileData.color);
                color = overlay(light, color);
                tileData.color = ROT.Color.toRGB(color);
            }

            if(tileData.bgColor){
                var bgColor = ROT.Color.fromString(tileData.bgColor);
                bgColor = overlay(light, bgColor);
                tileData.bgColor = ROT.Color.toRGB(bgColor);
            }
            return tileData;
        }
function(x, y, tileData){
            var light = this.ambientLight;
            var lighting = this.get(x, y);

            var overlay = function(c1, c2){
                var out = c1.slice();
                for (var i = 0; i < 3; i++) {
                    var a = c1[i],
                        b = c2[i];
                    if(b < 128){
                        out[i] = Math.round(2 * a * b / 255);
                    } else {
                        out[i] = Math.round(255 - 2 * (255 - a) * (255 - b) / 255);
                    }
                }
                return out;
            };

            if(lighting){
                light = ROT.Color.add(this.ambientLight, lighting);
            }

            if(tileData.color){
                var color = ROT.Color.fromString(tileData.color);
                color = overlay(light, color);
                tileData.color = ROT.Color.toRGB(color);
            }

            if(tileData.bgColor){
                var bgColor = ROT.Color.fromString(tileData.bgColor);
                bgColor = overlay(light, bgColor);
                tileData.bgColor = ROT.Color.toRGB(bgColor);
            }
            return tileData;
        }
function ( x , y , tileData ) { var light = this . ambientLight ; var lighting = this . get ( x , y ) ; var overlay = function ( c1 , c2 ) { var out = c1 . slice ( ) ; for ( var i = 0 ; i < 3 ; i ++ ) { var a = c1 [ i ] , b = c2 [ i ] ; if ( b < 128 ) { out [ i ] = Math . round ( 2 * a * b / 255 ) ; } else { out [ i ] = Math . round ( 255 - 2 * ( 255 - a ) * ( 255 - b ) / 255 ) ; } } return out ; } ; if ( lighting ) { light = ROT . Color . add ( this . ambientLight , lighting ) ; } if ( tileData . color ) { var color = ROT . Color . fromString ( tileData . color ) ; color = overlay ( light , color ) ; tileData . color = ROT . Color . toRGB ( color ) ; } if ( tileData . bgColor ) { var bgColor = ROT . Color . fromString ( tileData . bgColor ) ; bgColor = overlay ( light , bgColor ) ; tileData . bgColor = ROT . Color . toRGB ( bgColor ) ; } return tileData ; }
Shades tileData using lighting.
@method shadeTile
@param {Number} x - The x map coordinate to shade.
@param {Number} y - The y map coordinate to shade.
@param {TileData} tileData - The `TileData` object to shade.
@return {TileData}
Shades tileData using lighting .