Skip to content

Commit

Permalink
cleanup for validations, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 15, 2024
1 parent 05ed207 commit 6dfcb41
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/app/helpers/export/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export function formatItems(items: IItemDefinition[]): IItemDefinition[] {
if (item.containedItems && !item.containedItems.length)
delete item.containedItems;
if (item.trait && !item.trait.name) delete item.trait;
if (!item.notUsableAfterHours) delete item.notUsableAfterHours;
if (item.randomTrait && item.randomTrait.name.length === 0)
delete item.randomTrait;
if (item.useEffect && !item.useEffect.name) delete item.useEffect;
Expand Down
4 changes: 2 additions & 2 deletions src/app/helpers/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
checkMapNPCDialogs,
checkMapProperties,
checkMapSpawners,
checkNPCSprites,
checkNPCs,
checkNPCUsages,
checkQuests,
checkRecipes,
Expand All @@ -28,7 +28,7 @@ export function validationMessagesForMod(
checkItemUses(mod),
checkMapNPCDialogs(mod),
checkNPCUsages(mod),
checkNPCSprites(mod),
checkNPCs(mod),
checkRecipes(mod),
checkSpawners(mod),
checkQuests(mod),
Expand Down
39 changes: 39 additions & 0 deletions src/app/helpers/validators/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ import {
import { dialogSchema } from '../schemas';
import { validateSchema } from '../schemas/_helpers';

export function checkMapNPCDialogs(mod: IModKit): ValidationMessageGroup {
// check npc dialog refs, make sure they exist
const mapDialogValidations: ValidationMessageGroup = {
header: `Unused NPC Scripts`,
messages: [],
};

const foundDialogs: Record<string, number> = {};

const addDialogCount = (item: string) => {
foundDialogs[item] ??= 0;
foundDialogs[item]++;
};

mod.maps.forEach((map) => {
map.map.layers[9].objects.forEach((npc: any) => {
addDialogCount(npc.properties.tag as string);
});
});

mod.dialogs.forEach((dia) => {
if (foundDialogs[dia.tag]) return;

mapDialogValidations.messages.push({
type: 'warning',
message: `${dia.tag} is unused.`,
});
});

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

return mapDialogValidations;
}

export function validateDialogs(mod: IModKit): ValidationMessageGroup {
const itemValidations: ValidationMessageGroup = {
header: 'Invalid NPC Scripts',
Expand Down
48 changes: 8 additions & 40 deletions src/app/helpers/validators/npc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,6 @@ import { formatNPCs } from '../export';
import { npcSchema } from '../schemas';
import { validateSchema } from '../schemas/_helpers';

export function checkMapNPCDialogs(mod: IModKit): ValidationMessageGroup {
// check npc dialog refs, make sure they exist
const mapDialogValidations: ValidationMessageGroup = {
header: `Unused NPC Scripts`,
messages: [],
};

const foundDialogs: Record<string, number> = {};

const addDialogCount = (item: string) => {
foundDialogs[item] ??= 0;
foundDialogs[item]++;
};

mod.maps.forEach((map) => {
map.map.layers[9].objects.forEach((npc: any) => {
addDialogCount(npc.properties.tag as string);
});
});

mod.dialogs.forEach((dia) => {
if (foundDialogs[dia.tag]) return;

mapDialogValidations.messages.push({
type: 'warning',
message: `${dia.tag} is unused.`,
});
});

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

return mapDialogValidations;
}

export function checkNPCUsages(mod: IModKit) {
const npcValidations: ValidationMessageGroup = {
header: `Unused NPCs`,
Expand Down Expand Up @@ -105,7 +66,7 @@ export function checkNPCUsages(mod: IModKit) {
return npcValidations;
}

export function checkNPCSprites(mod: IModKit) {
export function checkNPCs(mod: IModKit) {
const npcValidations: ValidationMessageGroup = {
header: `NPCs`,
messages: [],
Expand All @@ -120,6 +81,13 @@ export function checkNPCSprites(mod: IModKit) {
message: `NPC ${item.npcId} has an invalid sprite: ${sprite} - it should be modulo 5.`,
});
});

if (item.forceAI) {
npcValidations.messages.push({
type: 'warning',
message: `NPC ${item.npcId} sets forceAI to ${item.forceAI}.`,
});
}
});

if (npcValidations.messages.length === 0) {
Expand Down

0 comments on commit 6dfcb41

Please sign in to comment.