diff --git a/src/app/helpers/validate.ts b/src/app/helpers/validate.ts index 5dd1eb2..96cd20a 100644 --- a/src/app/helpers/validate.ts +++ b/src/app/helpers/validate.ts @@ -11,6 +11,9 @@ import { checkQuests, checkRecipes, checkSpawners, + nonexistentItems, + nonexistentNPCs, + nonexistentRecipes, validateDialogs, validateDroptables, validateItems, @@ -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'); } diff --git a/src/app/helpers/validators/dialog.ts b/src/app/helpers/validators/dialog.ts index dad1597..3bcc9f1 100644 --- a/src/app/helpers/validators/dialog.ts +++ b/src/app/helpers/validators/dialog.ts @@ -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; } diff --git a/src/app/helpers/validators/item.ts b/src/app/helpers/validators/item.ts index 8d48dc3..f7fa606 100644 --- a/src/app/helpers/validators/item.ts +++ b/src/app/helpers/validators/item.ts @@ -1,4 +1,4 @@ -import { get } from 'lodash'; +import { get, groupBy } from 'lodash'; import { IItemDefinition, IModKit, @@ -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; } @@ -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; } @@ -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; +} diff --git a/src/app/helpers/validators/map.ts b/src/app/helpers/validators/map.ts index d7f8dda..f5110ab 100644 --- a/src/app/helpers/validators/map.ts +++ b/src/app/helpers/validators/map.ts @@ -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 @@ -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 @@ -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; diff --git a/src/app/helpers/validators/npc.ts b/src/app/helpers/validators/npc.ts index 46fc31a..2f3cf45 100644 --- a/src/app/helpers/validators/npc.ts +++ b/src/app/helpers/validators/npc.ts @@ -1,3 +1,4 @@ +import { groupBy } from 'lodash'; import { IModKit, INPCDefinition, @@ -56,13 +57,6 @@ export function checkNPCUsages(mod: IModKit) { }); }); - if (npcValidations.messages.length === 0) { - npcValidations.messages.push({ - type: 'good', - message: 'No abnormalities!', - }); - } - return npcValidations; } @@ -90,13 +84,6 @@ export function checkNPCs(mod: IModKit) { } }); - if (npcValidations.messages.length === 0) { - npcValidations.messages.push({ - type: 'good', - message: 'No abnormalities!', - }); - } - return npcValidations; } @@ -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; +} diff --git a/src/app/helpers/validators/quest.ts b/src/app/helpers/validators/quest.ts index 47c2f14..29019b2 100644 --- a/src/app/helpers/validators/quest.ts +++ b/src/app/helpers/validators/quest.ts @@ -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; } diff --git a/src/app/helpers/validators/recipe.ts b/src/app/helpers/validators/recipe.ts index 27ea1da..0e74213 100644 --- a/src/app/helpers/validators/recipe.ts +++ b/src/app/helpers/validators/recipe.ts @@ -1,3 +1,4 @@ +import { groupBy } from 'lodash'; import { IModKit, IRecipe, @@ -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; } @@ -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; +} diff --git a/src/app/helpers/validators/spawner.ts b/src/app/helpers/validators/spawner.ts index bdbef85..f51be84 100644 --- a/src/app/helpers/validators/spawner.ts +++ b/src/app/helpers/validators/spawner.ts @@ -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; } diff --git a/src/app/services/mod.service.ts b/src/app/services/mod.service.ts index 8607b6d..62cf7c4 100644 --- a/src/app/services/mod.service.ts +++ b/src/app/services/mod.service.ts @@ -110,6 +110,9 @@ export class ModService { ) { const mod = this.mod(); const arr = mod[key] as unknown as T[]; + + console.log(`[ENTRY:NEW]`, data); + arr.push(data); this.updateMod(mod); } @@ -122,6 +125,8 @@ export class ModService { const mod = this.mod(); const arr = mod[key] as unknown as T[]; + console.log(`[ENTRY:EDIT]`, oldData, newData); + const foundItemIdx = arr.findIndex((i) => i._id === oldData._id); if (foundItemIdx === -1) return; @@ -137,6 +142,8 @@ export class ModService { const mod = this.mod(); const arr = mod[key] as unknown as T[]; + console.log(`[ENTRY:DELETE]`, data); + (mod[key] as unknown as T[]) = arr.filter((i) => i._id !== data._id); this.updateMod(mod);