﻿import { MainApp } from '../babylonjs/MainApp';

/**
 * Kernel 转接器类 - 封装 mainApp 的功能，提供统一�?API 接口
 */
export class KernelAdapter {
  private mainApp: MainApp;

  constructor(mainApp: MainApp) {
    this.mainApp = mainApp;
  }

  /** 模型管理 */
  model = {
    /**
     * 销毁指定模�?     * @param modelName 模型名称
     */
    destroy: (modelName: string): void => {
      this.mainApp.appModel.destroyModel(modelName);
    }
  };

  /** 材质管理 */
  material = {
    /**
     * 应用材质
     * @param options 材质应用选项
     */
    apply: (options: { target: string; attribute: string,value:number|string }): void => {
      this.mainApp.gameManager.applyMaterial(options.target, options.attribute,options.value);
    }
  };

  /** 卷帘门控�?*/
  door = {
    /** 再次调用会自动反向动�?*/
    toggle: (options?: { upY?: number; downY?: number; speed?: number; meshNames?: string[] }): void => {
      this.mainApp.gameManager.toggleRollerDoor(options);
    },
    /** 显式设置开/�?*/
    setState: (open: boolean, options?: { upY?: number; downY?: number; speed?: number; meshNames?: string[] }): void => {
      this.mainApp.gameManager.setRollerDoorState(open, options);
    },
    /** 当前是否已开�?*/
    isOpen: (): boolean => {
      return this.mainApp.gameManager.isRollerDoorOpen();
    }
  };

  /** Y 轴剖�?*/
  clipping = {
    /** �������и߶ȣ�keepAbove=true ʱ�������ϲ��֣�onlyMeshNames Ϊ��Ĭ�Ͻ����þ����ţ�excludeMeshNames �����ų������е����� */
    setY: (height: number, keepAbove = true, onlyMeshNames?: string[], excludeMeshNames?: string[]): void => {
      this.mainApp.gameManager.setYAxisClip(height, keepAbove, onlyMeshNames, excludeMeshNames);
    },
    /** 关闭剖切 */
    clear: (): void => {
      this.mainApp.gameManager.clearYAxisClip();
    }
  };

  /** 热点管理 */
  hotspot = {
    /**
     * 渲染热点
     * @param hotspots 热点数据
     */
    render: (hotspots: any[]): void => {
      this.mainApp.appRay.renderHotspots(hotspots);
    }
  };
  /** 调试工具 */
  debug = {
    /** 列出当前场景网格名称 */
    listMeshNames: (): string[] => {
      return this.mainApp.gameManager.listMeshNames();
    }
  };
}