UNPKG

@bscotch/yy

Version:

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

129 lines 4.96 kB
// Generated by ts-to-zod import { z } from 'zod'; import { configValuesSchema, yyBaseSchema, yyParentSchema } from './YyBase.js'; import { fixed0, fixed1, fixedNumber, unstable } from './utility.js'; export var SoundBitDepth; (function (SoundBitDepth) { SoundBitDepth[SoundBitDepth["Bit8"] = 0] = "Bit8"; SoundBitDepth[SoundBitDepth["Bit16"] = 1] = "Bit16"; })(SoundBitDepth || (SoundBitDepth = {})); export var SoundChannel; (function (SoundChannel) { SoundChannel[SoundChannel["Mono"] = 0] = "Mono"; SoundChannel[SoundChannel["Stereo"] = 1] = "Stereo"; SoundChannel[SoundChannel["ThreeD"] = 2] = "ThreeD"; })(SoundChannel || (SoundChannel = {})); export var SoundCompression; (function (SoundCompression) { SoundCompression[SoundCompression["Uncompressed"] = 0] = "Uncompressed"; SoundCompression[SoundCompression["Compressed"] = 1] = "Compressed"; SoundCompression[SoundCompression["UncompressedOnLoad"] = 2] = "UncompressedOnLoad"; SoundCompression[SoundCompression["CompressedStreamed"] = 3] = "CompressedStreamed"; })(SoundCompression || (SoundCompression = {})); const soundChannelSchema = z.enum(SoundChannel); const soundCompressionSchema = z.enum(SoundCompression); const soundBitDepthSchema = z.enum(SoundBitDepth); const soundSampleRateSchema = z.union([ z.literal(5512), z.literal(11025), z.literal(22050), z.literal(32000), z.literal(44100), z.literal(48000), ]); const audioGroupIdSchema = z .object({ name: z.string(), path: z.string(), }) .default({ name: 'audiogroup_default', path: 'audiogroups/audiogroup_default', }); export const yySoundSchemaLegacy = yyBaseSchema.extend({ compression: soundCompressionSchema.default(0), conversionMode: z.number().optional().default(0), volume: fixedNumber(z.number().min(0).max(1)).default(fixed1), preload: z.boolean().default(false), bitRate: z.number().default(128), sampleRate: soundSampleRateSchema.default(44100), type: soundChannelSchema.default(1), bitDepth: soundBitDepthSchema.default(1), audioGroupId: audioGroupIdSchema, /** `${name}.${ext} (e.g. mySound) */ soundFile: z.string(), /** * Duration of the sound. Automatically * computed by GameMaker, so Stitch can generally * ignore it. */ duration: fixedNumber(z.number(), 2).optional(), resourceType: z.literal('GMSound').default('GMSound'), resourceVersion: z.literal('1.0').default('1.0'), }); export const yySoundSchemaV1 = unstable({ $GMSound: z.literal(''), '%Name': z.string(), audioGroupId: audioGroupIdSchema, bitDepth: soundBitDepthSchema.default(1), bitRate: z.number().default(128), compression: soundCompressionSchema.default(0), conversionMode: z.number().optional().default(0), /** * Duration of the sound. Automatically * computed by GameMaker, so Stitch can generally * ignore it. */ duration: fixedNumber(z.number(), 2).default(fixed0), name: z.string(), parent: yyParentSchema, preload: z.boolean().default(false), resourceType: z.literal('GMSound').default('GMSound'), resourceVersion: z.literal('2.0').default('2.0'), sampleRate: soundSampleRateSchema.default(44100), soundFile: z.string(), type: soundChannelSchema.default(1), volume: fixedNumber(z.number().min(0).max(1)).default(fixed1), }); export const yySoundSchemaV2 = z.looseObject({ $GMSound: z.literal('v2'), '%Name': z.string(), audioGroupId: audioGroupIdSchema, bitDepth: soundBitDepthSchema.default(1), channelFormat: soundChannelSchema .default(1) .describe("Previously called 'type'"), compression: soundCompressionSchema.default(0), compressionQuality: z.number().default(4), ConfigValues: configValuesSchema, conversionMode: z.number().optional().default(0), duration: fixedNumber(z.number(), 2).default(fixed0), exportDir: z.string().default(''), name: z.string(), parent: yyParentSchema, preload: z.boolean().default(false), resourceType: z.literal('GMSound').default('GMSound'), resourceVersion: z.literal('2.0').default('2.0'), sampleRate: soundSampleRateSchema.default(44100), soundFile: z.string(), volume: fixedNumber(z.number().min(0).max(1)).default(fixed1), }); export const yySoundSchema = z.preprocess((arg) => { if (!arg || typeof arg !== 'object') return arg; if ('resourceVersion' in arg && arg.resourceVersion === '2.0') { // @ts-expect-error type is unknown here arg['$GMSound'] ||= ''; } if ('$GMSound' in arg) { let v2 = arg; v2['resourceVersion'] = '2.0'; v2.name ||= v2['%Name']; v2['%Name'] ||= v2.name; } return arg; }, z.discriminatedUnion('resourceVersion', [ yySoundSchemaLegacy, z.discriminatedUnion('$GMSound', [yySoundSchemaV1, yySoundSchemaV2]), ])); //# sourceMappingURL=YySound.js.map