@@ -2953,6 +2953,36 @@ class TileMapEditorApp {
29532953
29542954let tileMapStudioApp = null ;
29552955
2956+ function isStrictWorkspaceTilemapSnapshot ( snapshot ) {
2957+ if ( ! snapshot || typeof snapshot !== "object" ) {
2958+ return false ;
2959+ }
2960+ const documentModel = snapshot . documentModel ;
2961+ const assetRegistry = snapshot . assetRegistry ;
2962+ if ( ! documentModel || typeof documentModel !== "object" ) {
2963+ return false ;
2964+ }
2965+ if ( documentModel . schema !== "toolbox.tilemap/1" ) {
2966+ return false ;
2967+ }
2968+ if ( ! documentModel . map || typeof documentModel . map !== "object" ) {
2969+ return false ;
2970+ }
2971+ if ( ! Array . isArray ( documentModel . layers ) ) {
2972+ return false ;
2973+ }
2974+ if ( ! Array . isArray ( documentModel . tileset ) ) {
2975+ return false ;
2976+ }
2977+ if ( ! documentModel . tilesetAtlas || typeof documentModel . tilesetAtlas !== "object" ) {
2978+ return false ;
2979+ }
2980+ if ( ! assetRegistry || typeof assetRegistry !== "object" ) {
2981+ return false ;
2982+ }
2983+ return true ;
2984+ }
2985+
29562986function bootTileMapStudio ( ) {
29572987 if ( tileMapStudioApp ) {
29582988 window . tileMapStudioApp = tileMapStudioApp ;
@@ -2965,13 +2995,15 @@ function bootTileMapStudio() {
29652995 app . applyProjectSystemState = function applyProjectSystemState ( snapshot ) {
29662996 if ( Date . now ( ) <= Number ( this . skipExternalProjectStateUntil || 0 ) ) {
29672997 this . skipExternalProjectStateUntil = 0 ;
2968- return ;
2998+ return true ;
2999+ }
3000+ if ( ! isStrictWorkspaceTilemapSnapshot ( snapshot ) ) {
3001+ this . updateStatus ( "Project state rejected: workspace snapshot is missing required tilemap source data." ) ;
3002+ return false ;
29693003 }
29703004 const nextDocument = sanitizeDocument ( snapshot ?. documentModel ) ;
29713005 this . documentModel = nextDocument ;
2972- this . assetRegistry = snapshot ?. assetRegistry && typeof snapshot . assetRegistry === "object"
2973- ? sanitizeAssetRegistry ( snapshot . assetRegistry )
2974- : createAssetRegistry ( { projectId : nextDocument ?. map ?. name || "tilemap-project" } ) ;
3006+ this . assetRegistry = sanitizeAssetRegistry ( snapshot . assetRegistry ) ;
29753007 this . selectedLayerId = typeof snapshot ?. selectedLayerId === "string" && nextDocument . layers . some ( ( layer ) => layer . id === snapshot . selectedLayerId )
29763008 ? snapshot . selectedLayerId
29773009 : nextDocument . layers [ 0 ] ?. id || "" ;
@@ -2983,6 +3015,7 @@ function bootTileMapStudio() {
29833015 this . syncInputsFromDocument ( ) ;
29843016 this . renderAll ( ) ;
29853017 this . updateStatus ( `Project state loaded for ${ this . documentModel . map . name } .` ) ;
3018+ return true ;
29863019 } ;
29873020 tileMapStudioApp = app ;
29883021 window . tileMapStudioApp = tileMapStudioApp ;
0 commit comments