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".
This commit is contained in:
Lordmau5 2020-12-10 16:10:15 +01:00
parent fa71f5771e
commit 48f5a07afd

View File

@ -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 <input_mogg_file> <input_game_file>');
@ -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;
}