UNPKG

@bscotch/yy

Version:

Stringify, parse, read, and write GameMaker yy and yyp files.

135 lines 4.63 kB
// Generated by ts-to-zod import { z } from 'zod'; import { bigNumber, isObjectWithField, nameField } from './utility.js'; export const yypResourceIdSchema = z.object({ name: z.string(), path: z.string(), }); const yypResourceSchema = z.object({ id: yypResourceIdSchema, order: z.number().optional(), }); const yypOptionSchema = z.object({ ConfigValues: z.record(z.record(z.string())).optional(), name: z.string(), path: z.string(), }); const yypConfigSchema = z.lazy(() => z.object({ name: z.string(), children: z.array(yypConfigSchema), })); const yypRoomOrderNodeSchema = z.object({ roomId: z.preprocess((input) => { if (isObjectWithField(input, 'name') && typeof input.name === 'string') { if (!input.path) { input.path = `rooms/${input.name}/${input.name}.yy`; } } return input; }, z.object({ name: z.string(), /** rooms/{name}/{name}.yy */ path: z.string(), })), }); export const yypFolderSchema = z.preprocess((input) => { if (isObjectWithField(input, 'name') && typeof input.name === 'string') { if (!input.folderPath) { // Default to a root folder input.folderPath = `folders/${input.name}.yy`; } } return input; }, z.object({ name: z.string(), tags: z.array(z.string()).optional(), folderPath: z.string(), order: z.number().optional(), resourceType: z.literal('GMFolder').default('GMFolder'), resourceVersion: z.string().default('1.0'), })); export const yypAudioGroupSchema = z.object({ ConfigValues: z.record(z.record(z.string())).optional(), name: z.string(), targets: bigNumber().default(-1n), resourceType: z.literal('GMAudioGroup').default('GMAudioGroup'), resourceVersion: z.string().default('1.3'), }); export const yypTextureGroupSchema = z .object({ ConfigValues: z.record(z.record(z.string())).optional(), name: z.string(), groupParent: z .object({ name: z.string(), path: z.string(), }) .nullable() .default(null), isScaled: z.boolean().default(true), customOptions: z.string().default(''), compressFormat: z.string().default('bz2'), autocrop: z.boolean().default(true), border: z.number().default(2), mipsToGenerate: z.number().default(0), targets: bigNumber().default(-1n), loadType: z.enum(['default', 'dynamicpages']).default('default'), directory: z.string().default(''), resourceType: z.literal('GMTextureGroup').default('GMTextureGroup'), resourceVersion: z.string().default('1.3'), }) .passthrough(); const yypIncludedFileSchema = z.object({ ConfigValues: z .record(z.object({ CopyToMask: z.string(), })) .optional(), /** The name of the file, including extension, without the path */ name: z.string(), CopyToMask: bigNumber().default(-1), /** `datafiles/${subdir}` */ filePath: z.string(), resourceType: z.literal('GMIncludedFile').default('GMIncludedFile'), resourceVersion: z.string().default('1.0'), }); export const yypSchema = z.preprocess((input) => { // Remove the Options field if it's an empty array // (Since the GameMaker IDE will, and thus create Git noise) if (input && typeof input === 'object' && 'Options' in input && Array.isArray(input.Options) && input.Options.length === 0) { delete input.Options; } return input; }, z .object({ [nameField]: z.string().optional(), name: z.string(), resourceType: z.literal('GMProject').default('GMProject'), resources: z.array(yypResourceSchema).default([]), RoomOrderNodes: z.array(yypRoomOrderNodeSchema).default([]), Options: z.array(yypOptionSchema).optional(), isDnDProject: z.boolean().optional(), defaultScriptType: z.number().default(1), isEcma: z.boolean().default(false), tutorialPath: z.string().optional(), configs: z.object({ name: z.literal('Default').default('Default'), children: z.array(yypConfigSchema).default([]), }), Folders: z.array(yypFolderSchema).default([]), AudioGroups: z.array(yypAudioGroupSchema).default([]), TextureGroups: z.array(yypTextureGroupSchema).default([]), IncludedFiles: z.array(yypIncludedFileSchema).default([]), MetaData: z.object({ IDEVersion: z.string(), }), LibraryEmitters: z.array(z.any()).optional(), resourceVersion: z.string(), tags: z.array(z.string()).optional(), }) .passthrough()); //# sourceMappingURL=Yyp.js.map