Skip to content

Commit

Permalink
Validation for non-existent things. better logging on delete/edit/new
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 16, 2024
1 parent d1de149 commit 2d474b4
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 79 deletions.
17 changes: 16 additions & 1 deletion src/app/helpers/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
checkQuests,
checkRecipes,
checkSpawners,
nonexistentItems,
nonexistentNPCs,
nonexistentRecipes,
validateDialogs,
validateDroptables,
validateItems,
Expand Down Expand Up @@ -41,7 +44,19 @@ export function validationMessagesForMod(
validateQuests(mod),
validateRecipes(mod),
validateSpawners(mod),
].filter((c) => c.messages.length > 0);
nonexistentItems(mod),
nonexistentNPCs(mod),
nonexistentRecipes(mod),
];

validationContainer.forEach((v) => {
if (v.messages.length !== 0) return;

v.messages.push({
type: 'good',
message: 'No abnormalities!',
});
});

return sortBy(validationContainer, 'header');
}
Expand Down
7 changes: 0 additions & 7 deletions src/app/helpers/validators/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ export function checkMapNPCDialogs(mod: IModKit): ValidationMessageGroup {
});
});

if (mapDialogValidations.messages.length === 0) {
mapDialogValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return mapDialogValidations;
}

Expand Down
128 changes: 113 additions & 15 deletions src/app/helpers/validators/item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get } from 'lodash';
import { get, groupBy } from 'lodash';
import {
IItemDefinition,
IModKit,
Expand Down Expand Up @@ -35,13 +35,6 @@ export function checkItemStats(mod: IModKit): ValidationMessageGroup {
}
});

if (itemValidations.messages.length === 0) {
itemValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return itemValidations;
}

Expand Down Expand Up @@ -112,13 +105,6 @@ export function checkItemUses(mod: IModKit): ValidationMessageGroup {
});
});

if (itemValidations.messages.length === 0) {
itemValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return itemValidations;
}

Expand All @@ -145,3 +131,115 @@ export function validateItems(mod: IModKit): ValidationMessageGroup {

return itemValidations;
}

export function nonexistentItems(mod: IModKit): ValidationMessageGroup {
const itemValidations: ValidationMessageGroup = {
header: 'Non-Existent Items',
messages: [],
};

const allItemNames = groupBy(mod.items, 'name');
allItemNames['none'] = {} as any;

mod.items.forEach((item) => {
item.containedItems?.forEach((checkRollable) => {
if (allItemNames[checkRollable.result]) return;

itemValidations.messages.push({
type: 'error',
message: `${checkRollable.result} ([item] ${item.name} -> containedItems) does not exist.`,
});
});
});

mod.npcs.forEach((npc) => {
npc.items.sack.forEach((checkRollable) => {
if (allItemNames[checkRollable.result]) return;

itemValidations.messages.push({
type: 'error',
message: `${checkRollable.result} ([npc] ${npc.npcId} -> sack) does not exist.`,
});
});

Object.keys(npc.items.equipment).forEach((itemslot) => {
npc.items.equipment[itemslot as ItemSlotType]?.forEach(
(checkRollable) => {
if (allItemNames[checkRollable.result]) return;

itemValidations.messages.push({
type: 'error',
message: `${checkRollable.result} ([npc] ${npc.npcId} -> ${itemslot}) does not exist.`,
});
}
);
});

npc.drops.forEach((checkRollable) => {
if (allItemNames[checkRollable.result]) return;

itemValidations.messages.push({
type: 'error',
message: `${checkRollable.result} ([npc] ${npc.npcId} -> drops) does not exist.`,
});
});

npc.dropPool.items.forEach((checkRollable) => {
if (allItemNames[checkRollable.result]) return;

itemValidations.messages.push({
type: 'error',
message: `${checkRollable.result} ([npc] ${npc.npcId} -> dropPool) does not exist.`,
});
});
});

mod.drops.forEach((droptable) => {
droptable.drops.forEach((checkRollable) => {
if (allItemNames[checkRollable.result]) return;

itemValidations.messages.push({
type: 'error',
message: `${checkRollable.result} ([droptable] ${
droptable.mapName || droptable.regionName || 'global drops'
}) does not exist.`,
});
});
});

mod.recipes.forEach((recipe) => {
if (!allItemNames[recipe.item]) {
itemValidations.messages.push({
type: 'error',
message: `${recipe.item} (${recipe.name}) does not exist.`,
});
}

if (recipe.transferOwnerFrom && !allItemNames[recipe.transferOwnerFrom]) {
itemValidations.messages.push({
type: 'error',
message: `${recipe.transferOwnerFrom} ([recipe] ${recipe.name}) does not exist.`,
});
}

recipe.ingredients?.forEach((ing) => {
if (ing && allItemNames[ing]) return;

itemValidations.messages.push({
type: 'error',
message: `${ing} ([recipe] ${recipe.name}) does not exist.`,
});
});

recipe.ozIngredients?.forEach((ing) => {
if (ing && allItemNames[ing.display]) return;

itemValidations.messages.push({
type: 'error',
message: `${ing.display} ([recipe] ${recipe.name}) does not exist.`,
});
});
});

return itemValidations;
}
21 changes: 0 additions & 21 deletions src/app/helpers/validators/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ export function checkMapSpawners(mod: IModKit): ValidationMessageGroup[] {
});
});

if (modSpawnerValidations.messages.length === 0) {
modSpawnerValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

groups.push(modSpawnerValidations);

// calculate map spawners
Expand All @@ -113,13 +106,6 @@ export function checkMapSpawners(mod: IModKit): ValidationMessageGroup[] {
});
});

if (mapSpawnerValidations.messages.length === 0) {
mapSpawnerValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

groups.push(mapSpawnerValidations);

// calculate boss validations
Expand All @@ -137,13 +123,6 @@ export function checkMapSpawners(mod: IModKit): ValidationMessageGroup[] {
});
});

if (mapLairValidations.messages.length === 0) {
mapLairValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

groups.push(mapLairValidations);

return groups;
Expand Down
48 changes: 34 additions & 14 deletions src/app/helpers/validators/npc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { groupBy } from 'lodash';
import {
IModKit,
INPCDefinition,
Expand Down Expand Up @@ -56,13 +57,6 @@ export function checkNPCUsages(mod: IModKit) {
});
});

if (npcValidations.messages.length === 0) {
npcValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return npcValidations;
}

Expand Down Expand Up @@ -90,13 +84,6 @@ export function checkNPCs(mod: IModKit) {
}
});

if (npcValidations.messages.length === 0) {
npcValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return npcValidations;
}

Expand All @@ -123,3 +110,36 @@ export function validateNPCs(mod: IModKit): ValidationMessageGroup {

return itemValidations;
}

export function nonexistentNPCs(mod: IModKit): ValidationMessageGroup {
const itemValidations: ValidationMessageGroup = {
header: 'Non-Existent NPCs',
messages: [],
};

const allNPCIds = groupBy(mod.npcs, 'npcId');

mod.spawners.forEach((spawner) => {
spawner.npcIds.forEach((checkRollable) => {
if (allNPCIds[checkRollable.result]) return;

itemValidations.messages.push({
type: 'error',
message: `${checkRollable.result} ([spawner] ${spawner.tag} -> npcIds) does not exist.`,
});
});
});

mod.quests.forEach((quest) => {
quest.requirements.npcIds.forEach((npcId) => {
if (allNPCIds[npcId]) return;

itemValidations.messages.push({
type: 'error',
message: `${npcId} ([quest] ${quest.name} -> requirements.npcIds) does not exist.`,
});
});
});

return itemValidations;
}
7 changes: 0 additions & 7 deletions src/app/helpers/validators/quest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ export function checkQuests(mod: IModKit): ValidationMessageGroup {
}
});

if (itemValidations.messages.length === 0) {
itemValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return itemValidations;
}

Expand Down
29 changes: 22 additions & 7 deletions src/app/helpers/validators/recipe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { groupBy } from 'lodash';
import {
IModKit,
IRecipe,
Expand Down Expand Up @@ -39,13 +40,6 @@ export function checkRecipes(mod: IModKit): ValidationMessageGroup {
}
});

if (itemValidations.messages.length === 0) {
itemValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return itemValidations;
}

Expand All @@ -66,3 +60,24 @@ export function validateRecipes(mod: IModKit): ValidationMessageGroup {

return itemValidations;
}

export function nonexistentRecipes(mod: IModKit): ValidationMessageGroup {
const itemValidations: ValidationMessageGroup = {
header: 'Non-Existent Recipes',
messages: [],
};

const allRecipes = groupBy(mod.recipes, 'name');

mod.items.forEach((item) => {
if (!item.recipe) return;
if (item.recipe && allRecipes[item.recipe]) return;

itemValidations.messages.push({
type: 'error',
message: `${item.recipe} ([item] ${item.name} -> recipe) does not exist.`,
});
});

return itemValidations;
}
7 changes: 0 additions & 7 deletions src/app/helpers/validators/spawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ export function checkSpawners(mod: IModKit): ValidationMessageGroup {
}
});

if (itemValidations.messages.length === 0) {
itemValidations.messages.push({
type: 'good',
message: 'No abnormalities!',
});
}

return itemValidations;
}

Expand Down
Loading

0 comments on commit 2d474b4

Please sign in to comment.