@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 5.34 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as i18n from"../../core/i18n/i18n.js";import*as Root from"../../core/root/root.js";import{Context}from"./Context.js";const UIStrings={elements:"Elements",screenshot:"Screenshot",network:"Network",memory:"Memory",javascript_profiler:"JavaScript Profiler",console:"Console",performance:"Performance",mobile:"Mobile",help:"Help",layers:"Layers",navigation:"Navigation",drawer:"Drawer",global:"Global",resources:"Resources",background_services:"Background Services",settings:"Settings",debugger:"Debugger",sources:"Sources",rendering:"Rendering"},str_=i18n.i18n.registerUIStrings("ui/legacy/ActionRegistration.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class Action extends Common.ObjectWrapper.ObjectWrapper{enabledInternal=!0;toggledInternal=!1;actionRegistration;constructor(t){super(),this.actionRegistration=t}id(){return this.actionRegistration.actionId}async execute(){if(!this.actionRegistration.loadActionDelegate)return!1;const t=await this.actionRegistration.loadActionDelegate(),e=this.id();return t.handleAction(Context.instance(),e)}icon(){return this.actionRegistration.iconClass}toggledIcon(){return this.actionRegistration.toggledIconClass}toggleWithRedColor(){return Boolean(this.actionRegistration.toggleWithRedColor)}setEnabled(t){this.enabledInternal!==t&&(this.enabledInternal=t,this.dispatchEventToListeners("Enabled",t))}enabled(){return this.enabledInternal}category(){return this.actionRegistration.category}tags(){if(this.actionRegistration.tags)return this.actionRegistration.tags.map((t=>t())).join("\0")}toggleable(){return Boolean(this.actionRegistration.toggleable)}title(){let t=this.actionRegistration.title?this.actionRegistration.title():i18n.i18n.lockedString("");const e=this.actionRegistration.options;if(e)for(const n of e)n.value!==this.toggledInternal&&(t=n.title());return t}toggled(){return this.toggledInternal}setToggled(t){console.assert(this.toggleable(),"Shouldn't be toggling an untoggleable action",this.id()),this.toggledInternal!==t&&(this.toggledInternal=t,this.dispatchEventToListeners("Toggled",t))}options(){return this.actionRegistration.options}contextTypes(){if(this.actionRegistration.contextTypes)return this.actionRegistration.contextTypes()}canInstantiate(){return Boolean(this.actionRegistration.loadActionDelegate)}bindings(){return this.actionRegistration.bindings}experiment(){return this.actionRegistration.experiment}condition(){return this.actionRegistration.condition}order(){return this.actionRegistration.order}}const registeredActionExtensions=[],actionIdSet=new Set;export function registerActionExtension(t){const e=t.actionId;if(actionIdSet.has(e))throw new Error(`Duplicate Action id '${e}': ${(new Error).stack}`);actionIdSet.add(e),registeredActionExtensions.push(new Action(t))}export function reset(){actionIdSet.clear(),registeredActionExtensions.length=0}export function getRegisteredActionExtensions(){return registeredActionExtensions.filter((t=>Root.Runtime.Runtime.isDescriptorEnabled({experiment:t.experiment(),condition:t.condition()}))).sort(((t,e)=>(t.order()||0)-(e.order()||0)))}export function maybeRemoveActionExtension(t){const e=registeredActionExtensions.findIndex((e=>e.id()===t));return!(e<0||!actionIdSet.delete(t))&&(registeredActionExtensions.splice(e,1),!0)}export var ActionCategory;!function(t){t.NONE="",t.ELEMENTS="ELEMENTS",t.SCREENSHOT="SCREENSHOT",t.NETWORK="NETWORK",t.MEMORY="MEMORY",t.JAVASCRIPT_PROFILER="JAVASCRIPT_PROFILER",t.CONSOLE="CONSOLE",t.PERFORMANCE="PERFORMANCE",t.MOBILE="MOBILE",t.HELP="HELP",t.LAYERS="LAYERS",t.NAVIGATION="NAVIGATION",t.DRAWER="DRAWER",t.GLOBAL="GLOBAL",t.RESOURCES="RESOURCES",t.BACKGROUND_SERVICES="BACKGROUND_SERVICES",t.SETTINGS="SETTINGS",t.DEBUGGER="DEBUGGER",t.SOURCES="SOURCES",t.RENDERING="RENDERING"}(ActionCategory||(ActionCategory={}));export function getLocalizedActionCategory(t){switch(t){case ActionCategory.ELEMENTS:return i18nString(UIStrings.elements);case ActionCategory.SCREENSHOT:return i18nString(UIStrings.screenshot);case ActionCategory.NETWORK:return i18nString(UIStrings.network);case ActionCategory.MEMORY:return i18nString(UIStrings.memory);case ActionCategory.JAVASCRIPT_PROFILER:return i18nString(UIStrings.javascript_profiler);case ActionCategory.CONSOLE:return i18nString(UIStrings.console);case ActionCategory.PERFORMANCE:return i18nString(UIStrings.performance);case ActionCategory.MOBILE:return i18nString(UIStrings.mobile);case ActionCategory.HELP:return i18nString(UIStrings.help);case ActionCategory.LAYERS:return i18nString(UIStrings.layers);case ActionCategory.NAVIGATION:return i18nString(UIStrings.navigation);case ActionCategory.DRAWER:return i18nString(UIStrings.drawer);case ActionCategory.GLOBAL:return i18nString(UIStrings.global);case ActionCategory.RESOURCES:return i18nString(UIStrings.resources);case ActionCategory.BACKGROUND_SERVICES:return i18nString(UIStrings.background_services);case ActionCategory.SETTINGS:return i18nString(UIStrings.settings);case ActionCategory.DEBUGGER:return i18nString(UIStrings.debugger);case ActionCategory.SOURCES:return i18nString(UIStrings.sources);case ActionCategory.RENDERING:return i18nString(UIStrings.rendering);case ActionCategory.NONE:return i18n.i18n.lockedString("")}return i18n.i18n.lockedString(t)}