Skip to content

Commit

Permalink
Add event validator
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Oct 29, 2024
1 parent c6e1dff commit d09e844
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/app/helpers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const defaultEvent: () => IDynamicEventMeta = () => ({
rarity: DynamicEventRarity.Common,
startMessage: '',
conflicts: [],
extraData: {},
map: undefined as unknown as string,
npc: undefined as unknown as string,

Expand Down
20 changes: 20 additions & 0 deletions src/app/helpers/schemas/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { isBoolean, isNumber, isObject, isString } from 'lodash';
import { Schema } from '../../../interfaces';
import { isArrayOf } from './_helpers';

export const eventSchema: Schema = [
['name', true, isString],
['duration', true, isNumber],
['cooldown', true, isNumber],
['rarity', true, isString],
['conflicts', false, isArrayOf(isString)],
['description', true, isString],
['startMessage', false, isString],
['endMessage', false, isString],
['map', false, isString],
['npc', false, isString],
['requiresPreviousEvent', false, isBoolean],
['spawnEventOnFailure', false, isString],
['spawnEventOnSuccess', false, isString],
['successMetrics', true, isObject],
];
1 change: 1 addition & 0 deletions src/app/helpers/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './achievement';
export * from './dialog';
export * from './dialog-behaviors';
export * from './droptable';
export * from './event';
export * from './item';
export * from './npc';
export * from './quest';
Expand Down
2 changes: 2 additions & 0 deletions src/app/helpers/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
validateDialogs,
validateDialogsItems,
validateDroptables,
validateEvents,
validateItems,
validateNPCs,
validateQuests,
Expand Down Expand Up @@ -60,6 +61,7 @@ export function validationMessagesForMod(
...checkMapSpawners(mod),
...checkMapItems(mod),
...checkMapObjects(mod),
validateEvents(mod),
validateDialogs(mod),
validateDialogActions(mod),
validateDialogsItems(mod, classes),
Expand Down
30 changes: 30 additions & 0 deletions src/app/helpers/validators/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
IDynamicEventMeta,
IModKit,
ValidationMessage,
ValidationMessageGroup,
} from '../../../interfaces';
import { eventSchema } from '../schemas';
import { validateSchema } from '../schemas/_helpers';

export function validateEvents(mod: IModKit): ValidationMessageGroup {
const itemValidations: ValidationMessageGroup = {
header: 'Invalid Events',
messages: [],
};

mod.events.forEach((item) => {
const failures = validateSchema<IDynamicEventMeta>(
item.name,
item,
eventSchema
);
const validationFailures: ValidationMessage[] = failures.map((f) => ({
type: 'error',
message: f,
}));
itemValidations.messages.push(...validationFailures);
});

return itemValidations;
}
1 change: 1 addition & 0 deletions src/app/helpers/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './achievement';
export * from './autogenerated';
export * from './dialog';
export * from './droptable';
export * from './event';
export * from './item';
export * from './map';
export * from './npc';
Expand Down
2 changes: 2 additions & 0 deletions src/app/services/mod.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export class ModService {

mod[checkKey] = structuredClone(check[checkKey]) as unknown as any;
});

mod.events.forEach((m) => delete (m as any).extraData);
}

public resetMod(): void {
Expand Down

0 comments on commit d09e844

Please sign in to comment.