Super upgraded version with no overwrite, no crash when battle-testing and support for tint screen during combat.
Spoiler
var TerraxLighting_Addon_BattleManager_setup = BattleManager.setup;
BattleManager.setup = function(troopId, canEscape, canLose) {
$gameTemp._Tint = '#FFFFFF';
if ($dataMap) {
boolean = false;
for (var i = 0; i < $dataMap.events.length; i++) {
if ($dataMap.events) {
var note = $dataMap.events.note
var note_args = note.split(" ");
var note_command = note_args.shift().toLowerCase();
if (note_command == "light" || note_command == "fire" || note_command == "daynight" || note_command == "flashlight" ) {
boolean = true;
break;
}
}
}
if ($dataMap.note.toLowerCase() == 'daynight') {
console.log($gameVariables.valueDayNightColor());
console.log($gameVariables.valueDayNightSave());
$gameTemp._Tint = $gameVariables.valueDayNightColor()[$gameVariables.valueDayNightSave()];
} else if (boolean) {
$gameTemp._Tint = $gameVariables.valueTintValueSave();
}
}
TerraxLighting_Addon_BattleManager_setup.call(this,troopId, canEscape, canLose);
}
Spriteset_Battle.prototype.createBattleLightmask = function() {
this._lightmask = new BattleLightmask();
this.addChild(this._lightmask);
};
var TerraxLighting_Addon_Spriteset_Base_createLowerLayer = Spriteset_Battle.prototype.createLowerLayer;
Spriteset_Battle.prototype.createLowerLayer = function() {
TerraxLighting_Addon_Spriteset_Base_createLowerLayer.call(this);
this.createBattleLightmask();
}
function BattleLightmask() {
this.initialize.apply(this, arguments);
}
BattleLightmask.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
BattleLightmask.prototype.constructor = BattleLightmask;
BattleLightmask.prototype.initialize = function() {
PIXI.DisplayObjectContainer.call(this);
this._width = Graphics.width;
this._height = Graphics.height;
this._sprites = [];
this._createBitmap();
//Initialize the bitmap
this._addSprite(0,0,this._maskBitmap);
var redhex = $gameTemp._Tint.substring(1,3);
var greenhex = $gameTemp._Tint.substring(3,5);
var bluehex = $gameTemp._Tint.substring(5);
var red = parseInt(redhex, 16);
var green = parseInt(greenhex, 16);
var blue = parseInt(bluehex, 16);
var color = red+green+blue;
if (color<153 && red<51 && green<51 && blue<51){
$gameTemp._Tint = '#333333' //The player have to see something
}
$gameTemp._BattleTint = $gameTemp._Tint;
this._maskBitmap.FillRect(0,0,maxX,maxY,$gameTemp._Tint);
$gameTemp._BattleTintSpeed = 0;
};
BattleLightmask.prototype._createBitmap = function() {
this._maskBitmap = new Bitmap(maxX,maxY);
var canvas = this._maskBitmap.canvas;
};
//Plugin commands:
//TintBattle set #FF0000 -> Tint the battle screen to the color used as argument.
Automatically set too dark color to '#333333' otherwise the player wouldn't see anything.
//TintBattle reset -> Reset the battle screen to his original color.
//TintBattle fade #FF0000 5 -> Fade the battle screen to the color used as first argument.
// The second argument is speed of the fade (1 very fast, 20 more slow)
// Still automatically set too dark color to '#333333' otherwise the player wouldn't see anything.
var TerraxLighting_Addon_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
TerraxLighting_Addon_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'tintbattle' && $gameParty.inBattle()) {
if (args[0] === 'set') {
$gameTemp._BattleTint = args[1];
var redhex = $gameTemp._BattleTint.substring(1,3);
var greenhex = $gameTemp._BattleTint.substring(3,5);
var bluehex = $gameTemp._BattleTint.substring(5);
var red = parseInt(redhex, 16);
var green = parseInt(greenhex, 16);
var blue = parseInt(bluehex, 16);
var color = red+green+blue;
if (color<153 && red<51 && green<51 && blue<51){
$gameTemp._BattleTint = '#333333' //The player have to see something
}
$gameTemp._BattleTintSpeed = 0;
}
if (args[0] === 'reset') {
$gameTemp._BattleTint = $gameTemp._Tint;
$gameTemp._BattleTintSpeed = 0;
}
if (args[0] === 'fade') {
$gameTemp._BattleTintFade = $gameTemp._BattleTint;
$gameTemp._BattleTintTimer = 0;
$gameTemp._BattleTint = args[1];
$gameTemp._BattleTintSpeed = args[2];
var redhex = $gameTemp._BattleTint.substring(1,3);
var greenhex = $gameTemp._BattleTint.substring(3,5);
var bluehex = $gameTemp._BattleTint.substring(5);
var red = parseInt(redhex, 16);
var green = parseInt(greenhex, 16);
var blue = parseInt(bluehex, 16);
var color = red+green+blue;
if (color<153 && red<51 && green<51 && blue<51){
$gameTemp._BattleTint = '#333333' //The player have to see something
}
}
}
}
BattleLightmask.prototype.update = function() {
var color1 = $gameTemp._BattleTint;
if ($gameTemp._BattleTintSpeed > 0) {
$gameTemp._BattleTintTimer += 1;
var r = hexToRgb($gameTemp._BattleTintFade).r;
var g = hexToRgb($gameTemp._BattleTintFade).g;
var b = hexToRgb($gameTemp._BattleTintFade).b;
var r2 = hexToRgb($gameTemp._BattleTint).r;
var g2 = hexToRgb($gameTemp._BattleTint).g;
var b2 = hexToRgb($gameTemp._BattleTint).b;
var stepR = (r2-r)/(60*$gameTemp._BattleTintSpeed);
var stepG = (g2-g)/(60*$gameTemp._BattleTintSpeed);
var stepB = (b2-b)/(60*$gameTemp._BattleTintSpeed);
var r3 = Math.floor(r + (stepR * $gameTemp._BattleTintTimer));
var g3 = Math.floor(g + (stepG * $gameTemp._BattleTintTimer));
var b3 = Math.floor(b + (stepB * $gameTemp._BattleTintTimer));
if (r3<0) { r3 = 0 }
if (g3<0) { g3 = 0 }
if (b3<0) { b3 = 0 }
if (r3>255) { r3 = 255 }
if (g3>255) { g3 = 255 }
if (b3>255) { b3 = 255 }
var reddone = false;
var greendone = false;
var bluedone = false;
if (stepR >=0 && r3>=r2) {
reddone = true;
}
if (stepR <=0 && r3<=r2) {
reddone = true;
}
if (stepG >=0 && g3>=g2) {
greendone = true;
}
if (stepG <=0 && g3<=g2) {
greendone = true;
}
if (stepB >=0 && b3>=b2) {
bluedone = true;
}
if (stepB <=0 && b3<=b2) {
bluedone = true;
}
if (reddone == true && bluedone == true && greendone == true) {
$gameTemp._BattleTintFade = $gameTemp._BattleTint;
$gameTemp._BattleTintSpeed = 0;
$gameTemp._BattleTintTimer = 0;
}
color1 = "#" + ((1 << 24) + (r3 << 16) + (g3 << 8) + b3).toString(16).slice(1);
$gameTemp._BattleTintFade = color1;
}
this._maskBitmap.FillRect(0,0,maxX,maxY,color1);
};
//@method _createBitmaps
/**
* @method _addSprite
* @private
*/
BattleLightmask.prototype._addSprite = function(x1,y1,selectedbitmap) {
var sprite = new Sprite(this.viewport);
sprite.bitmap = selectedbitmap;
sprite.opacity = 255;
sprite.blendMode = 2;
sprite.x = x1;
sprite.y = y1;
this._sprites.push(sprite);
this.addChild(sprite);
sprite.rotation = 0;
sprite.ax = 0
sprite.ay = 0
sprite.opacity = 255;
};
/**
* @method _removeSprite
* @private
*/
BattleLightmask.prototype._removeSprite = function() {
this.removeChild(this._sprites.pop());
};