export class ShinyStarFactory {
    scene;
    constructor(scene) {
        this.scene = scene;
    }
    create(group) {
        const shinyStar = new ShinyStar(this.scene);
        group.add(shinyStar);
        return shinyStar;
    }
}
export class ShinyStar extends Phaser.Physics.Arcade.Sprite {
    scene;
    constructor(scene) {
        const x = 0;
        const y = 0;
        super(scene, x, y, "shiny-star");
        this.scene = scene;
        scene.add.existing(this);
        scene.physics.add.existing(this);
        this.init();
        this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update, this);
        this.once(Phaser.GameObjects.Events.DESTROY, this.cleanup, this);
    }
    init() {
        this
            .setOrigin(0, 1)
            .setCollideWorldBounds(false)
            .setBodySize(120, 120)
            .setOffset(-5, 12)
            .setDepth(2);
        // Handle resizing
        this.scene.scale.on('resize', this.scaleToFit, this);
        this.scene.scale.on('resize', this.positionOnSky, this);
        this.scaleToFit();
        this.positionOnSky();
    }
    positionOnSky() {
        const possibleHeight = [450 * (this.scene.sky?.scaleFactors.height || 1), 450 * (this.scene.sky?.scaleFactors.height || 1)];
        const shinyStarHeight = possibleHeight[Math.floor(Math.random() * 2)];
        const groundTopY = this.scene.ground?.y ?? this.scene.scale.height;
        const y = groundTopY - shinyStarHeight;
        this.setY(y - 10);
        const distance = Phaser.Math.Between(this.scene.scale.width, this.scene.scale.width * 2);
        this.setX(distance);
    }
    scaleToFit() {
        // Use the scale factor from the Sky class to maintain consistency
        const scaleFactor = this.scene.sky?.scaleFactors.height || 1;
        const width = 85;
        const height = 85;
        // Apply the scale factor to the ShinyStar
        this.setDisplaySize(width * scaleFactor, height * scaleFactor);
    }
    update() {
    }
    cleanup() {
        this.scene?.events.off(Phaser.Scenes.Events.UPDATE, this.update, this);
        this.scene?.scale.off('resize', this.scaleToFit, this);
        this.scene?.scale.off('resize', this.positionOnSky, this);
    }
}
