
//#
//#
//#
//#
//#  * * *    *    * * * *  * * *  * * *    *       * * *  *   * 
//#  *       * *   *  *  *  *      *   *   * *      *       * *  
//#  *      * * *  *  *  *  * * *  * * *  * * *     * * *    *   
//#  *      *   *  *  *  *  *      *  *   *   *     *       * *  
//#  * * *  *   *  *     *  * * *  *   *  *   *     *      *   * 
//#
//#
//#
//#  


//! NOT ok
//_ multiply overlay darken lighten color-dodge color-burn hard-light soft-light difference hue saturation color luminosity clear copy source-in destination-in source-out destination-out destination-atop xor

//` OK
//` screen exclusion destination source-over destination-over source-atop lighter


//# ---------------------------------------------------- ~fx
var CameraFX = {
  oneBit:function(context, canvas){ // DigitalCamera
    var T = 30 + D.n(40,5);
    Filter.threshold(canvas, T/100);

    context.globalCompositeOperation = "screen";
    context.fillStyle = Color.toRGBA(0x0022aa, .5);
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.globalCompositeOperation = "normal";
    context.fillStyle = Color.toRGBA(0xaabb00, .25);
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.globalCompositeOperation = "normal";
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.4, 
      canvas.width*.5, canvas.height*.5, canvas.width*1.1
    );
    var tone = 0x99ff55;
    gradient.addColorStop(0, Color.toRGBA(tone, 0));
    gradient.addColorStop(1, Color.toRGBA(tone, 1));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);
  },

  blackAndWhite:function(context, canvas){ // VilmoltaCamera
    Filter.brightness(canvas, .95);
    Filter.contrast(canvas, 1.5);
    Filter.grayscale(canvas);
    context.globalCompositeOperation = "color"; //^ == == == ==
    context.fillStyle = Color.toRGBA(0xddff00, .1);
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.globalCompositeOperation = "normal";
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.4, 
      canvas.width*.5, canvas.height*.5, canvas.width*1.1
    );
    var tone = 0xff00ff; ///0x0099ff;
    gradient.addColorStop(0, Color.toRGBA(tone, 0));
    gradient.addColorStop(1, Color.toRGBA(tone, .6));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);
  },

  varying:function(context, canvas){ // VikonCamera
    var C1 = Color();///.lightness(60).saturation(100);
    var fillStyle = Color.toRGBA(C1.value,.5);
    Filter.fillRectWithMode(canvas, fillStyle, "color");

    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.65
    );
    gradient.addColorStop(0, Color.toRGBA(0xffffff, .3));
    gradient.addColorStop(1, Color.toRGBA(0x990044, 1));
    Filter.fillRectWithMode(canvas, gradient, "overlay");
  },

  disposable:function(context, canvas){ // DisposableCamera
    Filter.brightness(canvas, .8);
    Filter.contrast(canvas, 1.85);
    Filter.brightness(canvas, 1.2);
    context.globalCompositeOperation = "normal";
    context.fillStyle = Color.toRGBA(0x00ffff, .2);
    context.fillRect(0, 0, canvas.width, canvas.height);
    context.globalCompositeOperation = "normal";
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.6
    );
    gradient.addColorStop(0, Color.toRGBA(0x00ffff, 0));
    gradient.addColorStop(1, Color.toRGBA(0x00aaff, .5));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);

    ///Filter.noiseDigital(canvas, 66 );
    Filter.noiseDigitalEx(canvas, 250, D.n(100));
  },

  cheapYellow:function(context, canvas){ // InstantCamera
    Filter.brightness(canvas, .75);
    Filter.contrast(canvas, 1.5);
    context.globalCompositeOperation = "overlay"; //` == == == ==
    context.fillStyle = Color.toRGBA(0xffccff, 1);
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.globalCompositeOperation = "normal";
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.6
    );
    gradient.addColorStop(0, Color.toRGBA(0x00bbff, 0));
    gradient.addColorStop(1, Color.toRGBA(0xffff00, .75));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);
  },

  broken:function(context, canvas){ // PrototypeCamera
    Filter.rotate(canvas, rnd(360));
    var color = Color(0xffff00);
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.6
    );
    gradient.addColorStop(0, Color.toRGBA(0x00bbff, 0));
    gradient.addColorStop(1, Color.toRGBA(color.value, .75));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);
  },

  smashed:function(context, canvas){ // MalfunctioningCamera
    Filter.rotate(canvas, rnd(360));
    var color = Color(0xffff00);
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.6
    );
    gradient.addColorStop(0, Color.toRGBA(0x00bbff, 0));
    gradient.addColorStop(1, Color.toRGBA(color.value, .75));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);

    var dup = Game.copyImage(canvas);
    Filter.invert(dup);
    context.globalCompositeOperation = "color"; //` == == == ==
    context.drawImage(dup,0,0,dup.width,dup.height);
    Filter.contrast(canvas,1.5);
    Game.cache.recycle(dup);
    Filter.rotate(canvas,rnd.n(360));
  },
  noisy:function(context, canvas){ // NoisyCamera
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.6
    );
    var C1 = Color().saturation(100).lightness(70).value;
    var C2 = Color().saturation(100).lightness(70).value;
    gradient.addColorStop(0, Color.toRGBA(C1, 0));
    gradient.addColorStop(1, Color.toRGBA(C2, 1));
    Filter.fillRectWithMode(canvas, gradient, "color");

    Filter.noiseDigitalEx(canvas, D.n(10,2), rnd.n(99,2) );
  },

  // == == == == == == == == == == == == == == == == == UNUSED

  static:function(context, canvas){
    Filter.brightness(canvas, .8);
    Filter.contrast(canvas, 1.85);
    Filter.brightness(canvas, 1.2);
    context.globalCompositeOperation = "normal";
    context.fillStyle = Color.toRGBA(0x00ffff, .2);
    context.fillRect(0, 0, canvas.width, canvas.height);
    context.globalCompositeOperation = "normal";
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.6
    );
    gradient.addColorStop(0, Color.toRGBA(0x00ffff, 0));
    gradient.addColorStop(1, Color.toRGBA(0x00aaff, .5));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);

    Filter.noiseStatic(canvas, 3, 2 );
  },
  cheapRed:function(context, canvas){
    Filter.brightness(canvas, .75);
    Filter.contrast(canvas, 1.5);
    context.globalCompositeOperation = "overlay"; //^ == == == ==
    context.fillStyle = Color.toRGBA(0xffccff, 1);
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.globalCompositeOperation = "normal";
    var gradient = context.createRadialGradient(
      canvas.width*.5, canvas.height*.5, canvas.width*.2, 
      canvas.width*.5, canvas.height*.5, canvas.width*.6
    );
    gradient.addColorStop(0, Color.toRGBA(0x00bbff, 0));
    gradient.addColorStop(1, Color.toRGBA(0xff0055, .65));
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);
  },
  hueRotate:function(context, canvas){
    var dup = Game.copyImage(canvas);
    Filter.invert(dup);
    Filter.rotate(dup, 180);
    context.globalCompositeOperation = "color"; //~ == == == ==
    context.drawImage(dup,0,0,dup.width,dup.height);
    Game.cache.recycle(dup);
  },


};


//#
//#
//#
//#
//# * * * *    * *    * * * *  * * * *  * * * *    * *    * * * *  
//# *         *   *   *  *  *  *        *     *   *   *   *        
//# *        * * * *  *  *  *  * * * *  * * * *  * * * *  * * * *  
//# *        *     *  *  *  *  *        *  *     *     *        *  
//# * * * *  *     *  *     *  * * * *  *   *    *     *  * * * *  
//#
//#
//#
//# ~cameras


//# DisposableCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var DisposableCamera = MakeItem({
  item:"DisposableCamera",
  palette: App.palette.DisposableCamera,
  image:"images/disposableCamera.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:3,
      fx:function(a,b){return CameraFX.disposable(a,b)},
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    canUsePaused:true,
    ///recipe:"DisposableCamera = RockPile + Recorder|Talkie|Device + WaterBottle + Gem",
    stackable:false,
    countable:true,
    quantity:[-1,6,6],// -1 keeps the camera in inventory since never hits min
    rarity:"rare",
  }
});


//# SLRCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var SLRCamera = MakeItem({
  item:"SLRCamera",
  palette: App.palette.SLRCamera,
  image:"images/SLRCamera.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:3,
    },
    icon:{
      crop:rect(0, 0, 16),
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    ///recipe:"SLRCamera = StonePile + Recorder|Talkie|Device + CrushBottle + Gem",
    rarity:"veryrare",
  }
});


//  * * * *  * * * *  * * * *  * * * *  
//  *  *  *  *     *  *     *  *        
//  *  *  *  *     *  * * * *  * * * *  
//  *  *  *  *     *  *  *     *        
//  *     *  * * * *  *   *    * * * *  
//
//  * * * *    * *    * * * *  * * * *  * * * *    * *    * * * *  
//  *         *   *   *  *  *  *        *     *   *   *   *        
//  *        * * * *  *  *  *  * * * *  * * * *  * * * *  * * * *  
//  *        *     *  *  *  *  *        *  *     *     *        *  
//  * * * *  *     *  *     *  * * * *  *   *    *     *  * * * *  



//# InstantCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var InstantCamera = MakeItem({
  item:"InstantCamera",
  palette: App.palette.InstantCamera,
  image:"images/instantCamera.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:4,
      fx:function(a,b){return CameraFX.cheapYellow(a,b)}, //! == == == ==
    },
    icon:{
      crop:rect(0, 0, 16),
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    recipe:"-photographer> InstantCamera = StonePile + Talkie|Recorder|Device + ColaBottle + Gem",
    rarity:"extremelyrare",
  }
});

//# DigitalCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var DigitalCamera = MakeItem({
  item:"DigitalCamera",
  palette: App.palette.DigitalCamera,
  image:"images/digitalCamera.png",
  floorLevel:4,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:5,
      fx:function(a,b){return CameraFX.oneBit(a,b)}, //` == == == ==
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    recipe:"-photographer> DigitalCamera = StonePile + Device|Talkie|Recorder + ToxicPile + Gem",
    rarity:"extremelyrare",
  }
});

//# VikonCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var VikonCamera = MakeItem({
  item:"VikonCamera",
  palette: App.palette.VikonCamera,
  image:"images/vikonCamera.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:6,
      fx:function(a,b){return CameraFX.varying(a,b)}, //! == == == ==
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    recipe:"-photographer> VikonCamera = RockPile + Tire + ToxicPile + Gem",
    rarity:"extremelyrare",
  }
});

//# VilmoltaCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var VilmoltaCamera = MakeItem({
  item:"VilmoltaCamera",
  palette: App.palette.VilmoltaCamera,
  image:"images/blackAndWhiteCamera.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:4,
      fx:function(a,b){return CameraFX.blackAndWhite(a,b)}, //! == == == ==
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    recipe:"-photographer> VilmoltaCamera = RockPile + Tire + FungusPile:brown + Gem",
    rarity:"extremelyrare",
  }
});

//# PrototypeCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var PrototypeCamera = MakeItem({
  item:"PrototypeCamera",
  palette: App.palette.PrototypeCamera,
  image:"images/prototypeCamera.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:4,
      fx:function(a,b){return CameraFX.broken(a,b)}, //` == == == ==
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    recipe:"-photographer> PrototypeCamera = StoneFloorPile + Tire + FungusPile:white + Gem",
    rarity:"extremelyrare",
  }
});

//# MalfunctioningCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var MalfunctioningCamera = MakeItem({
  item:"MalfunctioningCamera",
  palette: App.palette.MalfunctioningCamera,
  image:"images/malfunctioningCamera.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:4,
      fx:function(a,b){return CameraFX.smashed(a,b)}, //! == == == ==
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    recipe:"-photographer> MalfunctioningCamera = StoneFloorPile + ToxicPile + FungusPile:white + Gem",
    rarity:"extremelyrare",
  }
});

//# NoisyCamera
//# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~  
var NoisyCamera = MakeItem({
  item:"NoisyCamera",
  palette: App.palette.NoisyCamera,
  image:"images/vilmoroid.png",
  floorLevel:6,
  noShadow:true,
  inventoryItem:{
    actions:["Snap", "Drop"],
    attributes:{
      fov:5,
      fx:function(a,b){return CameraFX.noisy(a,b)}, //! == == == ==
    },
    tooltip:TEXT("A camera<p>Take a picture, it'll last longer.</p>"),
    stackable:false,
    canUsePaused:true,
    recipe:"-photographer> NoisyCamera = StonePile + ToxicPile + BubbleBottle + Gem",
    rarity:"extremelyrare",
  }
});

// fragile
///App.loadMoreCameras = function(exports){
///  if(!exports) exports = window;
///  MakeItem more-cameras here
///};
///EVENT.on(Shop, "changed", function(productId){
///
///  if(productId == "vilmonic_photographer_recipes" ||
///     Shop.has("vilmonic_photographer_recipes") ){
///    App.loadMoreCameras();
///  }
///
///}.bind(this) );
///

