"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Ground = void 0;
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
class Ground extends Phaser.GameObjects.TileSprite {
  constructor(scene) {
    const x = 0;
    const y = scene.gameHeight;
    const width = scene.gameWidth;
    const height = 16;
    super(scene, x, y, width, height, "ground");
    _defineProperty(this, "heightScaled", 0);
    _defineProperty(this, "scaleFactor", 0);
    this.scene = scene;
    scene.add.existing(this);
    scene.physics.add.existing(this, false);

    // make ground immovable
    this.body.setImmovable(true);
    this.init();
    this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update, this);
  }
  init() {
    this.setOrigin(0, 0).setDepth(2);
    this.scaleToFit();
    // Handle resizing
    this.scene.scale.on('resize', this.scaleToFit, this);
    this.scene.scale.on('resize', this.positionOnSky, this);
    this.scaleToFit();
    this.positionOnSky();
  }
  positionOnSky() {
    var _this$scene$sky, _this$scene$sky2;
    const gameHeight = this.scene.scale.height;

    // Position player at the bottom of the scaled background
    const skyHeightScaled = (((_this$scene$sky = this.scene.sky) === null || _this$scene$sky === void 0 ? void 0 : _this$scene$sky.height) || 1) * (((_this$scene$sky2 = this.scene.sky) === null || _this$scene$sky2 === void 0 ? void 0 : _this$scene$sky2.scaleFactors.height) || 1);
    const y = gameHeight - (gameHeight - skyHeightScaled); // Slight offset for alignment
    this.setY(y - 10);
  }
  scaleToFit() {
    var _this$scene$sky3;
    // Use the scale factor from the Sky class to maintain consistency
    const scaleFactor = ((_this$scene$sky3 = this.scene.sky) === null || _this$scene$sky3 === void 0 ? void 0 : _this$scene$sky3.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);
  }
}
exports.Ground = Ground;