import PlayScene from "../scenes/PlayScene";

export class RightWall extends Phaser.GameObjects.TileSprite {
    scene: PlayScene;
    heightScaled: number = 0;
    scaleFactor: number = 0;

    constructor(scene: PlayScene) {
        const x = 0;
        const y = 0;
        const width = 10;
        const height = 1000;
        super(scene, x, y, width, height, "");
        this.scene = scene;
        scene.add.existing(this);
        scene.physics.add.existing(this, false);

        // make wall immovable
        (this.body as Phaser.Physics.Arcade.Body).setImmovable(true);

        this.init();
        this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update, this);
    }

    init() {
        this
            .setOrigin(0, 0)
            .setVisible(false)
            .setDepth(2);

        this.scaleToFit();
        // Handle resizing
        this.scene.scale.once('resize', this.scaleToFit, this);
        this.scene.scale.once('resize', this.positionOnMountain, this);

        this.scaleToFit();
        this.positionOnMountain();
    }

    positionOnMountain() {
        this.setY(0);
        this.setX(this.scene.scale.width - 10);
    }

    scaleToFit() {
        // Use the scale factor from the Sky class to maintain consistency
        const scaleFactor = this.scene.mountain?.scaleFactors.height || 1;
        const height = this.height * scaleFactor;
        // // Apply the scale factor to the player
        this.setDisplaySize(this.width, height);
    }

    update() {
        // this.tilePositionX += (this.scene.gameSpeed * this.scene.gameSpeedModifier);
    }
}
