"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Basic = require("./Basic.js");
const Resources = require("./Resources.js");
const Earth = require("./Earth.js");
class World {
  constructor(option) {
    __publicField(this, "basic");
    __publicField(this, "scene");
    __publicField(this, "camera");
    __publicField(this, "renderer");
    __publicField(this, "controls");
    __publicField(this, "material");
    __publicField(this, "resources");
    __publicField(this, "option");
    __publicField(this, "earth");
    this.option = option;
    this.basic = new Basic.Basic(option.dom);
    this.scene = this.basic.scene;
    this.renderer = this.basic.renderer;
    this.controls = this.basic.controls;
    this.camera = this.basic.camera;
    this.updateSize();
    this.resources = new Resources.Resources(async () => {
      await this.createEarth();
      this.render();
    });
  }
  async createEarth(data) {
    this.earth = new Earth.default({
      data: data || this.option.data,
      dom: this.option.dom,
      textures: this.resources.textures,
      earth: {
        radius: 50,
        rotateSpeed: 2e-3,
        isRotation: true
      },
      satellite: {
        show: true,
        rotateSpeed: -0.01,
        size: 1,
        number: 2
      },
      punctuation: {
        circleColor: 3707647,
        lightColumn: {
          startColor: 14942335,
          // 起点颜色
          endColor: 16777215
          // 终点颜色
        }
      },
      flyLine: {
        color: 15969910,
        // 飞线的颜色
        flyLineColor: 16742164,
        // 飞行线的颜色
        speed: 4e-3
        // 拖尾飞线的速度
      }
    });
    this.scene.add(this.earth.group);
    await this.earth.init();
  }
  /**
   * 渲染函数
   */
  render() {
    requestAnimationFrame(this.render.bind(this));
    this.renderer.render(this.scene, this.camera);
    this.controls && this.controls.update();
    this.earth && this.earth.render();
  }
  // 更新
  updateSize(width, height) {
    let w = width || this.option.width;
    let h = height || this.option.height;
    if (w < h)
      h = w;
    else
      w = h;
    this.renderer.setSize(w, h);
    this.camera.aspect = w / h;
    this.camera.updateProjectionMatrix();
  }
  // 数据更新重新渲染
  updateData(data) {
    if (!this.earth.group)
      return;
    this.scene.remove(this.earth.group);
    this.earth.group.traverse((obj) => {
      if (obj.type === "Mesh") {
        obj.geometry.dispose();
        obj.material.dispose();
      }
    });
    this.createEarth(data);
  }
}
exports.default = World;
