@@ -148,6 +148,18 @@ const FileManager = (() => {
148
148
]
149
149
} ) ) ;
150
150
}
151
+ function defaultLPE ( w , h , colors ) {
152
+ return {
153
+ "canvasWidth" :w ,
154
+ "canvasHeight" :h ,
155
+ "editorMode" :"Advanced" ,
156
+ colors,
157
+ "selectedLayer" :0 ,
158
+ "layers" :[
159
+ { "canvas" :{ } , "context" :{ "mozImageSmoothingEnabled" :false } , "isSelected" :true , "isVisible" :true , "isLocked" :false , "oldLayerName" :null , "menuEntry" :{ } , "id" :"layer0" , "name" :"Layer 0" , "src" :emptyCanvasSrc ( w , h ) }
160
+ ]
161
+ } ;
162
+ }
151
163
function localStorageLoad ( ) {
152
164
////console.log("loading from localStorage");
153
165
////console.log('JSON.parse(localStorage.getItem("lpe-cache") ?? "{}") === ',JSON.parse(localStorage.getItem("lpe-cache") ?? "{}"));
@@ -185,7 +197,10 @@ const FileManager = (() => {
185
197
186
198
img . onload = function ( ) {
187
199
//create a new pixel with the images dimentions
188
- Startup . newPixel ( this . width , this . height ) ;
200
+ Startup . newPixel ( {
201
+ canvasWidth : this . width ,
202
+ canvasHeight : this . height
203
+ } ) ;
189
204
EditorState . switchMode ( 'Advanced' ) ;
190
205
191
206
//draw the image onto the canvas
@@ -218,7 +233,7 @@ const FileManager = (() => {
218
233
}
219
234
220
235
function _parseLPE ( dictionary ) {
221
- Startup . newPixel ( dictionary [ 'canvasWidth' ] , dictionary [ 'canvasHeight' ] , dictionary , true ) ;
236
+ Startup . newPixel ( dictionary , true ) ;
222
237
}
223
238
}
224
239
function loadFromLPE ( dictionary ) {
@@ -361,20 +376,42 @@ const FileManager = (() => {
361
376
}
362
377
return dictionary ;
363
378
}
379
+ function emptyCanvasSrc ( w , h ) {
380
+ const canvas = document . createElement ( 'canvas' ) ;
381
+ canvas . width = w ;
382
+ canvas . height = h ;
383
+ const ctx = canvas . getContext ( '2d' ) ;
384
+ return canvas . toDataURL ( ) ;
385
+ }
386
+ function toggleCache ( elm ) {
387
+ console . log ( 'elm === ' , elm ) ;
388
+ FileManager . cacheEnabled = ! FileManager . cacheEnabled ;
389
+ localStorage . setItem ( "lpe-cache-enabled" , FileManager . cacheEnabled ? "1" : "0" ) ;
390
+ elm . textContent = cacheBtnText ( FileManager . cacheEnabled ) ;
391
+ }
392
+ function cacheBtnText ( cacheEnabled ) {
393
+ return `${ cacheEnabled ? "Disable" : "Enable" } auto-cache` ;
394
+ }
395
+
396
+ const cacheEnabled = ! ! Number ( localStorage . getItem ( "lpe-cache-enabled" ) ) ;
397
+ document . getElementById ( "auto-cache-button" ) . textContent = cacheBtnText ( cacheEnabled ) ;
364
398
365
399
return {
400
+ cacheEnabled,
366
401
loadFromLPE,
402
+ toggleCache,
367
403
getProjectData,
368
404
localStorageReset,
369
405
localStorageCheck,
370
406
localStorageSave,
371
407
localStorageLoad,
372
408
upgradeLPE,
409
+ defaultLPE,
373
410
saveProject,
374
411
openProject,
375
412
exportProject,
376
413
openPixelExportWindow,
377
414
openSaveProjectWindow,
378
415
open
379
- }
416
+ } ;
380
417
} ) ( ) ;
0 commit comments