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

public class Analyzer : MonoBehaviour {

    public Sprite analyzerBlank;
    public Sprite analyzerBlue;
    public Sprite analyzerGreen;
    public Sprite analyzerRed;
    public Sprite analyzerPurple;
    public Sprite analyzerCyan;
    public Sprite analyzerGold;

    private Modulator.PowerState[] receiverStates;
    private SpriteRenderer sprite;

	// Use this for initialization
	void Start () {
        receiverStates = new Modulator.PowerState[2];
        receiverStates[0] = Modulator.PowerState.BLANK;
        receiverStates[1] = Modulator.PowerState.BLANK;
        sprite = GetComponentInChildren<SpriteRenderer>();
	}
	
	public void setReceiverState(int index, Modulator.PowerState newState)
    {
        receiverStates[index] = newState;
        setPowerState();
    }

    public void setPowerState()
    {
        if (receiverStates[0] == Modulator.PowerState.BLANK && receiverStates[1] == Modulator.PowerState.BLANK)
        {
            sprite.sprite = analyzerBlank;
        }
        if ((receiverStates[0] == Modulator.PowerState.BLANK && receiverStates[1] == Modulator.PowerState.BLUE) || (receiverStates[0] == Modulator.PowerState.BLUE && receiverStates[1] == Modulator.PowerState.BLANK)){
            sprite.sprite = analyzerBlue;
        }
        if ((receiverStates[0] == Modulator.PowerState.BLANK && receiverStates[1] == Modulator.PowerState.GREEN) || (receiverStates[0] == Modulator.PowerState.GREEN && receiverStates[1] == Modulator.PowerState.BLANK)){
            sprite.sprite = analyzerGreen;
        }
        if ((receiverStates[0] == Modulator.PowerState.BLANK && receiverStates[1] == Modulator.PowerState.RED) || (receiverStates[0] == Modulator.PowerState.RED && receiverStates[1] == Modulator.PowerState.BLANK)){
            sprite.sprite = analyzerRed;
        }
        if ((receiverStates[0] == Modulator.PowerState.BLUE && receiverStates[1] == Modulator.PowerState.RED) || (receiverStates[0] == Modulator.PowerState.RED && receiverStates[1] == Modulator.PowerState.BLUE)){
            sprite.sprite = analyzerPurple;
        }
        if ((receiverStates[0] == Modulator.PowerState.BLUE && receiverStates[1] == Modulator.PowerState.GREEN) || (receiverStates[0] == Modulator.PowerState.GREEN && receiverStates[1] == Modulator.PowerState.BLUE)){
            sprite.sprite = analyzerCyan;
        }
        if ((receiverStates[0] == Modulator.PowerState.GREEN && receiverStates[1] == Modulator.PowerState.RED) || (receiverStates[0] == Modulator.PowerState.RED && receiverStates[1] == Modulator.PowerState.GREEN)){
            sprite.sprite = analyzerGold;
        }
    }
}
