Tests - Check if something is wrong with the variant's sprite (#1175)

* return a list of errors if something is wrong with the variant's sprite

* reformat

* added data in error message

* added read comfort + detection of missing json for existing variant

* fix an error of message display
This commit is contained in:
Greenlamp2 2024-05-20 21:40:40 +02:00 committed by GitHub
parent d2e455cdad
commit 136afa6b00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 5 deletions

View File

@ -36,10 +36,12 @@ describe("check if every variant's sprite are correctly set", () => {
function getMissingMasterlist(mlist, dirpath, excludes = []) { function getMissingMasterlist(mlist, dirpath, excludes = []) {
const errors = []; const errors = [];
const trimmedDirpath = `variant${path.sep}${dirpath.split(rootDir)[1]}`;
if (fs.existsSync(dirpath)) { if (fs.existsSync(dirpath)) {
const files = fs.readdirSync(dirpath); const files = fs.readdirSync(dirpath);
for (const filename of files) { for (const filename of files) {
const filePath = `${dirpath}${filename}` const filePath = `${dirpath}${filename}`
const trimmedFilePath = `${trimmedDirpath}${filename}`
const ext = filename.split('.')[1]; const ext = filename.split('.')[1];
const name = filename.split('.')[0]; const name = filename.split('.')[0];
if (excludes.includes(name)) continue; if (excludes.includes(name)) continue;
@ -49,20 +51,30 @@ describe("check if every variant's sprite are correctly set", () => {
if (ext !== 'json') { if (ext !== 'json') {
if (mlist.hasOwnProperty(id)) { if (mlist.hasOwnProperty(id)) {
const urlJsonFile = `${dirpath}${id}.json`; const urlJsonFile = `${dirpath}${id}.json`;
const trimmedUrlJsonFilepath = `${trimmedDirpath}${id}.json`;
const jsonFileExists = fs.existsSync(urlJsonFile); const jsonFileExists = fs.existsSync(urlJsonFile);
if (mlist[id].includes(1)) { if (mlist[id].includes(1)) {
const msg = `MISSING JSON ${urlJsonFile}`; const msg = `[${name}] MISSING JSON ${trimmedUrlJsonFilepath}`;
if (!jsonFileExists && !errors.includes(msg)) errors.push(msg); if (!jsonFileExists && !errors.includes(msg)) errors.push(msg);
} }
} }
if (!mlist.hasOwnProperty(id)) errors.push(`missing key ${id} in masterlist for ${filePath}`); if (!mlist.hasOwnProperty(id)) errors.push(`[${id}] missing key ${id} in masterlist for ${trimmedFilePath}`);
else if (mlist[id][parseInt(variant, 10) - 1] !== 2) errors.push(`the value should be 2 for the index ${parseInt(variant, 10) - 1} - ${filePath}`); else if (mlist[id][parseInt(variant, 10) - 1] !== 2) {
const urlJsonFile = `${dirpath}${name}.json`;
const trimmedUrlJsonFilepath = `${trimmedDirpath}${name}.json`;
const jsonFileExists = fs.existsSync(urlJsonFile);
if (mlist[id].includes(1)) {
const msg = `[${id}] MISSING JSON ${trimmedUrlJsonFilepath}`;
if (!jsonFileExists && !errors.includes(msg)) errors.push(msg);
}
errors.push(`[${id}] [${mlist[id]}] - the value should be 2 for the index ${parseInt(variant, 10) - 1} - ${trimmedFilePath}`);
}
} }
} else if (!mlist.hasOwnProperty(name)) errors.push(`named - missing key ${name} in masterlist for ${filePath}`);else { } else if (!mlist.hasOwnProperty(name)) errors.push(`named - missing key ${name} in masterlist for ${trimmedFilePath}`);else {
const raw = fs.readFileSync(filePath, {encoding: 'utf8', flag: 'r'}); const raw = fs.readFileSync(filePath, {encoding: 'utf8', flag: 'r'});
const data = JSON.parse(raw); const data = JSON.parse(raw);
for (const key of Object.keys(data)) { for (const key of Object.keys(data)) {
if (mlist[name][key] !== 1) errors.push(`the value should be 1 in the array ${filePath}`); if (mlist[name][key] !== 1) errors.push(`[${name}] [${mlist[name]}] - the value should be 1 for the index ${key} - ${trimmedFilePath}`);
} }
} }
} }