11class WorkspaceV2ToolStateProducer {
2+ static TOOL_STATE_PRODUCER_TOOL_IDS = Object . freeze ( [
3+ "asset-manager-v2" ,
4+ "svg-asset-studio-v2" ,
5+ "tilemap-studio-v2" ,
6+ "vector-map-editor-v2"
7+ ] ) ;
8+
29 constructor ( ) {
310 document . title = "Workspace V2" ;
411 document . body . dataset . toolId = "workspace-v2" ;
@@ -223,7 +230,8 @@ class WorkspaceV2ToolStateProducer {
223230 }
224231
225232 selectedToolId ( ) {
226- return typeof this . toolSelect . value === "string" ? this . toolSelect . value . trim ( ) : "" ;
233+ const selectedToolId = typeof this . toolSelect . value === "string" ? this . toolSelect . value . trim ( ) : "" ;
234+ return this . isToolStateProducerToolId ( selectedToolId ) ? selectedToolId : "" ;
227235 }
228236
229237 selectedToolStateName ( ) {
@@ -376,6 +384,17 @@ class WorkspaceV2ToolStateProducer {
376384 if ( ! this . toolSelect ) {
377385 return ;
378386 }
387+ Array . from ( this . toolSelect . options ) . forEach ( ( option ) => {
388+ if ( option . value === "palette-manager-v2" ) {
389+ option . remove ( ) ;
390+ }
391+ } ) ;
392+ const validToolIds = new Set ( WorkspaceV2ToolStateProducer . TOOL_STATE_PRODUCER_TOOL_IDS ) ;
393+ Array . from ( this . toolSelect . options ) . forEach ( ( option ) => {
394+ if ( ! validToolIds . has ( option . value ) ) {
395+ option . remove ( ) ;
396+ }
397+ } ) ;
379398 }
380399
381400 removeDiagnosticsPanelUi ( ) {
@@ -395,7 +414,7 @@ class WorkspaceV2ToolStateProducer {
395414 if ( ! this . toolSelect ) {
396415 return ;
397416 }
398- const defaultToolId = "palette -manager-v2" ;
417+ const defaultToolId = "asset -manager-v2" ;
399418 const hasDefaultOption = Array . from ( this . toolSelect . options ) . some ( ( option ) => option . value === defaultToolId ) ;
400419 if ( hasDefaultOption ) {
401420 this . toolSelect . value = defaultToolId ;
@@ -406,6 +425,26 @@ class WorkspaceV2ToolStateProducer {
406425 }
407426 }
408427
428+ isToolStateProducerToolId ( toolId ) {
429+ return (
430+ typeof toolId === "string" &&
431+ WorkspaceV2ToolStateProducer . TOOL_STATE_PRODUCER_TOOL_IDS . includes ( toolId . trim ( ) )
432+ ) ;
433+ }
434+
435+ firstToolStateProducerToolId ( ) {
436+ if ( ! this . toolSelect ) {
437+ return "" ;
438+ }
439+ const availableOptionValues = Array . from ( this . toolSelect . options )
440+ . map ( ( option ) => option . value )
441+ . filter ( ( value ) => this . isToolStateProducerToolId ( value ) ) ;
442+ if ( availableOptionValues . includes ( "asset-manager-v2" ) ) {
443+ return "asset-manager-v2" ;
444+ }
445+ return availableOptionValues . length > 0 ? availableOptionValues [ 0 ] : "" ;
446+ }
447+
409448 registerScrollTextColorRule ( ) {
410449 let textLightActive = false ;
411450 let scheduled = false ;
@@ -625,11 +664,6 @@ class WorkspaceV2ToolStateProducer {
625664 if ( ! this . toolSelect ) {
626665 return ;
627666 }
628- Array . from ( this . toolSelect . options ) . forEach ( ( option ) => {
629- if ( option . value === "palette-manager-v2" ) {
630- option . disabled = false ;
631- }
632- } ) ;
633667 this . loadFixtureButton . disabled = false ;
634668 this . launchButton . disabled = false ;
635669 }
@@ -670,20 +704,23 @@ class WorkspaceV2ToolStateProducer {
670704 return ;
671705 }
672706 const selectedToolId = this . selectedToolId ( ) ;
673- if ( ! selectedToolId ) {
674- this . statusNode . textContent = "Workspace V2 initialization blocked: default tool is missing." ;
707+ const fallbackToolId = this . firstToolStateProducerToolId ( ) ;
708+ const toolId = selectedToolId || fallbackToolId ;
709+ if ( ! toolId ) {
710+ this . statusNode . textContent = "Workspace V2 initialization blocked: no toolState-capable producer tool is available." ;
675711 return ;
676712 }
677- const initialPayload = this . createProducerPayloadForTool ( selectedToolId ) ;
713+ this . toolSelect . value = toolId ;
714+ const initialPayload = this . createProducerPayloadForTool ( toolId ) ;
678715 this . setCurrentToolStatePayload ( initialPayload , "workspace-v2-init" ) ;
679- const hostContextId = this . createHostContextToolStateId ( selectedToolId ) ;
716+ const hostContextId = this . createHostContextToolStateId ( toolId ) ;
680717 const activation = this . activateWorkspaceToolState ( hostContextId , initialPayload , "workspace-v2-init" ) ;
681718 if ( ! activation . ok ) {
682719 this . statusNode . textContent = activation . message ;
683720 return ;
684721 }
685722 this . syncWorkspaceManifestTextarea ( ) ;
686- this . statusNode . textContent = `Workspace V2 initialized.\nTool: ${ selectedToolId } \nHostContextId: ${ hostContextId } \nTool state is active for Save Tool State.` ;
723+ this . statusNode . textContent = `Workspace V2 initialized.\nTool: ${ toolId } \nHostContextId: ${ hostContextId } \nTool state is active for Save Tool State.` ;
687724 }
688725
689726 hasActiveWorkspaceToolStateForSave ( ) {
@@ -3352,7 +3389,7 @@ class WorkspaceV2ToolStateProducer {
33523389 async loadSelectedToolState ( ) {
33533390 const toolId = this . selectedToolId ( ) ;
33543391 if ( ! toolId ) {
3355- this . statusNode . textContent = "Select a V2 tool before loading a fixture ." ;
3392+ this . statusNode . textContent = "Select a toolState-capable V2 tool before loading tool state ." ;
33563393 return ;
33573394 }
33583395 try {
@@ -3500,10 +3537,11 @@ class WorkspaceV2ToolStateProducer {
35003537 manifestTools [ toolId ] = this . cloneToolStateValue ( this . workspaceImportedToolEntries [ toolId ] ) ;
35013538 } ) ;
35023539 manifestTools [ "palette-browser" ] = this . cloneToolStateValue ( activePaletteResolution . paletteBrowserPayload ) ;
3540+ const exportDefaultToolId = this . firstToolStateProducerToolId ( ) || activeToolId ;
35033541 manifestTools [ "workspace-v2" ] = {
35043542 schema : "html-js-gaming.workspace-v2-tool-state/1" ,
35053543 game : workspaceGame ,
3506- defaultToolId : "palette-manager-v2" ,
3544+ defaultToolId : exportDefaultToolId ,
35073545 activeToolId,
35083546 activeHostContextId,
35093547 activeToolState : this . cloneToolStateValue ( activePayload ) ,
@@ -3981,7 +4019,7 @@ class WorkspaceV2ToolStateProducer {
39814019 createToolStateAndLaunch ( ) {
39824020 const toolId = this . selectedToolId ( ) ;
39834021 if ( ! toolId ) {
3984- this . statusNode . textContent = "Select a V2 tool before launch ." ;
4022+ this . statusNode . textContent = "Select a toolState-capable V2 tool before opening tool state ." ;
39854023 return ;
39864024 }
39874025 if ( ! this . isValidToolStatePayload ( this . currentToolStatePayload ) ) {
0 commit comments