const gray = 0xaaaaaa;
const gray_light = 0xdddddd;
const yellow = 0xffff00;
const yellow_light = 0xfff958;

const tints = [ 0xff0000, 0xee1100, 0xdd2200, 0xcc3300, 0xcc6600, 0xcc9900,  
                0xcccc00, 0xdddd00, 0xffff00, 0xcccc00, 0x99cc00, 0x66cc00,
                0x33cc00, 0x33cc33, 0x33cc66, 0x33cc99, 0x33aabb, 0x3399cc,
                0x4499cc, 0x5599cc, 0x6699cc, 0x9999cc, 0x9966cc, 0x9933cc,
                0xaa33cc, 0xcc33cc, 0xff33cc, 0xff00ff, 0xff0099, 0xff0033 ];

//fx

const CHANGE_TIME = 100;

class LightsFX
{
    constructor (scene)
    {
        this.scene = scene;

        this.upperLeftPads = [];

        this.upperLeftPads[0] = this.scene.add.image(134, 720, "ulpads", "0").setDepth(1).setScale(1, 1.40);
        this.upperLeftPads[1] = this.scene.add.image(110, 682, "ulpads", "1").setDepth(1).setScale(1, 1.40);
        this.upperLeftPads[2] = this.scene.add.image(76, 642, "ulpads", "2").setDepth(1).setScale(1, 1.40);
        this.upperLeftPads[3] = this.scene.add.image(68, 602, "ulpads", "3").setDepth(1).setScale(1, 1.40);
        this.upperLeftPads[4] = this.scene.add.image(56, 560, "ulpads", "4").setDepth(1).setScale(1, 1.40);
        this.upperLeftPads[5] = this.scene.add.image(56, 518, "ulpads", "5").setDepth(1).setScale(1, 1.40);
        this.upperLeftPads[6] = this.scene.add.image(56, 476, "ulpads", "6").setDepth(1).setScale(1, 1.40);
        this.upperLeftPads[7] = this.scene.add.image(56, 430, "ulpads", "7").setDepth(1).setScale(1, 1.40);

        this.upperRightPads = [];

        this.upperRightPads[0] = this.scene.add.image(946, 722, "urpads", "0").setDepth(1).setScale(1, 1.40);
        this.upperRightPads[1] = this.scene.add.image(968, 684, "urpads", "1").setDepth(1).setScale(1, 1.40);;
        this.upperRightPads[2] = this.scene.add.image(1010, 644, "urpads", "2").setDepth(1).setScale(1, 1.40);;
        this.upperRightPads[3] = this.scene.add.image(1016, 601, "urpads", "3").setDepth(1).setScale(1, 1.40);
        this.upperRightPads[4] = this.scene.add.image(1026, 559, "urpads", "4").setDepth(1).setScale(1, 1.40);
        this.upperRightPads[5] = this.scene.add.image(1028, 517, "urpads", "5").setDepth(1).setScale(1, 1.40);
        this.upperRightPads[6] = this.scene.add.image(1026, 473, "urpads", "6").setDepth(1).setScale(1, 1.40);
        this.upperRightPads[7] = this.scene.add.image(1036, 429, "urpads", "7").setDepth(1).setScale(1, 1.40);

        this.lowerLeftPads = [];

        this.lowerLeftPads[0] = this.scene.add.image(129, 1219, "lpads", "0").setDepth(1).setFlipX(true).setScale(1, 1.40);
        this.lowerLeftPads[1] = this.scene.add.image(128, 1186, "lpads", "1").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-2);
        this.lowerLeftPads[2] = this.scene.add.image(126, 1149, "lpads", "2").setDepth().setFlipX(true).setScale(1, 1.40).setAngle(-4);
        this.lowerLeftPads[3] = this.scene.add.image(122, 1110, "lpads", "3").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-5);
        this.lowerLeftPads[4] = this.scene.add.image(118, 1070, "lpads", "4").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-7);
        this.lowerLeftPads[5] = this.scene.add.image(113, 1025, "lpads", "5").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-9);
        this.lowerLeftPads[6] = this.scene.add.image(106, 981, "lpads", "6").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-11);
        this.lowerLeftPads[7] = this.scene.add.image(98, 935, "lpads", "7").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-14);
        this.lowerLeftPads[8] = this.scene.add.image(88, 884, "lpads", "8").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-16);
        this.lowerLeftPads[9] = this.scene.add.image(76, 831, "lpads", "9").setDepth(1).setFlipX(true).setScale(1, 1.40).setAngle(-18);

        this.lowerRightPads = [];

        this.lowerRightPads[0] = this.scene.add.image(950, 1221, "lpads", "0").setDepth(1).setScale(1, 1.40);
        this.lowerRightPads[1] = this.scene.add.image(952, 1186, "lpads", "1").setDepth(1).setScale(1, 1.40).setAngle(2);
        this.lowerRightPads[2] = this.scene.add.image(955, 1149, "lpads", "2").setDepth(1).setScale(1, 1.40).setAngle(3);
        this.lowerRightPads[3] = this.scene.add.image(958, 1110, "lpads", "3").setDepth(1).setScale(1, 1.40).setAngle(4);
        this.lowerRightPads[4] = this.scene.add.image(963, 1070, "lpads", "4").setDepth(1).setScale(1, 1.40).setAngle(6);
        this.lowerRightPads[5] = this.scene.add.image(969, 1026, "lpads", "5").setDepth(1).setScale(1, 1.40).setAngle(8);
        this.lowerRightPads[6] = this.scene.add.image(976, 981, "lpads", "6").setDepth(1).setScale(1, 1.40).setAngle(10);
        this.lowerRightPads[7] = this.scene.add.image(983, 935, "lpads", "7").setDepth(1).setScale(1, 1.40).setAngle(12);
        this.lowerRightPads[8] = this.scene.add.image(993, 882, "lpads", "8").setDepth(1).setScale(1, 1.40).setAngle(14);
        this.lowerRightPads[9] = this.scene.add.image(1004, 831, "lpads", "9").setDepth(1).setScale(1, 1.40).setAngle(16);

        this.upperLeftLights = [];

        this.upperLeftLights[0] = this.scene.add.image(118, 720, "ulights", "0").setAngle(-15).setDepth(1);
        this.upperLeftLights[1] = this.scene.add.image(68, 688, "ulights", "1").setAngle(-13).setDepth(1);
        this.upperLeftLights[2] = this.scene.add.image(68, 642,"ulights", "2").setAngle(-11).setDepth(1);
        this.upperLeftLights[3] = this.scene.add.image(56, 604, "ulights", "3").setAngle(-9).setDepth(1);
        this.upperLeftLights[4] = this.scene.add.image(56, 560, "ulights", "4").setAngle(-5).setDepth(1);
        this.upperLeftLights[5] = this.scene.add.image(46, 518, "ulights", "5").setAngle(-2).setDepth(1);
        this.upperLeftLights[6] = this.scene.add.image(46, 476, "ulights", "6").setAngle(0).setDepth(1);
        this.upperLeftLights[7] = this.scene.add.image(46, 430, "ulights", "7").setAngle(0).setDepth(1);

        this.upperRightLights = [];

        this.upperRightLights[0] = this.scene.add.image(960, 720, "ulights", "0").setAngle(15).setDepth(1);
        this.upperRightLights[1] = this.scene.add.image(1010, 690, "ulights", "1").setAngle(12).setDepth(1);
        this.upperRightLights[2] = this.scene.add.image(1010, 644, "ulights", "2").setAngle(9).setDepth(1);
        this.upperRightLights[3] = this.scene.add.image(1024, 604, "ulights", "3").setAngle(9).setDepth(1);
        this.upperRightLights[4] = this.scene.add.image(1026, 559, "ulights", "4").setAngle(6).setDepth(1).setScale(0.92, 1);
        this.upperRightLights[5] = this.scene.add.image(1036, 518, "ulights", "5").setAngle(4).setDepth(1);
        this.upperRightLights[6] = this.scene.add.image(1036, 473, "ulights", "6").setAngle(2).setDepth(1);
        this.upperRightLights[7] = this.scene.add.image(1036, 429, "ulights", "7").setAngle(0).setDepth(1);
//
        this.lowerLightsLeft = [];

        this.lowerLightsLeft[0] = this.scene.add.image(131, 1221, "dlights", "0").setDepth(1);
        this.lowerLightsLeft[1] = this.scene.add.image(128, 1186, "dlights", "1").setAngle(-1).setDepth(1);
        this.lowerLightsLeft[2] = this.scene.add.image(126, 1150, "dlights", "2").setAngle(-2).setDepth(1);
        this.lowerLightsLeft[3] = this.scene.add.image(123, 1112, "dlights", "3").setAngle(-5).setDepth(1);
        this.lowerLightsLeft[4] = this.scene.add.image(117, 1072, "dlights", "4").setAngle(-6).setDepth(1);
        this.lowerLightsLeft[5] = this.scene.add.image(110, 1027, "dlights", "5").setAngle(-7).setDepth(1);
        this.lowerLightsLeft[6] = this.scene.add.image(106, 982, "dlights", "6").setAngle(-10).setDepth(1);
        this.lowerLightsLeft[7] = this.scene.add.image(96, 936, "dlights", "7").setAngle(-12).setDepth(1);
        this.lowerLightsLeft[8] = this.scene.add.image(86, 886, "dlights", "8").setAngle(-16).setDepth(1);
        this.lowerLightsLeft[9] = this.scene.add.image(74, 832, "dlights", "9").setAngle(-16).setDepth(1);

        this.lowerLightsRight = [];

        this.lowerLightsRight[0] = this.scene.add.image(950, 1221, "dlights", "0").setDepth(1);
        this.lowerLightsRight[1] = this.scene.add.image(953, 1186, "dlights", "1").setAngle(1).setDepth(1);
        this.lowerLightsRight[2] = this.scene.add.image(955, 1150, "dlights", "2").setAngle(2).setDepth(1);
        this.lowerLightsRight[3] = this.scene.add.image(958, 1112, "dlights", "3").setAngle(5).setDepth(1);
        this.lowerLightsRight[4] = this.scene.add.image(962, 1072, "dlights", "4").setAngle(8).setDepth(1);
        this.lowerLightsRight[5] = this.scene.add.image(967, 1027, "dlights", "5").setAngle(9).setDepth(1);
        this.lowerLightsRight[6] = this.scene.add.image(974, 982, "dlights", "6").setAngle(11).setDepth(1);
        this.lowerLightsRight[7] = this.scene.add.image(982, 936, "dlights", "7").setAngle(13).setDepth(1);
        this.lowerLightsRight[8] = this.scene.add.image(991, 883, "dlights", "8").setAngle(14).setDepth(1);
        this.lowerLightsRight[9] = this.scene.add.image(1001, 831, "dlights", "9").setAngle(17).setDepth(1);

        this.centerLights = [];
//top
        this.centerLights[0] = this.scene.add.image(300, 754, "clight").setDepth(3);
        this.centerLights[1] = this.scene.add.image(340, 754, "clight").setDepth(3);
        this.centerLights[2] = this.scene.add.image(380, 754, "clight").setDepth(3);
        this.centerLights[3] = this.scene.add.image(420, 754, "clight").setDepth(3);
        this.centerLights[4] = this.scene.add.image(460, 754, "clight").setDepth(3);
        this.centerLights[5] = this.scene.add.image(500, 754, "clight").setDepth(3);
        this.centerLights[6] = this.scene.add.image(540, 754, "clight").setDepth(3);
        this.centerLights[7] = this.scene.add.image(579, 754, "clight").setDepth(3);
        this.centerLights[8] = this.scene.add.image(619, 754, "clight").setDepth(3);
        this.centerLights[9] = this.scene.add.image(659, 754, "clight").setDepth(3);
        this.centerLights[10] = this.scene.add.image(698, 754, "clight").setDepth(3);
        this.centerLights[11] = this.scene.add.image(738, 754, "clight").setDepth(3);
        this.centerLights[12] = this.scene.add.image(777, 754, "clight").setDepth(3);
//right
        this.centerLights[13] = this.scene.add.image(777, 794, "clight").setDepth(3);
        this.centerLights[14] = this.scene.add.image(777, 834, "clight").setDepth(3);
        this.centerLights[15] = this.scene.add.image(777, 874, "clight").setDepth(3);
        this.centerLights[16] = this.scene.add.image(777, 914, "clight").setDepth(3);
        this.centerLights[17] = this.scene.add.image(777, 954, "clight").setDepth(3);
        this.centerLights[18] = this.scene.add.image(777, 994, "clight").setDepth(3);
        this.centerLights[19] = this.scene.add.image(777, 1033, "clight").setDepth(3);
        this.centerLights[20] = this.scene.add.image(777, 1073, "clight").setDepth(3);
        this.centerLights[21] = this.scene.add.image(777, 1111, "clight").setDepth(3);
        this.centerLights[22] = this.scene.add.image(777, 1150, "clight").setDepth(3);
        this.centerLights[23] = this.scene.add.image(777, 1190, "clight").setDepth(3);
        this.centerLights[24] = this.scene.add.image(777, 1230, "clight").setDepth(3);
//bottom
        this.centerLights[25] = this.scene.add.image(738, 1230, "clight").setDepth(3);
        this.centerLights[26] = this.scene.add.image(698, 1230, "clight").setDepth(3);
        this.centerLights[27] = this.scene.add.image(659, 1230, "clight").setDepth(3);
        this.centerLights[28] = this.scene.add.image(619, 1230, "clight").setDepth(3);
        this.centerLights[29] = this.scene.add.image(579, 1230, "clight").setDepth(3);
        this.centerLights[30] = this.scene.add.image(540, 1230, "clight").setDepth(3);
        this.centerLights[31] = this.scene.add.image(500, 1230, "clight").setDepth(3);
        this.centerLights[32] = this.scene.add.image(460, 1230, "clight").setDepth(3);
        this.centerLights[33] = this.scene.add.image(420, 1230, "clight").setDepth(3);
        this.centerLights[34] = this.scene.add.image(380, 1230, "clight").setDepth(3);
        this.centerLights[35] = this.scene.add.image(340, 1230, "clight").setDepth(3);
        this.centerLights[36] = this.scene.add.image(300, 1230, "clight").setDepth(3);
//left        
        this.centerLights[37] = this.scene.add.image(300, 1190, "clight").setDepth(3);
        this.centerLights[38] = this.scene.add.image(300, 1150, "clight").setDepth(3);
        this.centerLights[39] = this.scene.add.image(300, 1111, "clight").setDepth(3);
        this.centerLights[40] = this.scene.add.image(300, 1073, "clight").setDepth(3);
        this.centerLights[41] = this.scene.add.image(300, 1033, "clight").setDepth(3);
        this.centerLights[42] = this.scene.add.image(300, 994, "clight").setDepth(3);        
        this.centerLights[43] = this.scene.add.image(300, 954, "clight").setDepth(3);
        this.centerLights[44] = this.scene.add.image(300, 914, "clight").setDepth(3);
        this.centerLights[45] = this.scene.add.image(300, 874, "clight").setDepth(3);
        this.centerLights[46] = this.scene.add.image(300, 834, "clight").setDepth(3);
        this.centerLights[47] = this.scene.add.image(300, 794, "clight").setDepth(3);

        this.tintpos = 0;

        this.ulpos = 0;
        this.urpos = 0;

        this.ulisup = false;
        this.urisup = false;

        this.primaryColor = Phaser.Display.Color.ValueToColor(0x000000);
        this.secondaryColor = Phaser.Display.Color.ValueToColor(0x000000);
    }

    addTint (imgarr, color)
    {
        imgarr.forEach(img => {img.setTint(color);});
    }

    setTexture (imgarr, texture)
    {
        imgarr.forEach(img => {img.setTexture(texture);});
    }

    clearTint (imgarr, tween = undefined)
    {
        imgarr.forEach(img => {img.clearTint(); img.preFX.clear()});

        if (tween != undefined)
        {
            this.scene.tweens.remove(tween);
        }
    }

    clearAllTints ()
    {
        this.upperLeftPads.forEach(img => {img.clearTint();});

        this.upperRightPads.forEach(img => {img.clearTint();});

        this.lowerLeftPads.forEach(img => {img.clearTint();});

        this.lowerRightPads.forEach(img => {img.clearTint();});

        this.upperLeftLights.forEach(img => {img.clearTint();});

        this.upperRightLights.forEach(img => {img.clearTint();});

        this.lowerLightsLeft.forEach(img => {img.clearTint();});

        this.lowerLightsRight.forEach(img => {img.clearTint();});

        this.centerLights.forEach(img => {img.clearTint();});
    }

    playFX (fx)
    {
        switch (fx)
        {
            case FX_RUNNING_LIGHTS:this.fxMovingLightsPlay();break;
            case FX_FLASHING_LIGHTS:this.fxFlashingLightsPlay();break;
            case FX_BUST_LIGHTS:this.fxBustLightsPlay();break;
            case FX_LOWER_COLOR_CHANGE:this.fxLowerColorChangePlay();break;
            case FX_UPPER_LEFT_COLOR_CHANGE:this.fxUpperLeftColorChangePlay();break;
            case FX_UPPER_RIGHT_COLOR_CHANGE:this.fxUpperRightColorChangePlay();break;
            case FX_UPPER_FLASH_LIGHTS:this.fxUpperFlashingLightsPlay();break;
        }
    }

    stopFX (fx)
    {
        switch (fx)
        {
            case FX_RUNNING_LIGHTS:this.fxMovingLightsStop();break;
            case FX_FLASHING_LIGHTS:this.fxFlashingLightsStop();break;
            case FX_BUST_LIGHTS:this.fxBustLightsStop();break;
            case FX_LOWER_COLOR_CHANGE:this.fxLowerColorChangeStop();break;
            case FX_UPPER_LEFT_COLOR_CHANGE:this.fxUpperLeftColorChangeStop();break;
            case FX_UPPER_RIGHT_COLOR_CHANGE:this.fxUpperRightColorChangeStop();break;
            case FX_UPPER_FLASH_LIGHTS:this.fxUpperFlashingLightsStop();break;
        }
    }

    fxMovingLightsPlay ()
    {
        for (let i = 0; i < this.centerLights.length; ++i)
        {
            if ((i % 2) == 0)
            {
                this.centerLights[i].setTexture("clightup");
            }
            else
            {
                this.centerLights[i].setTexture("clight");
                this.centerLights[i].setTint(gray);
            }
        }

        this.fxMovingLightsTween = this.scene.tweens.addCounter({
            
            from: 0,
            to: 100,
            duration: 100,
            repeat: -1,

            callbackScope: this,

            onRepeat: function ()
            {
                for (let i = 0; i < this.centerLights.length; ++i)
                {
                    if (this.centerLights[i].texture.key == "clightup")
                    {
                        this.centerLights[i].setTexture("clight");
                        this.centerLights[i].setTint(gray);
                    }
                    else
                    {
                        this.centerLights[i].setTexture("clightup");
                        this.centerLights[i].clearTint();
                    }
                }
            }
        });
    }

    fxMovingLightsStop ()
    {
        for (let i = 0; i < this.centerLights.length; ++i)
        {
            this.centerLights[i].setTexture("clight").clearTint();
            this.centerLights[i].preFX.clear();
        }

        if (this.fxMovingLightsTween != undefined)
        {
            this.fxMovingLightsTween.stop();

            this.scene.tweens.remove(this.fxMovingLightsTween);

            this.fxMovingLightsTween = undefined;
        }
    }

    fxFlashingLightsPlay ()
    {
        for (let i = 0; i < this.centerLights.length; ++i)
        {
            this.centerLights[i].setTexture("clightup");
        }

        this.fxFlashingLightsTween = this.scene.tweens.addCounter({
            
            from: 0,
            to: 100,
            duration: 100,
            repeat: -1,

            callbackScope: this,

            onRepeat: function ()
            {
                for (let i = 0; i < this.centerLights.length; ++i)
                {
                    if (this.centerLights[i].texture.key == "clightup")
                    {
                        this.centerLights[i].setTexture("clight");
                        this.centerLights[i].setTint(gray);
                    }
                    else
                    {
                        this.centerLights[i].setTexture("clightup");
                        this.centerLights[i].clearTint();
                    }
                }
            }
        });
    }

    fxFlashingLightsStop ()
    {
        for (let i = 0; i < this.centerLights.length; ++i)
        {
            this.centerLights[i].setTexture("clight").clearTint();
        }

        if (this.fxFlashingLightsTween != undefined)
        {
            this.fxFlashingLightsTween.stop();

            this.scene.tweens.remove(this.fxFlashingLightsTween);

            this.fxFlashingLightsTween = undefined;
        }
    }

    fxBustLightsPlay ()
    {
        for (let i = 0; i < this.centerLights.length; ++i)
        {
            this.centerLights[i].setTint(gray);
        }
    }

    fxBustLightsStop ()
    {
        for (let i = 0; i < this.centerLights.length; ++i)
        {
            this.centerLights[i].clearTint();
        }
    }

    fxLowerColorChangePlay ()
    {
        this.tintpos = 0;

        this.primaryColor = Phaser.Display.Color.ValueToColor(tints[this.tintpos++]);
        this.secondaryColor = Phaser.Display.Color.ValueToColor(tints[this.tintpos]);

        for (let i = 0; i < this.lowerLightsLeft.length; ++i)
        {
            this.lowerLightsLeft[i].setTint(this.primaryColor);
            this.lowerLeftPads[i].setTint(this.primaryColor);

            this.lowerLightsRight[i].setTint(this.primaryColor);
            this.lowerRightPads[i].setTint(this.primaryColor);
        }

        this.fxLowerColorChangeTween = this.scene.tweens.addCounter({
            from: 0,
            to: 10,
            duration: 150,
            ease: Phaser.Math.Easing.Linear,
            repeat: -1,
            
            callbackScope: this,
            
            onUpdate: tween =>
            {
                let value = tween.getValue();

                let colorObject = Phaser.Display.Color.Interpolate.ColorWithColor(this.primaryColor, this.secondaryColor, 10, value);

                let color = Phaser.Display.Color.GetColor(colorObject.r, colorObject.g, colorObject.b);

                for (let i = 0; i < this.lowerLightsLeft.length; ++i)
                {
                    this.lowerLightsLeft[i].setTint(color);
                    this.lowerLeftPads[i].setTint(color);

                    this.lowerLightsRight[i].setTint(color);
                    this.lowerRightPads[i].setTint(color);
                }
            },
            
            onRepeat: tween =>
            {
                tween.seek(0);
                
                if (++this.tintpos == tints.length)
                {
                    this.tintpos = 0;
                }

                this.primaryColor = this.secondaryColor;
                this.secondaryColor = Phaser.Display.Color.ValueToColor(tints[this.tintpos]);
            }
        })
    }

    fxLowerColorChangeStop ()
    {
        for (let i = 0; i < this.lowerLightsLeft.length; ++i)
        {
            this.lowerLightsLeft[i].clearTint();
            this.lowerLeftPads[i].clearTint();

            this.lowerLightsRight[i].clearTint();
            this.lowerRightPads[i].clearTint();
        }

        if (this.fxLowerColorChangeTween != undefined)
        {
            this.fxLowerColorChangeTween.stop();

            this.scene.tweens.remove(this.fxLowerColorChangeTween);

            this.fxLowerColorChangeTween = undefined;
        }
    }

    fxUpperLeftColorChangePlay ()
    {
        this.ulpos = 0;
        this.ulisup = true;

        this.upperLeftLights[0].setTint(gray_light);
        this.upperLeftPads[0].setTint(gray_light);

        for (let i = 1; i < this.upperLeftLights.length; ++i)
        {
            this.upperLeftLights[i].setTint(yellow);
            this.upperLeftPads[i].setTint(yellow);

            this.upperRightLights[i].setTint(yellow);
            this.upperRightPads[i].setTint(yellow);
        }

        this.ultimer = this.scene.time.delayedCall(CHANGE_TIME, this.fxUpperLeftColorChangeUpdate, [], this);
    }

    updateTint (arr, arr2, index, color)
    {
        if (color != -1)
        {
            arr[index].setTint(color);
            arr2[index].setTint(color);
        }
        else
        {
            arr[index].clearTint(color);
            arr2[index].clearTint(color);
        }
    }
    
    fxUpperLeftColorChangeUpdate()
    {
        const lights = this.upperLeftLights;
        const pads = this.upperLeftPads;
        const len = lights.length;

    // 1. Reset all to yellow (Use a simple for-loop or forEach for performance)
        for (let i = 0; i < len; i++)
        {
            this.updateTint(lights, pads, i, yellow);
        }

    // 2. Update Position
        this.ulpos += this.ulisup ? 1 : -1;

    // 3. Handle Edge Cases & Direction Flips
        if (this.ulpos >= len + 2)
        {
            this.updateTint(lights, pads, len - 1, -1);
            this.ulisup = false;
        }
        else if (this.ulpos <= -1)
        {
            this.updateTint(lights, pads, 0, -1);
            this.ulisup = true;
        } 
        else
        {
        // 4. Gradient Logic (Applied to both directions since logic was identical)
        // Set main light
            if (this.ulpos >= 0 && this.ulpos < len)
            {
                this.updateTint(lights, pads, this.ulpos, gray_light);
            }

            // Set trailing/leading accents
            if (this.ulpos - 1 >= 0 && this.ulpos - 1 < len)
            {
                this.updateTint(lights, pads, this.ulpos - 1, gray);
            }
    
            if (this.ulpos - 2 >= 0 && this.ulpos - 2 < len)
            {
                this.updateTint(lights, pads, this.ulpos - 2, gray_light);
            }
        }

    // 5. Timer Management
        if (this.ultimer) 
        {
            this.scene.time.removeEvent(this.ultimer);
        }
        
        this.ultimer = this.scene.time.delayedCall(CHANGE_TIME, this.fxUpperLeftColorChangeUpdate, [], this);
    }
/*    fxUpperLeftColorChangeUpdate ()
    {
        for (let i = 0; i < this.upperLeftLights.length; ++i)
        {
            this.updateTint (this.upperLeftLights, this.upperLeftPads, i, yellow);
        }

        if (this.ulisup)
        {
            ++this.ulpos
        }
        else
        {
            --this.ulpos;
        }

        if (this.ulpos >= this.upperLeftLights.length)
        {
            if (this.ulisup)
            {
                if (this.ulpos == this.upperLeftLights.length)
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.upperLeftLights.length - 1, gray);
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos - 2, gray_light);
                }
                else if (this.ulpos == (this.upperLeftLights.length + 1))
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.upperLeftLights.length - 1, gray_light);
                }
                else if (this.ulpos == (this.upperLeftLights.length + 2))
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.upperLeftLights.length - 1, -1);
                    this.ulisup = !this.ulisup;
                }
            }
            else
            {
                if (this.ulpos == this.upperLeftLights.length)
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.upperLeftLights.length - 1, gray);
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos - 2, gray_light);
                }
                else if (this.ulpos == (this.upperLeftLights.length + 1))
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.upperLeftLights.length - 1, gray_light);
                }
            }
        }
        else if (this.ulpos == -1)
        {
            this.updateTint(this.upperLeftLights, this.upperLeftPads, 0, -1);

            this.ulisup = !this.ulisup;
        }
        else
        {
            if (this.ulisup)
            {
                this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos, gray_light);

                if ((this.ulpos - 1) >= 0 && this.ulpos < this.upperLeftLights.length)
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos - 1, gray);

                    if ((this.ulpos - 2) >= 0 && this.ulpos < this.upperLeftLights.length)
                    {
                        this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos - 2, gray_light);
                    }
                }
                else if ((this.ulpos + 1) < this.upperLeftLights.length && this.ulpos > 1)
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos + 1, gray);
                }
            }
            else
            {
                this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos, gray_light);

                if ((this.ulpos - 1) >= 0 && this.ulpos < this.upperLeftLights.length)
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos - 1, gray);

                    if ((this.ulpos - 2) >= 0 && this.ulpos < this.upperLeftLights.length)
                    {
                        this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos - 2, gray_light);
                    }
                }
                else if ((this.ulpos + 1) < this.upperLeftLights.length && this.ulpos > 1)
                {
                    this.updateTint(this.upperLeftLights, this.upperLeftPads, this.ulpos + 1, gray);
                }
            }
        }

        if (this.ultimer != undefined)
        {
            this.scene.time.removeEvent(this.ultimer);
        }
        
        this.ultimer = this.scene.time.delayedCall(CHANGE_TIME, this.fxUpperLeftColorChangeUpdate, [], this);
    }*/

    fxUpperLeftColorChangeStop ()
    {
        for (let i = 0; i < this.upperLeftLights.length; ++i)
        {
            this.upperLeftLights[i].clearTint();
            this.upperLeftPads[i].clearTint();
        }

        this.scene.time.removeEvent(this.ultimer);
    }

    fxUpperRightColorChangePlay ()
    {
        this.urpos = this.upperRightLights.length;
        this.urisup = false;

        this.upperRightLights[this.upperRightLights.length - 1].setTint(gray_light);
        this.upperRightPads[this.upperRightLights.length - 1].setTint(gray_light);

        for (let i = 0; i < this.upperRightLights.length - 1; ++i)
        {
            this.upperRightLights[i].setTint(yellow);
            this.upperRightPads[i].setTint(yellow);
        }

        this.urtimer = this.scene.time.delayedCall(CHANGE_TIME, this.fxUpperRightColorChangeUpdate, [], this);
    }

    fxUpperRightColorChangeUpdate ()
    {
        for (let i = 0; i < this.upperRightLights.length; ++i)
        {
            this.updateTint (this.upperRightLights, this.upperRightPads, i, yellow);
        }

        if (this.urisup)
        {
            ++this.urpos
        }
        else
        {
            --this.urpos;
        }

        if (this.urpos >= this.upperRightLights.length)
        {
            if (this.urisup)
            {
                if (this.urpos == this.upperRightLights.length)
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.upperRightLights.length - 1, gray);
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos - 2, gray_light);
                }
                else if (this.urpos == (this.upperRightLights.length + 1))
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.upperRightLights.length - 1, gray_light);
                }
                else if (this.urpos == (this.upperRightLights.length + 2))
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.upperRightLights.length - 1, -1);
                    this.urisup = !this.urisup;
                }
            }
            else
            {
                if (this.urpos == this.upperRightLights.length)
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.upperRightLights.length - 1, gray);
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos - 2, gray_light);
                }
                else if (this.urpos == (this.upperRightLights.length + 1))
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.upperRightLights.length - 1, gray_light);
                }
            }
        }
        else if (this.urpos == -1)
        {
            this.updateTint(this.upperRightLights, this.upperRightPads, 0, -1);

            this.urisup = !this.urisup;
        }
        else
        {
            if (this.urisup)
            {
                this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos, gray_light);

                if ((this.urpos - 1) >= 0 && this.urpos < this.upperRightLights.length)
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos - 1, gray);

                    if ((this.urpos - 2) >= 0 && this.urpos < this.upperRightLights.length)
                    {
                        this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos - 2, gray_light);
                    }
                }
                else if ((this.urpos + 1) < this.upperRightLights.length && this.urpos > 1)
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos + 1, gray);
                }
            }
            else
            {
                this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos, gray_light);

                if ((this.urpos - 1) >= 0 && this.urpos < this.upperRightLights.length)
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos - 1, gray);

                    if ((this.urpos - 2) >= 0 && this.urpos < this.upperRightLights.length)
                    {
                        this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos - 2, gray_light);
                    }
                }
                else if ((this.urpos + 1) < this.upperRightLights.length && this.urpos > 1)
                {
                    this.updateTint(this.upperRightLights, this.upperRightPads, this.urpos + 1, gray);
                }
            }
        }

        if (this.urtimer != undefined)
        {
            this.scene.time.removeEvent(this.urtimer);
        }
        
        this.urtimer = this.scene.time.delayedCall(CHANGE_TIME, this.fxUpperRightColorChangeUpdate, [], this);
    }

    fxUpperRightColorChangeStop ()
    {
        for (let i = 0; i < this.upperRightLights.length; ++i)
        {
            this.upperRightLights[i].clearTint();
            this.upperRightPads[i].clearTint();
        }

        this.scene.time.removeEvent(this.urtimer);
    }
//
    fxUpperFlashingLightsPlay ()
    {
        for (let i = 0; i < this.upperRightLights.length; ++i)
        {
            this.upperLeftLights[i].setTint(yellow);
            this.upperLeftPads[i].setTint(yellow);
            
            this.upperRightLights[i].setTint(yellow);
            this.upperRightPads[i].setTint(yellow);
        }

        this.uflashtimer = this.scene.time.delayedCall(200, this.fxUpperFlashingLightsUpdate, [], this);
    }

    fxUpperFlashingLightsUpdate ()
    {
        if (this.upperLeftLights[0].tint == yellow)
        {
            for (let i = 0; i < this.upperRightLights.length; ++i)
            {
                this.upperLeftLights[i].clearTint();
                this.upperLeftPads[i].clearTint();
            
                this.upperRightLights[i].clearTint();
                this.upperRightPads[i].clearTint();
            }
        }
        else
        {
            for (let i = 0; i < this.upperRightLights.length; ++i)
            {
                this.upperLeftLights[i].setTint(yellow);
                this.upperLeftPads[i].setTint(yellow);
            
                this.upperRightLights[i].setTint(yellow);
                this.upperRightPads[i].setTint(yellow);
            }
        }

        if (this.uflashtimer != undefined)
        {
            this.scene.time.removeEvent(this.uflashtimer);
        }
        
        this.uflashtimer = this.scene.time.delayedCall(200, this.fxUpperFlashingLightsUpdate, [], this);
    }

    fxUpperFlashingLightsStop ()
    {
        for (let i = 0; i < this.upperRightLights.length; ++i)
        {
            this.upperLeftLights[i].clearTint();
            this.upperLeftPads[i].clearTint();
            
            this.upperRightLights[i].clearTint();
            this.upperRightPads[i].clearTint();
        }

        this.scene.time.removeEvent(this.uflashtimer);
    }
}