@@ -314,9 +314,91 @@ export async function listSpineTextureAtlasEmbeddedResources(
314314 } ;
315315}
316316
317+ /**
318+ * List the embedded resources of a PixiJS Spritesheet JSON resource.
319+ * A spritesheet JSON file contains a `meta.image` field that references the
320+ * texture atlas image file.
321+ *
322+ * @param project The project
323+ * @param filePath The file path of a spritesheet JSON resource
324+ * @returns The embedded resources (the texture image), or null if parsing fails
325+ */
326+ export async function listSpritesheetEmbeddedResources (
327+ project : gdProject ,
328+ filePath : string
329+ ) : Promise < ?EmbeddedResources > {
330+ if ( ! fs || ! path ) return null ;
331+
332+ let spritesheetContent : ?string = null ;
333+ try {
334+ spritesheetContent = await fs . promises . readFile ( filePath , 'utf8' ) ;
335+ } catch ( error ) {
336+ console . error (
337+ `Unable to read spritesheet JSON file at path ${ filePath } :` ,
338+ error
339+ ) ;
340+ return null ;
341+ }
342+
343+ if ( ! spritesheetContent ) return null ;
344+
345+ try {
346+ const spritesheetData = JSON . parse ( spritesheetContent ) ;
347+
348+ // Check if this looks like a valid PixiJS spritesheet JSON
349+ // (must have "frames" and "meta" fields)
350+ if (
351+ ! spritesheetData ||
352+ typeof spritesheetData !== 'object' ||
353+ ! spritesheetData . frames ||
354+ ! spritesheetData . meta
355+ ) {
356+ console . warn (
357+ `File ${ filePath } does not appear to be a valid PixiJS spritesheet JSON (missing "frames" or "meta" fields).`
358+ ) ;
359+ return null ;
360+ }
361+
362+ // Get the image path from meta.image
363+ const imageRelPath = spritesheetData . meta . image ;
364+ if ( ! imageRelPath || typeof imageRelPath !== 'string' ) {
365+ console . warn (
366+ `Spritesheet JSON file ${ filePath } is missing the "meta.image" field or it is not a string.`
367+ ) ;
368+ return null ;
369+ }
370+
371+ const dir = path . dirname ( filePath ) ;
372+ const embeddedResources = new Map < string , EmbeddedResource > ( ) ;
373+
374+ const fullPath = path . resolve ( dir , imageRelPath ) ;
375+ const isOutsideProjectFolder = ! isPathInProjectFolder ( project , fullPath ) ;
376+ const resource : EmbeddedResource = {
377+ resourceKind : 'image ',
378+ relPath : imageRelPath ,
379+ fullPath ,
380+ isOutsideProjectFolder ,
381+ } ;
382+
383+ embeddedResources . set ( imageRelPath , resource ) ;
384+
385+ return {
386+ embeddedResources ,
387+ hasAnyEmbeddedResourceOutsideProjectFolder : isOutsideProjectFolder ,
388+ } ;
389+ } catch ( error ) {
390+ console . error (
391+ `Unable to parse spritesheet JSON file ${ filePath } :` ,
392+ error
393+ ) ;
394+ return null ;
395+ }
396+ }
397+
317398export const embeddedResourcesParsers : { [ string ] : ParseEmbeddedFiles } = {
318399 tilemap : listTileMapEmbeddedResources ,
319400 json : listTileMapEmbeddedResources ,
320401 spine : listSpineEmbeddedResources ,
321402 atlas : listSpineTextureAtlasEmbeddedResources ,
403+ spritesheet : listSpritesheetEmbeddedResources ,
322404} ;
0 commit comments