From f242d720ca167ac8b1cc11d372bc3c4d70d61f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?100=E3=81=AE=E4=BA=BA?= <100@pokemori.jp> Date: Sat, 13 Oct 2018 23:14:32 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E3=81=A4=E3=81=AE=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E5=86=85=E3=81=AB=E8=A4=87=E6=95=B0=E3=81=AE?= =?UTF-8?q?YAML=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=8C=E5=9F=8B=E3=82=81=E8=BE=BC=E3=81=BE=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E5=A0=B4=E5=90=88=E3=80=81=E8=B5=B7=E5=8B=95?= =?UTF-8?q?=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=A7=E8=AA=AD?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=82=80=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=92=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88?= =?UTF-8?q?=E3=82=89=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 53 +++++++++++++++++++ ...43\202\222\350\265\267\345\213\225.js.cmd" | 52 +++++++++++++----- 2 files changed, 93 insertions(+), 12 deletions(-) diff --git a/readme.md b/readme.md index e2e1c51..14dcea9 100644 --- a/readme.md +++ b/readme.md @@ -89,6 +89,59 @@ allow_direct_view: true 起動オプション -------------- +### `--esperecyan-document-index=[数字]` (0から始まる整数) +一つのファイル内に複数のYAMLドキュメントが埋め込まれていた場合、読み込むドキュメントを切り替えます。 + +例: + +```yaml +--- +niconico: + character_models: + - 32797 + - 32806 + - 32813 +--- # コメント +niconico: + character_models: + - 40000 + - 40001 + - 40023 +--- +niconico: + character_models: + - 41036 +``` + +#### `--esperecyan-document-index==0` の場合 +指定しなかった場合と同じ。 + +```json +{ + "niconico": { + "character_models": [ + 32797, + 32806, + 32813 + ] + } +} +``` + +#### `--esperecyan-document-index==1` の場合 + +```json +{ + "niconico": { + "character_models": [ + 40000, + 40001, + 40023 + ] + } +} +``` + ### `--esperecyan-niconico-character-models-offset-16x=[数字]` `niconico.character_models` の順番をズラします。 diff --git "a/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" "b/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" index c412084..0cfadec 100644 --- "a/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" +++ "b/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" @@ -113,6 +113,21 @@ function putFileContents(path, contents) stream.Close(); } +/** + * w肳ꂽR}hC̒l擾܂B + * @param {string} name + * @returns {string} + */ +function getArgument(name) +{ + for (var i = 0, l = WSH.Arguments.length; i < l; i++) { + if (WSH.Arguments(i).startsWith(name + '=')) { + return WSH.Arguments(i).replace(name + '=', ''); + } + } + return ''; +} + /** * w肳ꂽl Object łȂ΁AG[bZ[W\܂B * @param {*} config @@ -184,9 +199,9 @@ if (inputFile) { var yaml = getFileContents(inputFile.Path); - var config; + var configs; try { - config = jsyaml.safeLoad(yaml, {filename: inputFile.Path}); + configs = jsyaml.safeLoadAll(yaml, null, {filename: inputFile.Path}); } catch (exception) { if (exception.name === 'YAMLException') { var errorMessage = 'u' + inputFile.Name + 'v͉Ă܂Bȉ̃G[܂B'; @@ -206,22 +221,35 @@ if (inputFile) { } } + var config = configs[0]; + var argument = getArgument('--esperecyan-document-index'); + if (argument) { + var index = Number.parseInt(argument); + if (configs.length <= index) { + Shell.Popup( + inputFile.Name + 'ɂ' + configs.length + '‚YAMLhLg܂܂Ă̂ŁA' + + '--esperecyan-document-index ɂ0`' + (configs.length - 1) + 'w肷Kv܂B', + 0, + WSH.ScriptName, + vbOKOnly + vbCritical + ); + return; + } + config = configs[index]; + } + if (!isValidConfig(config, inputFile.Name)) { return; } if (typeof config.niconico === 'object' && config.niconico !== null && Array.isArray(config.niconico.character_models)) { - for (var i = 0, l = WSH.Arguments.length; i < l; i++) { - if (WSH.Arguments(i).startsWith('--esperecyan-niconico-character-models-offset-16x=')) { - var offset = Number.parseInt( - WSH.Arguments(i).replace('--esperecyan-niconico-character-models-offset-16x=', '') - ) * MAX_NICONICO_CHARCTER_MODELS_COUNT; - if (config.niconico.character_models.length > offset) { - config.niconico.character_models - = config.niconico.character_models.concat(config.niconico.character_models.splice(0, offset)); - } - break; + var argument = getArgument('--esperecyan-niconico-character-models-offset-16x'); + if (argument) { + var offset = Number.parseInt(argument) * MAX_NICONICO_CHARCTER_MODELS_COUNT; + if (config.niconico.character_models.length > offset) { + config.niconico.character_models + = config.niconico.character_models.concat(config.niconico.character_models.splice(0, offset)); } } }