From 48f5a07afd8cd5630d40f77c4f6d7f76ac75302f Mon Sep 17 00:00:00 2001 From: Lordmau5 Date: Thu, 10 Dec 2020 16:10:15 +0100 Subject: [PATCH] Add partial OGG search No need to write out the full name for a song anymore. Errors if more than 1 matches Example: "daytona_usa_lets_go_away" All you need is "daytona", "usa" or "lets_go". --- index.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b756745..f80947a 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ async function moggify() { const files = await fs.promises.readdir('mogg_input'); for(const file of files) { - console.log(file); + console.log(`Converting ${file}...`); const from = path.join('mogg_input', file); const tmp = path.join('tmp', path.parse(file).name + '.mogg'); @@ -36,6 +36,30 @@ async function moggify() { } } +async function findOGG(name) { + const files = await fs.promises.readdir('mogg_output'); + + const found = []; + + for(const file of files) { + if (file.toLowerCase().includes(name.toLowerCase())) { + found.push(file); + } + } + + if (found.length === 0) { + console.error(`Couldn't find mogg with name "${name}".`); + return false; + } + + if (found.length > 1) { + console.error(`Found more than 1 mogg with name "${name}".`); + return false; + } + + return found[0]; +} + async function replace() { if (process.argv.length !== 4) { console.error('Usage: node replace.js '); @@ -43,15 +67,13 @@ async function replace() { return; } - const mogg_file = process.argv[2] + '.mogg'; + const mogg_file = await findOGG(process.argv[2]); const game_file = process.argv[3]; - const mogg_exists = await fileExists(`mogg_output/${mogg_file}`); const uexp_exists = await fileExists(`game_input/${game_file}.uexp`); const uasset_exists = await fileExists(`game_input/${game_file}.uasset`); - if (!mogg_exists) { - console.error(`Couldn't find the .mogg file '${mogg_file}'.`); + if (!mogg_file) { return; }