@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 3.11 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as i18n from"../../core/i18n/i18n.js";import*as SDK from"../../core/sdk/sdk.js";const UIStrings={showInternalLayers:"Show internal layers"},str_=i18n.i18n.registerUIStrings("panels/layer_viewer/LayerViewHost.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class LayerView{}export class Selection{typeInternal;layerInternal;constructor(e,t){this.typeInternal=e,this.layerInternal=t}static isEqual(e,t){return e&&t?e.isEqual(t):e===t}type(){return this.typeInternal}layer(){return this.layerInternal}isEqual(e){return!1}}export class LayerSelection extends Selection{constructor(e){console.assert(Boolean(e),"LayerSelection with empty layer"),super("Layer",e)}isEqual(e){return"Layer"===e.typeInternal&&e.layer().id()===this.layer().id()}}export class ScrollRectSelection extends Selection{scrollRectIndex;constructor(e,t){super("ScrollRect",e),this.scrollRectIndex=t}isEqual(e){return"ScrollRect"===e.typeInternal&&this.layer().id()===e.layer().id()&&this.scrollRectIndex===e.scrollRectIndex}}export class SnapshotSelection extends Selection{snapshotInternal;constructor(e,t){super("Snapshot",e),this.snapshotInternal=t}isEqual(e){return"Snapshot"===e.typeInternal&&this.layer().id()===e.layer().id()&&this.snapshotInternal===e.snapshotInternal}snapshot(){return this.snapshotInternal}}export class LayerViewHost{views;selectedObject;hoveredObject;showInternalLayersSettingInternal;snapshotLayers;target;constructor(){this.views=[],this.selectedObject=null,this.hoveredObject=null,this.showInternalLayersSettingInternal=Common.Settings.Settings.instance().createSetting("layersShowInternalLayers",!1),this.snapshotLayers=new Map}registerView(e){this.views.push(e)}setLayerSnapshotMap(e){this.snapshotLayers=e}getLayerSnapshotMap(){return this.snapshotLayers}setLayerTree(e){if(!e)return;this.target=e.target();const t=this.selectedObject&&this.selectedObject.layer();!t||e&&e.layerById(t.id())||this.selectObject(null);const s=this.hoveredObject&&this.hoveredObject.layer();!s||e&&e.layerById(s.id())||this.hoverObject(null);for(const t of this.views)t.setLayerTree(e)}hoverObject(e){if(Selection.isEqual(this.hoveredObject,e))return;this.hoveredObject=e;const t=e&&e.layer();this.toggleNodeHighlight(t?t.nodeForSelfOrAncestor():null);for(const t of this.views)t.hoverObject(e)}selectObject(e){if(!Selection.isEqual(this.selectedObject,e)){this.selectedObject=e;for(const t of this.views)t.selectObject(e)}}selection(){return this.selectedObject}showContextMenu(e,t){e.defaultSection().appendCheckboxItem(i18nString(UIStrings.showInternalLayers),this.toggleShowInternalLayers.bind(this),this.showInternalLayersSettingInternal.get());const s=t&&t.layer()&&t.layer().nodeForSelfOrAncestor();s&&e.appendApplicableItems(s),e.show()}showInternalLayersSetting(){return this.showInternalLayersSettingInternal}toggleShowInternalLayers(){this.showInternalLayersSettingInternal.set(!this.showInternalLayersSettingInternal.get())}toggleNodeHighlight(e){e?e.highlightForTwoSeconds():SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight()}}