diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/editor.mjs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index c121eb0..dfafaa9 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
| @@ -833,25 +833,31 @@ new window.MutationObserver(mutaions => { | |||
| 833 | // }}} | 833 | // }}} |
| 834 | 834 | ||
| 835 | /** | 835 | /** |
| 836 | * addMapRandomlyByPreset. insert text of valid mapclay yaml into editor | 836 | * addMapRandomlyByPreset. insert random text of valid mapclay yaml into editor |
| 837 | */ | 837 | */ |
| 838 | const addMapRandomlyByPreset = () => { | 838 | const addMapRandomlyByPreset = () => { |
| 839 | const yamlText = [ | ||
| 840 | 'apply: dist/default.yml', | ||
| 841 | 'width: 85%', | ||
| 842 | 'height: 200px', | ||
| 843 | ] | ||
| 839 | const order = [ | 844 | const order = [ |
| 845 | 'id', | ||
| 846 | 'apply', | ||
| 840 | 'use', | 847 | 'use', |
| 848 | 'width', | ||
| 849 | 'height', | ||
| 841 | 'center', | 850 | 'center', |
| 842 | 'XYZ', | 851 | 'XYZ', |
| 843 | 'zoom' | 852 | 'zoom' |
| 844 | ] | 853 | ] |
| 845 | const aliasesEntries = Object.entries(aliasesForMapOptions) | 854 | const aliasesEntries = Object.entries(aliasesForMapOptions) |
| 846 | .sort((a, b) => order.indexOf(a) < order.indexOf(b)) | 855 | .filter(([key, _]) => |
| 847 | .filter(([key, _]) => order.includes(key)) | 856 | order.includes(key) |
| 857 | && !yamlText.find(text => text.startsWith(key)) | ||
| 858 | ) | ||
| 848 | if (aliasesEntries.length === 0) return | 859 | if (aliasesEntries.length === 0) return |
| 849 | 860 | ||
| 850 | const yamlText = [ | ||
| 851 | 'apply: dist/default.yml', | ||
| 852 | 'width: 100%', | ||
| 853 | 'height: 200px', | ||
| 854 | ] | ||
| 855 | aliasesEntries.forEach(([option, aliases]) => { | 861 | aliasesEntries.forEach(([option, aliases]) => { |
| 856 | const entries = Object.entries(aliases) | 862 | const entries = Object.entries(aliases) |
| 857 | const validEntries = entries | 863 | const validEntries = entries |
| @@ -869,9 +875,15 @@ const addMapRandomlyByPreset = () => { | |||
| 869 | const randomValue = validEntries | 875 | const randomValue = validEntries |
| 870 | .at((Math.random() * validEntries.length) | 0) | 876 | .at((Math.random() * validEntries.length) | 0) |
| 871 | .at(0) | 877 | .at(0) |
| 878 | |||
| 872 | yamlText.push(`${option}: ${typeof randomValue === 'object' ? randomValue.value : randomValue}`) | 879 | yamlText.push(`${option}: ${typeof randomValue === 'object' ? randomValue.value : randomValue}`) |
| 880 | |||
| 881 | if (option === 'center') yamlText.push(`id: ${randomValue}`) | ||
| 873 | }) | 882 | }) |
| 874 | 883 | ||
| 884 | yamlText.sort((a, b) => | ||
| 885 | order.indexOf(a.split(':')[0]) > order.indexOf(b.split(':')[0]) | ||
| 886 | ) | ||
| 875 | cm.replaceRange( | 887 | cm.replaceRange( |
| 876 | '\n```map\n' + yamlText.join('\n') + '\n```\n', | 888 | '\n```map\n' + yamlText.join('\n') + '\n```\n', |
| 877 | cm.getCursor() | 889 | cm.getCursor() |