"use strict";
/* an overlay to obscure the screen, or a rectangular region thereof.  Triggered by setting "flash" on the scratchpad */
var Deco_Flash = function(tilesw,tilesh){
	this.tilesw = tilesw ? tilesw : 4;
	this.tilesh = tilesh ? tilesh : 4;
	this.frame = GLOBAL_SCRATCHPAD.check("flash") ? 0 : 7;
};

Deco_Flash.prototype = new Decoration(
	new TileSheet(
		3, 3, 3, 0, 
		SDS_Load_Image("art/sheets/decoration/flash.png")
	),
	"Flash");

Deco_Flash.prototype.animate = function(){
		if (GLOBAL_SCRATCHPAD.check("flash")){
			this.frame=0;
			GLOBAL_SCRATCHPAD.unpersist("flash");
			GLOBAL_SCRATCHPAD.note("flash",false);
		}
		else if (this.frame<7){
			++this.frame;
		}
	}

Deco_Flash.prototype.drawIntoCanvas = function(canvas){
		if (this.tile_sheet){
			for (this._heap.j=0; this.frame!=7 && this._heap.j<this.tilesh; this._heap.j++){
				for (this._heap.i=0; this._heap.i<this.tilesw; this._heap.i++){
					this.tile_sheet.drawIntoCanvas(
						canvas,
						this.frame,
						this.x + this._heap.i*this.tile_sheet.tile_pixel_width,
						this.y + this._heap.j*this.tile_sheet.tile_pixel_height);
				}
			}
		}
	};
