/*:
@author chaucer
@plugindesc | CHAU_Arc : Versoin 1.0.0 |
@help()()
*(^_^)
*c(")(")
#=============================================================================#
# Instructions.
#=============================================================================#
 To use this plugin just type in a script call or in your plugin the below code

 var myVariablesName = new PiSprite(x, y, radius, angle, color);

 it will make a new circualar arc graphic, each argument should be pretty simple
 to follow along with.

* *x : the x location in pixels.

* *y : the y location in pixels.

* *radius : the radius of the circle.

* *angle : this is the end angle of our circle(this is a percent value, rather
* *than in radians, to make things simpler, it should be a value between 0 and 1,
* * 0 being completely empty, 1 being a full circle).

* *color : a hex color that our circle will be drawn in.

* * Changing the angle :

* *you can change the angle anytime you want once the graphic is created, in
* *order to do this, simply use a use the following snippet in a script call or
* *whatever plugin you use it in(remember, the angle is a percent, and not
* * a radian ).

* myVariablesName.changeAngle( newAngle );

#=============================================================================#
ChangeLog
#=============================================================================#
 Version 1.0.0
*
 *Release.

#=============================================================================#
contact info.
#=============================================================================#
  rgpmakerweb username : chaucer
  skype id : chaucer1991
  email : chaucer91@gmail.com
#=============================================================================#
#=============================================================================#

*/

//=============================================================================
// PiSprite
//=============================================================================

function PiSprite() {
  this.initialize.apply( this, arguments );
};

PiSprite.prototype = Object.create( PIXI.Graphics.prototype );
PiSprite.prototype.constructor = PiSprite;

//initialize our variables.
PiSprite.prototype.initialize = function ( x, y, radius, angle, color ) {
  PIXI.Graphics.call( this );
  //x and y values.
  this.x = Number ( x || 10 );
  this.y = Number ( y || 10 );
  //this will decrease our radius by 90 degrees to make sure
  //we begin drawing from the top.
  this._oR = Math.PI / 2;
  //our start angle.
  this._start = 0 - this._oR;
  //the size of our circles radius.
  this._radius = Number ( radius || 10 );
  //the ending angle.
  this._angle = (Math.PI * 2) * Number ( angle || 1 ).clamp( 0, 1) - this._oR;
  //our color, if none specified return black.
  this._color = color ? eval( color.replace( "#", "0x" ) ) : 0x000000;
  this.refresh();
};


PiSprite.prototype.changeColor = function(r, g, b){
  this._color = eval(this.rgbToHex(r, g, b));
  this.refresh();
}

PiSprite.prototype.updateColor = function(rv, gv, bv){
  this.changeColor($gameVariables.value(rv), $gameVariables.value(gv), $gameVariables.value(bv));
}

//this function changes the value of our pi sprite and refreshes it.
PiSprite.prototype.changeAngle = function( angle ) {
  //setup our new end angle, then refresh the graphic.
  this._angle = (Math.PI * 2) * Number ( angle || 1 ).clamp( 0, 1) - this._oR;
  this.refresh()
};

PiSprite.prototype.rgbToHex = function(r, g, b){
 return "0x" + this.pad2(r.toString(16)) + this.pad2(g.toString(16)) + this.pad2(b.toString(16));
}

PiSprite.prototype.pad2 = function(s){
 return (s.length < 2) ? "0" + s : s;
}

//this function simply redraws our sprite when the value gets changed.
PiSprite.prototype.refresh = function() {
  //check our parent for future reference.
  var parent = this.parent;
  //remove the parent if we have one.
  if ( parent )
    parent.removeChild( this );
    //clear our graphic so that the old image is erased
    //otherwise it could make things weird.
    this.clear();
    //begin the fill with our color.
    this.beginFill( this._color );
    //move the the center, just incase for some reason
    //we're not already there.
    this.moveTo( this.x, this.y );
    //draw our arc!
    this.arc( this.x, this.y, this._radius, this._start, this._angle );
    //and finally close the graphic.
    this.endFill();
    //then re-add our this graphic to it's parent.
    if ( parent )
      parent.addChild( this );
};

var Circles = {};