浏览代码

updated to use enum for `initialTab` option

ycw 5 年之前
父节点
当前提交
4501649cdf
共有 2 个文件被更改,包括 35 次插入33 次删除
  1. 7 20
      inspector/src/components/actionTabs/actionTabsComponent.tsx
  2. 28 13
      src/Debug/debugLayer.ts

+ 7 - 20
inspector/src/components/actionTabs/actionTabsComponent.tsx

@@ -2,6 +2,7 @@ import * as React from "react";
 import { Nullable } from "babylonjs/types";
 import { Observer } from "babylonjs/Misc/observable";
 import { Scene } from "babylonjs/scene";
+import { DebugLayerTab } from "babylonjs/Debug/debugLayer";
 import { TabsComponent } from "./tabsComponent";
 import { faFileAlt, faWrench, faBug, faChartBar, faCog } from '@fortawesome/free-solid-svg-icons';
 import { StatisticsTabComponent } from "./tabs/statisticsTabComponent";
@@ -25,19 +26,9 @@ interface IActionTabsComponentProps {
     onPopup?: () => void,
     onClose?: () => void,
     globalState?: GlobalState,
-    initialTab?: string
+    initialTab?: DebugLayerTab
 }
 
-const ACTION_TAB_INDEX: {
-    [k: string]: number
-} = {
-    PROPERTIES: 0,
-    DEBUG: 1,
-    STATISTICS: 2,
-    TOOLS: 3,
-    SETTINGS: 4
-};
-
 export class ActionTabsComponent extends React.Component<IActionTabsComponentProps, { selectedEntity: any, selectedIndex: number }> {
     private _onSelectionChangeObserver: Nullable<Observer<any>>;
     private _onTabChangedObserver: Nullable<Observer<any>>;
@@ -46,19 +37,15 @@ export class ActionTabsComponent extends React.Component<IActionTabsComponentPro
     constructor(props: IActionTabsComponentProps) {
         super(props);
 
-        let initialIndex = ACTION_TAB_INDEX.PROPERTIES;
-        if (props.initialTab !== undefined) {
-            let index = ACTION_TAB_INDEX[props.initialTab.toUpperCase()];
-            if (index !== undefined) {
-                initialIndex = index;
-            }
-        }
+        let initialIndex = props.initialTab === undefined 
+            ? DebugLayerTab.PROPERTIES
+            : props.initialTab
 
         if (this.props.globalState) {
             const validationResutls = this.props.globalState.validationResults;
             if (validationResutls) {
                 if (validationResutls.issues.numErrors || validationResutls.issues.numWarnings) {
-                    initialIndex = ACTION_TAB_INDEX.TOOLS;
+                    initialIndex = DebugLayerTab.TOOLS;
                 }
             }
         }
@@ -70,7 +57,7 @@ export class ActionTabsComponent extends React.Component<IActionTabsComponentPro
     componentDidMount() {
         if (this.props.globalState) {
             this._onSelectionChangeObserver = this.props.globalState.onSelectionChangedObservable.add((entity) => {
-                this.setState({ selectedEntity: entity, selectedIndex: ACTION_TAB_INDEX.PROPERTIES });
+                this.setState({ selectedEntity: entity, selectedIndex: DebugLayerTab.PROPERTIES });
             });
 
             this._onTabChangedObserver = this.props.globalState.onTabChangedObservable.add(index => {

+ 28 - 13
src/Debug/debugLayer.ts

@@ -81,9 +81,9 @@ export interface IInspectorOptions {
      */
     inspectorURL?: string;
     /**
-     * Optional initial tab (default to DebugLayer.ACTION_TAB.PROPERTIES)
+     * Optional initial tab (default to DebugLayerTab.PROPERTIES)
      */
-    initialTab?: string;
+    initialTab?: DebugLayerTab.PROPERTIES;
 }
 
 declare module "../scene" {
@@ -113,6 +113,32 @@ Object.defineProperty(Scene.prototype, "debugLayer", {
 });
 
 /**
+ * Enum of inspector action tab
+ */
+export enum DebugLayerTab {
+    /**
+     * Properties tag (default)
+     */
+    PROPERTIES = 0,
+    /**
+     * Debug tab
+     */
+    DEBUG = 1,
+    /**
+     * Statistics tab
+     */
+    STATISTICS = 2,
+    /**
+     * Tools tab
+     */
+    TOOLS = 3,
+    /**
+     * Settings tab
+     */
+    SETTINGS = 4
+}
+
+/**
  * The debug layer (aka Inspector) is the go to tool in order to better understand
  * what is happening in your scene
  * @see http://doc.babylonjs.com/features/playground_debuglayer
@@ -125,17 +151,6 @@ export class DebugLayer {
      */
     public static InspectorURL = `https://unpkg.com/babylonjs-inspector@${Engine.Version}/babylon.inspector.bundle.js`;
 
-    /**
-     * Action tab kinds
-     */
-    public static ACTION_TAB = {
-        PROPERTIES: "properties",
-        DEBUG: "debug",
-        STATISTICS: "statistics",
-        TOOLS: "tools",
-        SETTINGS: "settings"
-    };
-
     private _scene: Scene;
 
     private BJSINSPECTOR = this._getGlobalInspector();