@@ -37,63 +37,43 @@ function toStandaloneToolHref(entryPoint) {
3737 return normalized ? `/tools/${ encodeURI ( normalized ) } ` : "" ;
3838}
3939
40- function shouldUsePresetRoundtrip ( sample , toolId ) {
41- const sampleId = normalize ( sample ?. id ) ;
42- const samplePhase = normalize ( sample ?. phase ) ;
43- if ( ! sampleId || ! samplePhase ) {
44- return false ;
40+ function normalizePresetPath ( value ) {
41+ const normalized = normalize ( value ) . replace ( / \\ / g, "/" ) ;
42+ if ( ! normalized || normalized . includes ( ".." ) ) {
43+ return "" ;
4544 }
46- if ( samplePhase === "12" && sampleId === "1208" ) {
47- return toolId === "tile-map-editor"
48- || toolId === "parallax-editor"
49- || toolId === "vector-asset-studio" ;
45+ if ( normalized . startsWith ( "/samples/" ) ) {
46+ return normalized ;
5047 }
51- if ( toolId === "parallax-editor" ) {
52- return ( sampleId === "0306" && samplePhase === "03" )
53- || ( sampleId === "1204" && samplePhase === "12" )
54- || ( sampleId === "1205" && samplePhase === "12" ) ;
48+ if ( normalized . startsWith ( "samples/" ) ) {
49+ return `/${ normalized } ` ;
5550 }
56- if ( toolId === "tile-map-editor" ) {
57- return ( sampleId === "0221" && samplePhase === "02" )
58- || ( sampleId === "0305" && samplePhase === "03" )
59- || ( sampleId === "1209" && samplePhase === "12" )
60- || ( sampleId === "1210" && samplePhase === "12" )
61- || ( sampleId === "1211" && samplePhase === "12" ) ;
51+ if ( normalized . startsWith ( "./samples/" ) ) {
52+ return `/${ normalized . slice ( 2 ) } ` ;
6253 }
63- if ( toolId === "performance-profiler" ) {
64- return ( sampleId === "0512" && samplePhase === "05" )
65- || ( sampleId === "1407" && samplePhase === "14" ) ;
66- }
67- if ( toolId === "physics-sandbox" ) {
68- return ( sampleId === "0303" && samplePhase === "03" )
69- || ( sampleId === "1606" && samplePhase === "16" ) ;
70- }
71- if ( toolId === "replay-visualizer" ) {
72- return ( sampleId === "0708" && samplePhase === "07" )
73- || ( sampleId === "1315" && samplePhase === "13" )
74- || ( sampleId === "1406" && samplePhase === "14" ) ;
75- }
76- if ( toolId === "vector-map-editor" ) {
77- return sampleId === "0901" && samplePhase === "09" ;
78- }
79- if ( toolId === "sprite-editor" ) {
80- return ( sampleId === "0207" && samplePhase === "02" )
81- || ( sampleId === "0213" && samplePhase === "02" )
82- || ( sampleId === "0214" && samplePhase === "02" )
83- || ( sampleId === "0219" && samplePhase === "02" )
84- || ( sampleId === "0224" && samplePhase === "02" )
85- || ( sampleId === "0301" && samplePhase === "03" )
86- || ( sampleId === "0302" && samplePhase === "03" )
87- || ( sampleId === "0905" && samplePhase === "09" )
88- || ( sampleId === "1414" && samplePhase === "14" ) ;
89- }
90- return false ;
54+ return "" ;
9155}
9256
93- function getRoundtripPresetPath ( sample , toolId ) {
94- const sampleId = normalize ( sample ?. id ) ;
95- const samplePhase = normalize ( sample ?. phase ) ;
96- return `/samples/phase-${ samplePhase } /${ sampleId } /sample-${ sampleId } -${ toolId } .json` ;
57+ function getExplicitRoundtripPresetPath ( sample , toolId ) {
58+ const safeToolId = normalizeToken ( toolId ) ;
59+ if ( ! safeToolId ) {
60+ return "" ;
61+ }
62+ const mappedEntries = asArray ( sample ?. roundtripToolPresets ) ;
63+ for ( const entry of mappedEntries ) {
64+ if ( ! entry || typeof entry !== "object" ) {
65+ continue ;
66+ }
67+ const mappedToolId = normalizeToken ( entry . toolId ) ;
68+ if ( mappedToolId !== safeToolId ) {
69+ continue ;
70+ }
71+ const presetPath = normalizePresetPath ( entry . presetPath ) ;
72+ if ( presetPath ) {
73+ return presetPath ;
74+ }
75+ }
76+ return "" ;
9777}
9878
9979function buildRoundtripLinks ( sample , toolRegistryMap ) {
@@ -116,8 +96,8 @@ function buildRoundtripLinks(sample, toolRegistryMap) {
11696
11797 let href = baseHref ;
11898 let label = `Open ${ normalize ( tool . displayName ) || normalize ( tool . name ) || toolId } ` ;
119- if ( shouldUsePresetRoundtrip ( sample , toolId ) ) {
120- const presetPath = getRoundtripPresetPath ( sample , toolId ) ;
99+ const presetPath = getExplicitRoundtripPresetPath ( sample , toolId ) ;
100+ if ( presetPath ) {
121101 href = `${ baseHref } ?sampleId=${ encodeURIComponent ( sample . id ) } &sampleTitle=${ encodeURIComponent ( sample . title || "" ) } &samplePresetPath=${ encodeURIComponent ( presetPath ) } ` ;
122102 }
123103
0 commit comments