using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class lightColourising : MonoBehaviour {

    //The spotlight we're colouring
    public Light colouredLight;

    //The phase of colouration
    //0:    increasing RED
    //1:    decreasing BLUE
    //2:    increasing GREEN
    //3:    decreasing RED
    //4:    increasing BLUE
    //5:    decreasing GREEN
    private int colourationPhase = 0;

    //Current colours.
    private Color32 shade = new Color32(0, 0, 255, 0);

	// Use this for initialization
	void Start () {
		
	}

    int boostColourVal(byte shaderByte)
    {
        int newColourVal;

        newColourVal = (int)(shaderByte + (Time.deltaTime * 100));
        if (newColourVal > 255)
        {
            newColourVal = 255;
            colourationPhase++;
        }

        return newColourVal;
    }

    int reduceColourVal(byte shaderByte)
    {
        int newColourVal;

        newColourVal = (int)(shaderByte - (Time.deltaTime * 100));
        if (newColourVal < 0)
        {
            newColourVal = 0;
            colourationPhase++;
        }

        return newColourVal;
    }

    // Update is called once per frame
    void Update () {
        //Change colours based on the phase.
        int newColourVal;

		switch(colourationPhase)
        {
            case 0:
                newColourVal = boostColourVal(shade.r);
                shade = new Color32((byte)newColourVal, shade.g, shade.b, shade.a);
                break;

            case 1:
                newColourVal = reduceColourVal(shade.b);
                shade = new Color32(shade.r, shade.g, (byte)newColourVal, shade.a);
                break;


            case 2:
                newColourVal = boostColourVal(shade.g);
                shade = new Color32(shade.r, (byte)newColourVal, shade.b, shade.a);
                break;

            case 3:
                newColourVal = reduceColourVal(shade.r);
                shade = new Color32((byte)newColourVal, shade.g, shade.b, shade.a);
                break;


            case 4:
                newColourVal = boostColourVal(shade.b);
                shade = new Color32(shade.r, shade.g, (byte)newColourVal, shade.a);
                break;

            case 5:
                newColourVal = reduceColourVal(shade.g);
                shade = new Color32(shade.r, (byte)newColourVal, shade.b, shade.a);
                break;

            default:
                break;
        }
        
        if(colourationPhase > 5)
        {
            colourationPhase = 0;
        }

        colouredLight.color = shade;
	}
}
