@@ -116,7 +116,7 @@ const createCell = (x, index, grid, eventListener) => {
116
116
} ;
117
117
118
118
// update cell. toggle its content
119
- const createField_updateCell = ( i , parentGrid , fromPreview ) => {
119
+ const createField_updateCell = ( i , parentGrid , fromPreview , cellClass = "cell" ) => {
120
120
let userInfoClass = localStorage . getItem ( "userInfoClass" ) ;
121
121
let userInfoColor = localStorage . getItem ( "userInfoColor" ) ;
122
122
let UserIcon = localStorage . getItem ( "UserIcon" ) ;
@@ -126,15 +126,15 @@ const createField_updateCell = (i, parentGrid, fromPreview) => {
126
126
// check if cell is empty or not
127
127
if ( cell . classList . contains ( "draw" ) ) { // cell is full. empty it
128
128
// reset cell
129
- cell . className = `cell ${ fromPreview } ` ;
129
+ cell . className = `${ cellClass } ${ fromPreview } ` ;
130
130
cell . textContent = null ;
131
131
cell . style . color = "white" ;
132
132
133
133
} else { // cell is empty. draw on it
134
134
135
135
// user uses advaned skin
136
136
if ( userInfoClass != "empty" ) {
137
- cell . className = `cell ${ fromPreview } ${ userInfoClass } ` ;
137
+ cell . className = `${ cellClass } ${ fromPreview } ${ userInfoClass } ` ;
138
138
139
139
} else { // user uses normal color skin
140
140
@@ -248,16 +248,23 @@ const Display_CostumPatterns = () => {
248
248
// delete previous content
249
249
costum_patterns_overview . textContent = null ;
250
250
251
- if ( Object . keys ( patterns ) . length <= 0 ) costum_patterns_overview . textContent = "No costum patterns are created yet." ;
251
+ if ( patterns ) {
252
+ if ( Object . keys ( patterns ) . length <= 0 ) costum_patterns_overview . textContent = "No costum patterns are created yet." ;
252
253
253
- // creates pattern html element from an object
254
- Object . keys ( patterns ) . forEach ( pattName => {
255
- let pattStructure = patterns [ pattName ] ;
254
+ // creates pattern html element from an object
255
+ Object . keys ( patterns ) . forEach ( pattName => {
256
+ let pattStructure = patterns [ pattName ] ;
256
257
257
- createPattern_preview ( pattName , pattStructure , costum_patterns_overview , "personal" ) ;
258
- } ) ;
258
+ createPattern_preview ( pattName , pattStructure , costum_patterns_overview , "personal" ) ;
259
+ } ) ;
259
260
260
- NewCreativeLevel . InitCostumPatterns ( NewCreativeLevel . CurrentSelectedSetting . costumPatterns ) ;
261
+ NewCreativeLevel . InitCostumPatterns ( NewCreativeLevel . CurrentSelectedSetting . costumPatterns ) ;
262
+
263
+ } else {
264
+ costum_patterns_overview . textContent = "No costum patterns are created yet." ;
265
+
266
+ NewCreativeLevel . InitCostumPatterns ( { } ) ;
267
+ } ;
261
268
} ;
262
269
263
270
// displays all fields stored in localstorage in "own fields" tab container
@@ -267,18 +274,25 @@ const Display_CostumFields = () => {
267
274
// delete previous content
268
275
costum_field_overview . textContent = null ;
269
276
270
- if ( Object . keys ( fields ) . length <= 0 ) costum_field_overview . textContent = "No costum fields are created yet." ;
277
+ if ( fields ) {
278
+ if ( Object . keys ( fields ) . length <= 0 ) costum_field_overview . textContent = "No costum fields are created yet." ;
271
279
272
- // creates pattern html element from an object
273
- Object . keys ( fields ) . forEach ( key => {
274
- let name = fields [ key ] [ "name" ] ;
275
- let x = fields [ key ] [ "x" ] ;
276
- let y = fields [ key ] [ "y" ] ;
280
+ // creates pattern html element from an object
281
+ Object . keys ( fields ) . forEach ( key => {
282
+ let name = fields [ key ] [ "name" ] ;
283
+ let x = fields [ key ] [ "x" ] ;
284
+ let y = fields [ key ] [ "y" ] ;
277
285
278
- createPattern_preview ( name , [ ] , costum_field_overview , "personal" , undefined , x , "scroll" , undefined , y , "field" ) ;
279
- } ) ;
286
+ createPattern_preview ( name , [ ] , costum_field_overview , "personal" , undefined , x , "scroll" , undefined , y , "field" ) ;
287
+ } ) ;
280
288
281
- NewCreativeLevel . InitCostumField ( NewCreativeLevel . CurrentSelectedSetting . costumField ) ;
289
+ NewCreativeLevel . InitCostumField ( NewCreativeLevel . CurrentSelectedSetting . costumField ) ;
290
+
291
+ } else {
292
+ costum_field_overview . textContent = "No costum fields are created yet." ;
293
+
294
+ NewCreativeLevel . InitCostumField ( { } ) ;
295
+ } ;
282
296
} ;
283
297
284
298
// create pattern preview element
@@ -308,7 +322,7 @@ const createPattern_preview = (patternName, patternStructure, parent, rights, sp
308
322
createPattern_checkPatternInLevel ( checkBox , patternName , patternStructure , gridType ) ;
309
323
310
324
// create basic 5x5 grid
311
- createPattern_createGrid ( patternStructure , gridRows , y , grid ) ;
325
+ createPattern_createGrid ( patternStructure , gridRows , y , grid , rights ) ;
312
326
313
327
// event listener
314
328
createPattern_eventListener ( pen , bin , checkBox , bin2 , patternStructure , patternName , gridType , Number ( gridRows ) , Number ( y ) ) ;
@@ -338,7 +352,14 @@ const createPattern_preview = (patternName, patternStructure, parent, rights, sp
338
352
gridWrapper . setAttribute ( "right" , "personal" ) ;
339
353
340
354
} else if ( rights == "level" ) {
355
+
341
356
gridWrapper . setAttribute ( "right" , "level" ) ;
357
+
358
+ } else if ( rights == "remove" ) {
359
+
360
+ editItemsWrapper . appendChild ( bin2 ) ;
361
+
362
+ gridWrapper . setAttribute ( "right" , "remove" ) ;
342
363
} ;
343
364
344
365
setTimeout ( ( ) => {
@@ -370,6 +391,7 @@ const createPattern_addAttributes = (gridWrapper, patternName, grid, title, head
370
391
checkBox . style . fontSize = "larger" ;
371
392
grid . style . gridTemplateColumns = `repeat(${ gridRows } , 1fr)` ;
372
393
title . textContent = patternName ;
394
+ title . style . fontSize = "medium" ;
373
395
} ;
374
396
375
397
// check if this pattern exists in the current creative level
@@ -395,11 +417,13 @@ const createPattern_checkPatternInLevel = (checkBox, patternName, patternStructu
395
417
} ;
396
418
397
419
// create grid and grid pattern if exists to the grid
398
- const createPattern_createGrid = ( patternStructure , gridRows , y , grid ) => {
420
+ const createPattern_createGrid = ( patternStructure , gridRows , y , grid , rights ) => {
421
+ let cellClass = rights == "level" ? "miniCellMini" : "cell" ;
422
+
399
423
new Array ( gridRows * y ) . fill ( "" ) . forEach ( i => {
400
424
let cell = document . createElement ( "div" ) ;
401
425
cell . classList . add ( "preview_cell" ) ;
402
- cell . classList . add ( "cell" ) ;
426
+ cell . classList . add ( cellClass ) ;
403
427
404
428
grid . appendChild ( cell ) ;
405
429
} ) ;
@@ -409,7 +433,7 @@ const createPattern_createGrid = (patternStructure, gridRows, y, grid) => {
409
433
let index = parseInt ( i ) ;
410
434
411
435
// console.log(index, i, grid, grid.children[index]);
412
- createField_updateCell ( index , grid , "preview_cell" ) ;
436
+ createField_updateCell ( index , grid , "preview_cell" , cellClass ) ;
413
437
} ) ;
414
438
} ;
415
439
@@ -482,7 +506,7 @@ const createPattern_scrollgrid = (gridWrapper, grid, Yscroll, Xscroll) => {
482
506
} ;
483
507
484
508
if ( Xscroll === undefined ) {
485
- gridWrapper . style . overflowX = "unset " ;
509
+ gridWrapper . style . overflowX = "hidden " ;
486
510
} ;
487
511
} ;
488
512
0 commit comments