class SceneRules extends Phaser.Scene
{
    constructor ()
    {
        super({ key: 'Info', active: true });
    }

    create (data)
    {
        this.parent = data.scene;
        this.vDelta = data.vDelta;
        this.x = data.x;
        this.y = data.y;

        this.pY = 0;

        this.imagekey = data.imagekey;

        this.f = this.textures.getFrame(data.imagekey);

        this.rt = this.add.renderTexture(220, 0, 840, 658);        

        if(this.vDelta == 0)
        {
            this.zone = this.add.zone(220, 0, 840, 658).setOrigin(0).setInteractive();
        }
        else
        {
            this.rt.setSize(840, 658);
            this.zone = this.add.zone(220, 0, 840, 1458).setOrigin(0).setInteractive();
        }

        this.zone.on('pointermove', this.onPointerMove.bind(this));
            
        this.scene.sleep();
    }

    onPointerMove(pointer)
    {
        if (pointer.isDown)
        {
            this.pY += pointer.position.y - pointer.prevPosition.y;

            if(this.vDelta == 0)
            {
                this.pY = Phaser.Math.Clamp(this.pY, -this.f.height + 658, 0);
                this.rt.setCrop(0, this.pY, 840, 658);
            }
            else
            {
                this.pY = Phaser.Math.Clamp(this.pY, -this.f.height + 1458, 0);
                this.rt.setCrop(0, this.pY, 840, 1458);
            }
        }
    }

    onOrientationChange(v)
    {
        this.vDelta = v;

        this.pY = 0;

        if(v == 0)
        {
            this.rt.setSize(840, 658);
            this.rt.setCrop(0, this.pY, 840, 658);
            this.zone.setSize(840, 658);
        }
        else
        {
            this.rt.setSize(840, 1458);
            this.rt.setCrop(0, this.pY, 840, 1458);
            this.zone.setSize(840, 1458);            
        }
    }

    update(time, delta)
    {
        this.rt.draw(this.imagekey, 0, this.pY);
    }
}
