UNPKG

@bscotch/sprite-source

Version:

Art pipeline scripting module for GameMaker sprites.

51 lines 1.87 kB
import { z } from 'zod'; import { jsonSchemaRemoteDir } from './constants.js'; export const cacheVersion = 2; const imageSummarySchema = z.object({ width: z.number(), height: z.number(), checksum: z.string().describe('Pixel-based checksum of the image.'), changed: z.number().describe('Unix timestamp of last modification date.'), }); const spriteSummarySchema = z.looseObject({ spine: z.literal(false), checksum: z .string() .describe('A checksum combining the pixel-based checksums of all of the frame checksums.'), frames: z.record(z.string(), imageSummarySchema), }); const spineSummarySchema = z.looseObject({ spine: z.literal(true), checksum: z .string() .describe('A checksum combining the pixel-based checksum of the atlas file with the contets of the atlas and json files.'), changed: z .number() .describe('Unix timestamp of the most recent modified date for all associate files (atlas, json, png).'), }); const schemaFilename = 'stitch.sprite-cache.schema.json'; const remoteFilename = `${jsonSchemaRemoteDir}/${schemaFilename}`; export const spritesInfoSchema = z.looseObject({ $schema: z.string().default(remoteFilename).optional(), version: z.number().default(1), info: z .record(z.string(), z.discriminatedUnion('spine', [spriteSummarySchema, spineSummarySchema])) .default({}), }); export const spritesInfoInfo = { schema: spritesInfoSchema, name: 'Sprite Cache', filename: schemaFilename, }; export function lastChanged(info) { return info.spine ? info.changed : Math.max(...Object.values(info.frames).map((f) => f.changed), 0); } /** * Returns `true` if `a` is newer than `b`. */ export function isNewer(a, b) { return lastChanged(a) > lastChanged(b); } //# sourceMappingURL=SpriteCache.schemas.js.map