Skip to content

Commit

Permalink
incc: more validation
Browse files Browse the repository at this point in the history
  • Loading branch information
manavortex committed Jan 17, 2025
1 parent 605b49f commit a4d5dfc
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions Scripts/Internal/FileValidation/inkcc.wscript
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,57 @@ const validLinks = {
],
}

const allOptionNames = [];

function validateGameuiAppearanceInfo(debugInfo, gameUiAppearanceOptions, slotGroups) {
// Logger.Success(gameUiAppearanceOptions);

// if a resource is linked: check it
if (gameUiAppearanceOptions["resource"] && gameUiAppearanceOptions["resource"]["DepotPath"]) {
checkDepotPath(stringifyPotentialCName(gameUiAppearanceOptions["resource"]["DepotPath"]), debugInfo);
}

allOptionNames.push(stringifyWithSpaces(gameUiAppearanceOptions["name"], debugInfo));
}

function validateGameuiSwitcherOptions(groupKey, debugText, gameUiSwitcherOptions, slotGroupsResolved) {


function validateGameuiSwitcherOptions(groupKey, gameUiSwitcherOptions, slotGroups) {

const groups = {};
slotGroups.forEach((sg) => {
groups[stringifyWithSpaces(sg.name)] = (sg.options ?? []).map((name) => stringifyWithSpaces(name));
});

for (let i = 0; i < gameUiSwitcherOptions.length; i++) {
const gameSwitcherOption = gameUiSwitcherOptions[i];

const optionNames = gameSwitcherOption["names"].map(name => stringifyWithSpaces(name));
optionNames.forEach(name => {
allOptionNames.push(name);
let found = false;
Object.keys(groups).forEach(key => {
if (groups[key].includes(name)) {
Object.keys(slotGroupsResolved).forEach(key => {
if (slotGroupsResolved[key].includes(name)) {
found = true;
}
})
});
if (!found) {
Logger.Error(`${groupKey}: option[${i}] includes the name ${name}, which is not defined in any slot group: ${stringifyMap(groups, true)}`)
Logger.Error(`${debugText}.options[${i}] includes the name ${name}, which is not defined in any slot group: ${stringifyMap(groups, true)}`)
}
});

const validTagsForGroup = validTags[groupKey] ?? [];
const invalidTags = gameSwitcherOption.tags.tags.map((tag) => stringifyWithSpaces(tag)).filter((tag) => !validTagsForGroup.includes(tag));
if (invalidTags.length > 0) {
Logger.Warning(`${groupKey}: option[${i}] has invalid tags ${invalidTags.join(", ")} (valid tags are ${validTags.join(", ")})`);
Logger.Warning(`${debugText}: option[${i}] has invalid tags ${invalidTags.join(", ")} (valid tags are ${validTags.join(", ")})`);
}
}

}

function validateCustomizationOptions(groupKey, customizationOptions, slotGroups) {
if (customizationOptions.length === 0 && slotGroups.length === 0) {
function validateCustomizationOptions(groupKey, customizationOptions, slotGroupsResolved) {
if (customizationOptions.length === 0 && slotGroupsResolved.length === 0) {
return;
}

allOptionNames.splice(0, allOptionNames.length);

for (let i = 0; i < customizationOptions.length; i++) {
const opt = customizationOptions[i];
const option = opt["Data"];
Expand All @@ -73,7 +86,6 @@ function validateCustomizationOptions(groupKey, customizationOptions, slotGroups
Logger.Error(`${groupKey}: customizationOptions[${i}] has no name (only the first can be empty)`);
}


const validLinksForGroup = validLinks[groupKey] ?? [];
if (link !== "None" && !validLinksForGroup.includes(link)) {
Logger.Warning(`${groupKey}: option[${i}] links to '${link}' (we only know ${validLinksForGroup.join(", ")})`);
Expand All @@ -82,14 +94,25 @@ function validateCustomizationOptions(groupKey, customizationOptions, slotGroups

switch (option["$type"]) {
case "gameuiSwitcherInfo":
validateGameuiSwitcherOptions(groupKey, option["options"], slotGroups);
validateGameuiSwitcherOptions(groupKey, `${groupKey}.customizationOptions[${i}]`, option["options"], slotGroupsResolved);
break;
case "gameuiAppearanceInfo":
validateGameuiAppearanceInfo(`${groupKey}.customizationOptions[${i}]`, option, slotGroupsResolved);
break;

default:
break;

}
}

// now that we collected all appearance names, let's check if we are missing any
Object.keys(slotGroupsResolved).forEach(key => {
const namesNotFound = slotGroupsResolved[key].filter(name => !allOptionNames.includes(name));
if (namesNotFound.length === 0) {
return;
}
Logger.Warning(`${groupKey}: slot group '${key}' contains names that are not used in any customization option: ${namesNotFound.join(", ")}`);
});
}

const customizationOptions = {
Expand All @@ -112,12 +135,17 @@ export function validateInkCCFile(inkcc, _inkccSettings) {
Object.keys(customizationOptions).forEach((key) => {
const groupKey = customizationOptions[key];
const option = inkcc[key];
const groupOptions = inkcc[groupKey];
const slotGroups = inkcc[groupKey];

const slotGroupsResolved = {};
slotGroups.forEach((sg) => {
slotGroupsResolved[stringifyWithSpaces(sg.name)] = (sg.options ?? []).map((name) => stringifyWithSpaces(name));
});

validateCustomizationOptions(
key.replace("CustomizationOptions", ""),
option,
groupOptions);
slotGroupsResolved);
});

}
Expand Down

0 comments on commit a4d5dfc

Please sign in to comment.