Skip to content

Commit

Permalink
add validation for map helditems and peddle items
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 30, 2024
1 parent 50525f9 commit ad0b750
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/helpers/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
checkItemStats,
checkItemUses,
checkMapBGMs,
checkMapItems,
checkMapNPCDialogs,
checkMapProperties,
checkMapSpawners,
Expand Down Expand Up @@ -48,6 +49,7 @@ export function validationMessagesForMod(
...checkMapBGMs(mod, json),
...checkMapProperties(mod),
...checkMapSpawners(mod),
...checkMapItems(mod),
validateDialogs(mod),
validateDialogsItems(mod, classes),
validateItems(mod),
Expand Down
42 changes: 42 additions & 0 deletions src/app/helpers/validators/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,48 @@ export function checkMapBGMs(
return groups;
}

export function checkMapItems(mod: IModKit): ValidationMessageGroup[] {
const validItemNames = mod.items.map((i) => i.name);
const groups: ValidationMessageGroup[] = [];

mod.maps.forEach((map) => {
const mapValidations: ValidationMessageGroup = {
header: `Map Items (${map.name})`,
messages: [],
};

map.map.layers?.[8].objects.forEach((obj: any) => {
if (!obj.properties?.requireHeld) return;

if (!validItemNames.includes(obj.properties.requireHeld as string)) {
mapValidations.messages.push({
type: 'error',
message: `${obj.properties.requireHeld} is not a valid item (Held|${
obj.x / 64
},${obj.y / 64 - 1}).`,
});
}
});

map.map.layers?.[9].objects.forEach((obj: any) => {
if (!obj.properties?.peddleItem) return;

if (!validItemNames.includes(obj.properties.peddleItem as string)) {
mapValidations.messages.push({
type: 'error',
message: `${obj.properties.peddleItem} is not a valid item (Peddler|${
obj.x / 64
},${obj.y / 64 - 1}).`,
});
}
});

groups.push(mapValidations);
});

return groups;
}

export function checkMapSpawners(mod: IModKit): ValidationMessageGroup[] {
const groups: ValidationMessageGroup[] = [];

Expand Down

0 comments on commit ad0b750

Please sign in to comment.