import posxImg from '../images/BlueSky/posx.jpg'
import negxImg from '../images/BlueSky/negx.jpg'
import posyImg from '../images/BlueSky/posy.jpg'
import negyImg from '../images/BlueSky/negy.jpg'
import poszImg from '../images/BlueSky/posz.jpg'
import negzImg from '../images/BlueSky/negz.jpg'
import posxImgDark from '../images/Dark/posx.jpg'
import negxImgDark from '../images/Dark/negx.jpg'
import posyImgDark from '../images/Dark/posy.jpg'
import negyImgDark from '../images/Dark/negy.jpg'
import poszImgDark from '../images/Dark/posz.jpg'
import negzImgDark from '../images/Dark/negz.jpg'
/**
 * 负责天空盒的设置和还原
 */
export default class GlobalLight extends THING.Component {
  constructor(options) {
    super()
    this.options = options
  }

  onAwake() {
    const app = THING.App.current
    // 缓存默认开始的背景
    this.backgroundIntensity = app.background
  }

  /**
   * 切换到白天
   */
  day() {
    const day = [posxImg, negxImg, posyImg, negyImg, poszImg, negzImg]
    app.background = new THING.ImageTexture(day)
  }
  /**
   * 切换到黑夜
   */
  night() {
    // 天空球颜色也要暗
    const dark = [
      posxImgDark,
      negxImgDark,
      posyImgDark,
      negyImgDark,
      poszImgDark,
      negzImgDark,
    ]

    app.background = new THING.ImageTexture(dark)
  }

  onDestroy() {
    app.background = this.backgroundIntensity
  }
}
