Best JavaScript code snippet using playwright-internal
mapEngine.js
Source:mapEngine.js
...205 206 for (var x = 0; x < 15; x++){207 var rngX = randomInt(0, Math.round((mapWidth/75)-1));208 var rngY = randomInt(0, Math.round((mapHeight/75)-1));209 block.createBlock(rngX,rngY, 1, 1, "normal"); //Bottom Left210 }211 //Spawn areas212 spawnXminBlack = mapWidth/2 - 500;213 spawnXmaxBlack = mapWidth/2 + 500;214 spawnYminBlack = mapHeight/2 - 500;215 spawnYmaxBlack = mapHeight/2 + 500;216 spawnXminWhite = mapWidth/2 - 500;217 spawnXmaxWhite = mapWidth/2 + 500;218 spawnYminWhite = mapHeight/2 - 500;219 spawnYmaxWhite = mapHeight/2 + 500; 220 var hordeHoleWidth = 4;221 var hordeHoleXDistFromEdge = 10;222 block.createBlock(-1/2, mapHeight/75, (mapWidth/75) - hordeHoleXDistFromEdge + 1/2, 1/2, "normal"); //Bottom Left223 block.createBlock(-1/2, -1/2, 1/2, (mapHeight/75) - hordeHoleXDistFromEdge + 1/2, "normal"); //Left Top224 block.createBlock(mapWidth/75, -1/2, 1/2, hordeHoleXDistFromEdge-2 + 1/2, "normal"); //Right Top225 block.createBlock(-1/2, -1/2, hordeHoleXDistFromEdge-2 + 1/2, 1/2, "normal"); //Top Left226 block.createBlock((mapWidth/75) - hordeHoleXDistFromEdge + hordeHoleWidth, mapHeight/75, hordeHoleXDistFromEdge - hordeHoleWidth, 1/2, "normal"); //Bottom Right227 block.createBlock(-1/2, (mapHeight/75) - hordeHoleXDistFromEdge + hordeHoleWidth, 1/2, hordeHoleXDistFromEdge - hordeHoleWidth, "normal"); //Left Bottom228 block.createBlock(mapWidth/75, hordeHoleXDistFromEdge-2 + hordeHoleWidth, 1/2, (mapHeight/75) - (hordeHoleXDistFromEdge-2 + hordeHoleWidth) + 1/2, "normal"); //Right Bottom229 block.createBlock(hordeHoleXDistFromEdge-2 + hordeHoleWidth, -1/2, (mapWidth/75) - (hordeHoleXDistFromEdge-2 + hordeHoleWidth) + 1/2, 1/2, "normal"); //Top Right230 } 231 else if (map == "loadTest"){232 for (var i = 0; i <= 60; i+=10){233 block.createBlock(450 + i, 200, 400, 75, "normal");234 block.createBlock(200 + i, 450, 75, 400, "normal");235 block.createBlock(mapWidth + i - 400 - 450, mapHeight - 75 - 200, 400, 75, "normal");236 block.createBlock(mapWidth + i - 75 - 200, mapHeight - 400 - 450, 75, 400, "normal");237 block.createBlock(mapWidth/2 + i - 250, mapHeight/2 - 37, 500, 75, "normal");238 block.createBlock(-20 + i, 235, 70, 50, "normal");239 block.createBlock(mapWidth + i - 50, mapHeight - 285, 70, 50, "normal"); 240 block.createBlock(-50 + i, mapHeight, mapWidth + 100, 50, "normal"); //Bottom241 block.createBlock(-50 + i, -50, 50, mapHeight + 100, "normal"); //Left242 block.createBlock(mapWidth + i, -50, 50, mapHeight + 100, "normal"); //Right243 block.createBlock(-50 + i, -50, mapWidth + 100, 50, "normal"); //Top244 }245 }246 else if (map == "longest"){247 mapWidth = 39*75;248 mapHeight = 22*75;249 250 //Spawn areas251 spawnXminBlack = mapWidth - 700;252 spawnXmaxBlack = mapWidth - 10;253 spawnYminBlack = 10;254 spawnYmaxBlack = mapHeight;255 256 spawnXminWhite = 10;257 spawnXmaxWhite = 700;258 spawnYminWhite = 0;259 spawnYmaxWhite = mapHeight - 10;260 261 //push blocks262 block.createBlock(9.7, 5, 5.6, 1, "pushDown");263 block.createBlock(26.7, 5, 3.6, 1, "pushDown");264 block.createBlock(8.7, 16, 3.6, 1, "pushUp");265 block.createBlock(23.7, 16, 5.6, 1, "pushUp"); 266 block.createBlock(3, 0, 7, 3, "normal");267 block.createBlock(-0.5, -0.5, 10.5, 2.5, "normal"); 268 block.createBlock(3, 5, 7, 1, "normal");269 block.createBlock(15, 0, 7, 6, "normal");270 block.createBlock(15, -0.5, 16, 2.5, "normal");271 block.createBlock(24, 5, 3, 1, "normal");272 block.createBlock(30, -0.5, 1, 6.5, "normal");273 block.createBlock(34, 2, 1, 2.9, "blue");274 block.createBlock(34, 4, 3, 1, "blue");275 block.createBlock(3, 10, 9, 2, "red");276 block.createBlock(17, 10.1, 5, 1.8, "normal"); //mid passthrough blocker277 block.createBlock(14, 11, 8, 1, "red"); //mid bars278 block.createBlock(17, 10, 8, 1, "blue"); //mid bars279 block.createBlock(27, 10, 9, 2, "blue");280 block.createBlock(4, 17.1, 1, 2.9, "red");281 block.createBlock(2, 17, 3, 1, "red");282 block.createBlock(8, 16, 1, 6.5, "normal");283 block.createBlock(12, 16, 3, 1, "normal");284 block.createBlock(17, 16, 7, 6, "normal");285 block.createBlock(8, 20, 16, 2.5, "normal");286 block.createBlock(29, 16, 7, 1, "normal");287 block.createBlock(29, 19, 7, 3, "normal");288 block.createBlock(29, 20, 10.5, 2.5, "normal"); 289 block.createBlock(-1/2, mapHeight/75, (mapWidth + 75)/75, 1/2, "normal"); //Bottom290 block.createBlock(-1/2, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Left291 block.createBlock(mapWidth/75, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Right292 block.createBlock(-1/2, -1/2, (mapWidth + 75)/75, 1/2, "normal"); //Top293 294 /*295 block.createBlock(-100/75, (mapHeight - 10)/75, (mapWidth + 400)/75, 200/75); //Bottom296 block.createBlock((-200 + 10)/75, -200/75, 200/75, (mapHeight + 400)/75); //Left297 block.createBlock((mapWidth - 10)/75, -200/75, 200/75, (mapHeight + 400)/75); //Right298 block.createBlock(-200/75, (-200 + 10)/75, (mapWidth + 400)/75, 200/75); //Top 299 */300 }301 else if (map == "thepit"){302 mapWidth = 41*75;303 mapHeight = 30*75;304 305 //Spawn areas306 spawnXminBlack = mapWidth - 700;307 spawnXmaxBlack = mapWidth - 10;308 spawnYminBlack = 8*75;309 spawnYmaxBlack = 29*75;310 spawnXminWhite = 10;311 spawnXmaxWhite = 700;312 spawnYminWhite = 8*75;313 spawnYmaxWhite = 29*75;314 315 block.createBlock(4, 3, 2, 2, "normal"); 316 block.createBlock(4, 7, 2, 2, "normal"); 317 block.createBlock(-0.5, 7, 2.5, 2, "normal"); 318 block.createBlock(6, 15, 1, 7, "red"); 319 block.createBlock(3, 15, 4, 1, "red"); 320 block.createBlock(2, 21, 5, 1, "red"); 321 block.createBlock(2, 24, 1, 4, "red"); 322 block.createBlock(2, 27, 4, 1, "red"); 323 block.createBlock(13, 18, 1, 4, "red"); 324 block.createBlock(10, 27, 4, 1, "normal"); 325 block.createBlock(10, 3, 4.9, 1, "normal"); 326 block.createBlock(10, 5, 4.9, 1, "normal"); 327 block.createBlock(14, -0.5, 1, 4.5, "normal"); 328 block.createBlock(14.1, 8, 4.9, 1, "normal"); 329 block.createBlock(14, 5, 1, 4, "normal"); 330 block.createBlock(22, 8, 4.9, 1, "normal"); 331 block.createBlock(26.1, 3, 4.9, 1, "normal"); 332 block.createBlock(26, -0.5, 1, 4.5, "normal"); 333 block.createBlock(26.1, 5, 4.9, 1, "normal"); 334 block.createBlock(26, 5, 1, 4, "normal"); 335 block.createBlock(35, 3, 2, 2, "normal"); 336 block.createBlock(35, 7, 2, 2, "normal"); 337 block.createBlock(39, 7, 2.5, 2, "normal"); 338 block.createBlock(27, 18, 1, 4, "blue"); 339 block.createBlock(34, 15, 1, 7, "blue"); 340 block.createBlock(34, 15, 4, 1, "blue"); 341 block.createBlock(34, 21, 5, 1, "blue"); 342 block.createBlock(38, 24, 1, 4, "blue"); 343 block.createBlock(35, 27, 4, 1, "blue"); 344 block.createBlock(27, 27, 4, 1, "normal"); 345 block.createBlock(17, 28, 7, 2.5, "normal"); 346 block.createBlock(17, 21, 2, 2, "normal"); 347 block.createBlock(22, 21, 2, 2, "normal"); 348 block.createBlock(17, 22, 7, 5, "normal"); 349 block.createBlock(20, 12, 1, 6, "normal"); 350 block.createBlock(17, 17, 7, 2, "normal"); 351 block.createBlock(-1/2, mapHeight/75, (mapWidth + 75)/75, 1/2, "normal"); //Bottom352 block.createBlock(-1/2, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Left353 block.createBlock(mapWidth/75, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Right354 block.createBlock(-1/2, -1/2, (mapWidth + 75)/75, 1/2, "normal"); //Top355 }356 else if (map == "crik"){357 mapWidth = 52*75;358 mapHeight = 26*75;359 360 //Spawn areas361 spawnXminWhite = 10;362 spawnXmaxWhite = mapWidth/2;363 spawnYminWhite = 10;364 spawnYmaxWhite = mapHeight - 10;365 spawnXminBlack = mapWidth/2;366 spawnXmaxBlack = mapWidth - 10;367 spawnYminBlack = 10;368 spawnYmaxBlack = mapHeight - 10;369 370 371 //block.createBlocks372 block.createBlock(17, 6.9, 1, 2.2, "pushRight"); 373 block.createBlock(34, 6.9, 1, 2.2, "pushLeft"); 374 block.createBlock(40, 14, 2, 5.8, "normal"); 375 block.createBlock(10, 6, 2, 6, "normal"); 376 block.createBlock(4, 11, 2, 1, "red"); 377 block.createBlock(4, 14, 2, 1, "red"); 378 block.createBlock(46, 11, 2, 1, "blue"); 379 block.createBlock(46, 14, 2, 1, "blue"); 380 block.createBlock(19, -0.5, 2, 2.5, "normal"); 381 block.createBlock(22, 1, 2, 1, "normal"); 382 block.createBlock(24, 1, 5.1, 1, "pushDown");383 block.createBlock(29, -0.5, 23.4, 2.5, "normal"); 384 block.createBlock(17, 4, 1, 3, "red"); 385 block.createBlock(44, 3, 2, 2, "normal"); 386 block.createBlock(5,6, 8, 1, "red"); 387 block.createBlock(15, 6, 3, 1, "red"); 388 block.createBlock(34, 6, 13, 1, "blue"); 389 block.createBlock(24, 8, 1, 10, "pushLeft"); 390 block.createBlock(27, 8, 1, 10, "pushRight"); //middle bridge391 block.createBlock(17, 16.9, 1, 2.2, "pushRight"); 392 block.createBlock(34, 16.9, 1, 2.2, "pushLeft"); 393 block.createBlock(46, 6, 1, 14, "blue"); 394 block.createBlock(14, 9, 1, 8, "normal"); 395 block.createBlock(17, 9, 1, 3, "red"); 396 block.createBlock(20, 8, 2, 3, "normal"); 397 block.createBlock(34, 9, 1, 3, "blue"); 398 block.createBlock(37, 9, 1, 8, "normal"); 399 block.createBlock(40, 9, 2, 3, "normal"); 400 block.createBlock(5, 6, 1, 14, "red"); 401 block.createBlock(10, 14, 2, 3, "normal"); 402 block.createBlock(17, 14, 1, 3, "red"); 403 block.createBlock(30, 15, 2, 3, "normal"); 404 block.createBlock(34, 14, 1, 3, "blue"); 405 block.createBlock(5, 19, 13, 1, "red"); 406 block.createBlock(6, 21, 2, 2, "normal"); 407 block.createBlock(34, 19, 3, 1, "blue"); 408 block.createBlock(39, 19, 8, 1, "blue"); 409 block.createBlock(34, 19, 1, 3, "blue"); 410 block.createBlock(-0.4, 24, 23.4, 2.4, "normal"); 411 block.createBlock(23, 24, 5.1, 1, "pushUp"); 412 block.createBlock(28, 24, 2, 1, "normal"); 413 block.createBlock(31, 24, 2, 2.5, "normal"); 414 415 block.createBlock(4, 12, 1, 2, "warp", 48.1 * 75, 13 * 75); 416 block.createBlock(47, 12, 1, 2, "warp", 3.9 * 75, 13 * 75); 417 block.createBlock(-1/2, mapHeight/75, (mapWidth + 75)/75, 1/2, "normal"); //Bottom418 block.createBlock(-1/2, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Left419 block.createBlock(mapWidth/75, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Right420 block.createBlock(-1/2, -1/2, (mapWidth + 75)/75, 1/2, "normal"); //Top421 } 422 else if (map == "narrows"){423 mapWidth = 43*75;424 mapHeight = 63*75;425 426 //Spawn areas427 spawnXminWhite = 3*75;428 spawnXmaxWhite = 42*75;429 spawnYminWhite = 10;430 spawnYmaxWhite = 16*75;431 spawnXminBlack = 1*75;432 spawnXmaxBlack = 40*75;433 spawnYminBlack = 44*75;434 spawnYmaxBlack = 62*75;435 //pushblocks436 block.createBlock(13.9, 15, 1.1, 6, "pushDown");437 block.createBlock(28, 15, 1.1, 6, "pushDown");438 block.createBlock(13.9, 42, 1.1, 6, "pushUp");439 block.createBlock(28, 42, 1.1, 6, "pushUp");440 441 //red north442 block.createBlock(2.1, 7, 3, 3, "normal"); //plug443 block.createBlock(2, 0, 18, 1, "normal"); 444 block.createBlock(2, 0, 15, 4, "normal"); 445 block.createBlock(23, 0, 10, 1, "normal"); 446 block.createBlock(25, 0, 18, 4, "normal"); 447 block.createBlock(34, 0, 9, 7, "normal"); 448 block.createBlock(42, 0, 1, 20, "normal"); 449 block.createBlock(0, 0, 3, 14, "normal");450 block.createBlock(12, 5.1, 2, 3.9, "red"); 451 block.createBlock(12, 5, 6, 2, "red"); 452 block.createBlock(30, 5.1, 2, 3.9, "red"); 453 block.createBlock(26, 5, 6, 2, "red"); 454 //red warps455 block.createBlock(20, 0, 3, 1, "warp", 21.5*75, 26*75); 456 block.createBlock(12, 16, 1, 3, "warp", 31.1*75, 17.5*75); 457 block.createBlock(30, 16, 1, 3, "warp", 11.1*75, 17.5*75); 458 //right device459 block.createBlock(36.9, 15, 2.2, 29, "pushDown");460 block.createBlock(29, 15, 5, 1, "normal"); 461 block.createBlock(29, 15, 1, 33, "normal"); 462 block.createBlock(36, 13, 1, 31, "normal"); 463 block.createBlock(39, 13, 1, 43, "normal");464 block.createBlock(39, 19, 4, 3, "normal");465 block.createBlock(29, 19, 8, 25, "normal");466 block.createBlock(29, 43, 8, 1, "normal");467 block.createBlock(29, 47, 5, 1, "normal");468 block.createBlock(37, 46, 3, 10, "normal");469 //left device470 block.createBlock(3.9, 19, 2.2, 29, "pushUp");471 block.createBlock(3, 7, 3, 10, "normal"); 472 block.createBlock(9, 15, 5, 1, "normal"); 473 block.createBlock(6, 19, 8, 25, "normal"); 474 block.createBlock(13, 15, 1, 33, "normal");475 block.createBlock(0, 41, 4, 3, "normal");476 block.createBlock(6, 43, 8, 1, "normal");477 block.createBlock(9, 47, 5, 1, "normal");478 block.createBlock(3, 7, 1, 43, "normal");479 block.createBlock(6, 19, 1, 31, "normal");480 //center map481 block.createBlock(19, 22, 5, 1, "normal"); 482 block.createBlock(20, 26, 1, 5, "red"); 483 block.createBlock(22, 26, 1, 5, "red"); 484 block.createBlock(20, 30, 3, 1, "red"); 485 block.createBlock(20, 32, 3, 1, "blue"); 486 block.createBlock(20, 32, 1, 5, "blue"); 487 block.createBlock(22, 32, 1, 5, "blue"); 488 block.createBlock(19, 40, 5, 1, "normal"); 489 //Blue south490 block.createBlock(38, 53, 2.9, 3, "normal"); //plug491 block.createBlock(0, 43, 1, 20, "normal"); 492 block.createBlock(0, 56, 9, 7, "normal"); 493 block.createBlock(0, 59, 18, 4, "normal"); 494 block.createBlock(0, 62, 20, 1, "normal"); 495 block.createBlock(23, 62, 18, 1, "normal"); 496 block.createBlock(40, 49, 3, 14, "normal"); 497 block.createBlock(25, 59, 16, 4, "normal"); 498 block.createBlock(11, 54, 2, 3.9, "blue"); 499 block.createBlock(11, 56, 6, 2, "blue"); 500 block.createBlock(29, 54, 2, 3.9, "blue"); 501 block.createBlock(25, 56, 6, 2, "blue"); 502 //blue warps503 block.createBlock(30, 44, 1, 3, "warp", 11.1*75, 45.5*75); 504 block.createBlock(12, 44, 1, 3, "warp", 31.1*75, 45.5*75); 505 block.createBlock(20, 62, 3, 1, "warp", 21.5*75, 37*75);506 // block.createBlock(-1/2, mapHeight/75, (mapWidth + 75)/75, 1/2, "normal"); //Bottom507 // block.createBlock(-1/2, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Left508 // block.createBlock(mapWidth/75, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Right509 // block.createBlock(-1/2, -1/2, (mapWidth + 75)/75, 1/2, "normal"); //Top510 } 511 else if (map == "longNarrows"){512 mapWidth = 53*75;513 mapHeight = 87*75;514 515 //Spawn areas516 spawnXminWhite = 1*75;517 spawnXmaxWhite = 50*75;518 spawnYminWhite = 1*75;519 spawnYmaxWhite = 20*75;520 spawnXminBlack = 3*75;521 spawnXmaxBlack = 46*75;522 spawnYminBlack = 67*75;523 spawnYmaxBlack = mapHeight - 75;524 //pushblocks525 block.createBlock(18.9, 20, 1.1, 6, "pushDown");526 block.createBlock(33, 20, 1.1, 6, "pushDown");527 block.createBlock(18.9, 61, 1.1, 6, "pushUp");528 block.createBlock(33, 61, 1.1, 6, "pushUp");529 530 //red north531 block.createBlock(0, 0, 23, 1, "normal"); 532 block.createBlock(0, 0, 1, 14, "normal"); 533 block.createBlock(0, 0, 19, 4, "normal"); 534 block.createBlock(26, 0, 25, 1, "normal"); 535 block.createBlock(31, 0, 20, 4, "normal"); 536 block.createBlock(41, 0, 10, 8, "normal"); 537 block.createBlock(50, 0, 3, 27, "normal");538 block.createBlock(0, 13, 7, 48, "normal");539 block.createBlock(12, 5.1, 3, 4.9, "red"); 540 block.createBlock(12, 5, 8, 3, "red"); 541 block.createBlock(17, 13, 4, 2, "red"); 542 block.createBlock(37, 5.1, 3, 4.9, "red"); 543 block.createBlock(33, 5, 7, 3, "red"); 544 block.createBlock(31, 13, 4, 2, "red"); 545 //red warps546 block.createBlock(23, 0, 3, 1, "warp", 26.5*75, 37*75); 547 block.createBlock(17, 23, 1, 3, "warp", 36.1*75, 24.5*75); 548 block.createBlock(35, 23, 1, 3, "warp", 16.9*75, 24.5*75); 549 //right device550 block.createBlock(43.9, 16, 2.2, 22, "pushDown");551 block.createBlock(43.9, 38, 2.2, 23, "pushDown");552 block.createBlock(46, 22, 5, 5, "normal");553 block.createBlock(37, 18, 3, 4.9, "normal"); 554 block.createBlock(34, 20, 6, 3, "normal"); 555 block.createBlock(43, 14, 1, 47, "normal"); 556 block.createBlock(46, 14, 1, 60, "normal");557 block.createBlock(34, 26, 10, 35, "normal");558 block.createBlock(34, 64, 7, 3, "normal");559 block.createBlock(38, 64, 3, 5, "normal");560 block.createBlock(44, 63, 3, 11, "normal");561 //left device562 block.createBlock(6.9, 26, 2.2, 22, "pushUp");563 block.createBlock(6.9, 48, 2.2, 23, "pushUp");564 block.createBlock(2, 60, 5, 5, "normal");565 block.createBlock(6, 13, 3, 11, "normal"); 566 block.createBlock(12, 18, 3, 4.9, "normal"); 567 block.createBlock(12, 20, 7, 3, "normal"); 568 block.createBlock(9, 26, 10, 35, "normal");569 block.createBlock(6, 13, 1, 60, "normal");570 block.createBlock(9, 26, 1, 47, "normal");571 block.createBlock(13.1, 64, 5.8, 3, "normal");572 block.createBlock(13, 64, 3, 5, "normal");573 //center map574 block.createBlock(18, 20, 1, 47, "normal"); //rails575 block.createBlock(34, 20, 1, 47, "normal"); 576 block.createBlock(24, 28, 5, 1, "normal"); 577 block.createBlock(25, 38, 1, 5, "red"); 578 block.createBlock(27, 38, 1, 5, "red"); 579 block.createBlock(25, 42, 3, 1, "red"); 580 block.createBlock(25, 44, 1, 5, "blue"); 581 block.createBlock(27, 44, 1, 5, "blue"); 582 block.createBlock(25, 44, 3, 1, "blue"); 583 block.createBlock(24, 58, 5, 1, "normal"); 584 //Blue south585 block.createBlock(0, 60, 3, 27, "normal"); 586 block.createBlock(2, 79, 10, 8, "normal"); 587 block.createBlock(2, 83, 20, 4, "normal"); 588 block.createBlock(2, 86, 25, 1, "normal"); 589 block.createBlock(30, 86, 23, 1, "normal"); 590 block.createBlock(34, 83, 19, 4, "normal"); 591 block.createBlock(52, 73, 1, 14, "normal"); 592 block.createBlock(46, 26, 7, 48, "normal"); 593 block.createBlock(38, 77, 3, 4.9, "blue"); 594 block.createBlock(34, 79, 7, 3, "blue"); 595 block.createBlock(13, 77, 3, 4.9, "blue"); 596 block.createBlock(13, 79, 7, 3, "blue"); 597 block.createBlock(18, 72, 4, 2, "blue"); 598 block.createBlock(32, 72, 4, 2, "blue"); 599 //blue warps600 block.createBlock(17, 61, 1, 3, "warp", 36.1*75, 62.5*75); 601 block.createBlock(35, 61, 1, 3, "warp", 16.9*75, 62.5*75); 602 block.createBlock(27, 86, 3, 1, "warp", 26.5*75, 49.5*75);603 // block.createBlock(-1/2, mapHeight/75, (mapWidth + 75)/75, 1/2, "normal"); //Bottom604 // block.createBlock(-1/2, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Left605 // block.createBlock(mapWidth/75, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Right606 // block.createBlock(-1/2, -1/2, (mapWidth + 75)/75, 1/2, "normal"); //Top607 } 608 else if (map == "whirlpool"){609 mapWidth = 58*75;610 mapHeight = 36*75;611 612 //Spawn areas613 spawnXminBlack = 40 * 75;614 spawnXmaxBlack = 54 * 75;615 spawnYminBlack = 3 * 75;616 spawnYmaxBlack = 33 * 75;617 618 spawnXminWhite = 4 * 75;619 spawnXmaxWhite = 18 * 75;620 spawnYminWhite = 3 * 75;621 spawnYmaxWhite = 33 * 75;622 623 //push blocks624 block.createBlock(0.9, -0.1, 9.1, 2.2, "pushRight");625 block.createBlock(10, -0.1, 9, 2.2, "pushRight");626 block.createBlock(19, -0.1, 9, 2.2, "pushRight");627 block.createBlock(28, -0.1, 9, 2.2, "pushRight");628 block.createBlock(37, -0.1, 9, 2.2, "pushRight");629 block.createBlock(46, -0.1, 9, 2.2, "pushRight");630 block.createBlock(54.9, 0, 2.2, 5, "pushDown");631 block.createBlock(54.9, 5, 2.2, 6, "pushDown");632 block.createBlock(54.9, 11, 2.2, 6, "pushDown");633 block.createBlock(54.9, 19, 2.2, 7, "pushDown");634 block.createBlock(54.9, 26, 2.2, 8, "pushDown");635 block.createBlock(3, 33.9, 9, 2.2, "pushLeft");636 block.createBlock(12, 33.9, 9, 2.2, "pushLeft");637 block.createBlock(21, 33.9, 9, 2.2, "pushLeft");638 block.createBlock(30, 33.9, 9, 2.2, "pushLeft");639 block.createBlock(39, 33.9, 9, 2.2, "pushLeft");640 block.createBlock(48, 33.9, 9.1, 2.2, "pushLeft");641 block.createBlock(0.9, 2, 2.2, 5, "pushUp");642 block.createBlock(0.9, 7, 2.2, 5, "pushUp");643 block.createBlock(0.9, 12, 2.2, 5, "pushUp");644 block.createBlock(0.9, 19, 2.2, 5, "pushUp");645 block.createBlock(0.9, 24, 2.2, 6, "pushUp");646 block.createBlock(0.9, 30, 2.2, 6, "pushUp");647 block.createBlock(3, 16.9, 1, 2.2, "pushLeft");648 block.createBlock(54, 16.9, 1, 2.2, "pushRight");649 //Outside walls650 block.createBlock(0, 0, 1, mapHeight/75, "normal"); //left wall651 block.createBlock(3, 2, 1, 15, "normal"); 652 block.createBlock(3, 19, 1, 15, "normal"); 653 block.createBlock(3, 2, 25, 1, "normal");//Top wall 654 block.createBlock(30.1, 2, 24.9, 1, "normal"); 655 block.createBlock(30, 1, 1, 2, "normal"); 656 block.createBlock(54, 2, 1, 15, "normal"); //right wall 657 block.createBlock(54, 19, 1, 15, "normal"); 658 block.createBlock(57, -0.5, 1, mapHeight/75 + 1, "normal"); 659 block.createBlock(3, 33, 24.9, 1, "normal");//bottom wall660 block.createBlock(30, 33, 25, 1, "normal"); 661 block.createBlock(27, 33, 1, 2, "normal"); 662 663 block.createBlock(0, -0.6, (mapWidth)/75, 1/2, "normal"); //Top664 block.createBlock(0, mapHeight/75 - 0.1, (mapWidth)/75, 1/2, "normal"); //Bottom665 //Red Left666 block.createBlock(12, 4, 4, 1, "red"); 667 block.createBlock(12, 4, 1, 4, "red"); 668 block.createBlock(22, 5, 4, 1, "red"); 669 block.createBlock(25, 5, 1, 4, "red"); 670 block.createBlock(18, 10, 4, 1, "red"); 671 block.createBlock(18, 7, 1, 4, "red"); 672 block.createBlock(8, 12, 4, 1, "red"); 673 block.createBlock(8, 9, 1, 4, "red"); 674 block.createBlock(7, 15, 5, 1, "red"); //base 675 block.createBlock(11, 15, 1, 6, "red"); 676 block.createBlock(7, 20, 5, 1, "red"); 677 block.createBlock(16, 15, 4, 1, "red"); 678 block.createBlock(23, 16, 4, 1, "red"); 679 block.createBlock(26, 13, 1, 4, "red"); 680 block.createBlock(15, 19, 3.9, 1, "red"); 681 block.createBlock(18, 19, 1, 4, "red"); 682 block.createBlock(9, 26, 4, 1, "red"); 683 block.createBlock(12, 23, 1, 4, "red"); 684 block.createBlock(21, 25, 4, 1, "red"); 685 block.createBlock(24, 22, 1, 4, "red"); 686 block.createBlock(15, 30, 4, 1, "red"); 687 block.createBlock(15, 27, 1, 4, "red"); 688 //Blue Right689 block.createBlock(39, 5, 3.9, 1, "blue"); 690 block.createBlock(42, 5, 1, 4, "blue"); 691 block.createBlock(45, 9, 4, 1, "blue"); 692 block.createBlock(45, 9, 1, 4, "blue"); 693 block.createBlock(33.1, 10, 3.9, 1, "blue"); 694 block.createBlock(33, 10, 1, 4, "blue"); 695 block.createBlock(39, 16, 4, 1, "blue"); 696 block.createBlock(39, 13, 1, 4, "blue"); 697 block.createBlock(46, 15, 5, 1, "blue"); //base 698 block.createBlock(46, 15, 1, 6, "blue"); 699 block.createBlock(46, 20, 5, 1, "blue"); 700 block.createBlock(38, 20, 4, 1, "blue"); 701 block.createBlock(31, 19, 4, 1, "blue"); 702 block.createBlock(31, 19, 1, 4, "blue"); 703 block.createBlock(46, 23, 3.9, 1, "blue"); 704 block.createBlock(49, 23, 1, 4, "blue"); 705 block.createBlock(36, 25, 4, 1, "blue"); 706 block.createBlock(39, 25, 1, 4, "blue"); 707 block.createBlock(32, 30, 4, 1, "blue"); 708 block.createBlock(32, 27, 1, 4, "blue"); 709 block.createBlock(42, 31, 4, 1, "blue"); 710 block.createBlock(45, 28, 1, 4, "blue"); 711 }712 else if (map == "close"){713 mapWidth = 8*75;714 mapHeight = 8*75;715 716 //Spawn areas717 spawnXminBlack = mapWidth - 400;718 spawnXmaxBlack = mapWidth - 10;719 spawnYminBlack = mapHeight - 400;720 spawnYmaxBlack = mapHeight - 10;721 spawnXminWhite = 10;722 spawnXmaxWhite = 400;723 spawnYminWhite = 10;724 spawnYmaxWhite = 400;725 726 block.createBlock(3, 6, 2, 2, "normal"); 727 block.createBlock(3, 6, 2, 2, "normal"); 728 block.createBlock(3, 6, 2, 2, "normal"); 729 block.createBlock(3, 6, 2, 2, "normal"); 730 block.createBlock(3, 6, 2, 2, "normal"); 731 block.createBlock(-1/2, mapHeight/75, (mapWidth + 75)/75, 1/2, "normal"); //Bottom732 block.createBlock(-1/2, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Left733 block.createBlock(mapWidth/75, -1/2, 1/2, (mapHeight + 75)/75, "normal"); //Right734 block.createBlock(-1/2, -1/2, (mapWidth + 75)/75, 1/2, "normal"); //Top735 }736 else{ //default 737 mapWidth = 2100;738 mapHeight = 1500;739 740 //Spawn areas741 spawnXminBlack = mapWidth - 700;742 spawnXmaxBlack = mapWidth - 10;743 spawnYminBlack = mapHeight - 700;744 spawnYmaxBlack = mapHeight - 10;745 spawnXminWhite = 10;746 spawnXmaxWhite = 700;747 spawnYminWhite = 10;748 spawnYmaxWhite = 700;749 block.createBlock(550/75, 200/75, 600/75, 75/75, "normal");750 block.createBlock(-50/75, 275/75, 350/75, 900/75, "normal");751 block.createBlock((mapWidth - 400 - 750)/75, (mapHeight - 75 - 200)/75, 600/75, 75/75, "normal");752 block.createBlock((mapWidth - 300)/75, (mapHeight - 900 - 450 + 175)/75, 350/75, 900/75, "normal");753 block.createBlock((mapWidth/2 - 37)/75, (mapHeight/2 - 250)/75, 75/75, 500/75, "normal"); //Middle beam754 block.createBlock(-20/75, 235/75, 70/75, 50/75, "normal"); //BM nub white755 block.createBlock((mapWidth - 50)/75, (mapHeight - 285)/75, 70/75, 50/75, "normal"); //BM nub black756 block.createBlock(-50/75, mapHeight/75, (mapWidth + 100)/75, 50/75, "normal"); //Bottom757 block.createBlock(-50/75, -50/75, 50/75, (mapHeight + 100)/75, "normal"); //Left758 block.createBlock(mapWidth/75, -50/75, 50/75, (mapHeight + 100)/75, "normal"); //Right759 block.createBlock(-50/75, -50/75, (mapWidth + 100)/75, 50/75, "normal"); //Top760 }761 762}763module.exports.initializePickups = initializePickups;...
engine_blocks.js
Source:engine_blocks.js
...24});25// Getter tests26test('getBlock', t => {27 const b = new Blocks();28 b.createBlock({29 id: 'foo',30 opcode: 'TEST_BLOCK',31 next: null,32 fields: {},33 inputs: {},34 topLevel: true35 });36 const block = b.getBlock('foo');37 t.type(block, 'object');38 const notBlock = b.getBlock('?');39 t.type(notBlock, 'undefined');40 t.end();41});42test('getScripts', t => {43 const b = new Blocks();44 let scripts = b.getScripts();45 t.type(scripts, 'object');46 t.equals(scripts.length, 0);47 // Create two top-level blocks and one not.48 b.createBlock({49 id: 'foo',50 opcode: 'TEST_BLOCK',51 next: null,52 fields: {},53 inputs: {},54 topLevel: true55 });56 b.createBlock({57 id: 'foo2',58 opcode: 'TEST_BLOCK',59 next: null,60 fields: {},61 inputs: {},62 topLevel: true63 });64 b.createBlock({65 id: 'foo3',66 opcode: 'TEST_BLOCK',67 next: null,68 fields: {},69 inputs: {},70 topLevel: false71 });72 scripts = b.getScripts();73 t.type(scripts, 'object');74 t.equals(scripts.length, 2);75 t.ok(scripts.indexOf('foo') > -1);76 t.ok(scripts.indexOf('foo2') > -1);77 t.equals(scripts.indexOf('foo3'), -1);78 t.end();79});80test('getNextBlock', t => {81 const b = new Blocks();82 b.createBlock({83 id: 'foo',84 opcode: 'TEST_BLOCK',85 next: null,86 fields: {},87 inputs: {},88 topLevel: true89 });90 let next = b.getNextBlock('foo');91 t.equals(next, null);92 // Add a block with "foo" as its next.93 b.createBlock({94 id: 'foo2',95 opcode: 'TEST_BLOCK',96 next: 'foo',97 fields: {},98 inputs: {},99 topLevel: true100 });101 next = b.getNextBlock('foo2');102 t.equals(next, 'foo');103 // Block that doesn't exist.104 const noBlock = b.getNextBlock('?');105 t.equals(noBlock, null);106 t.end();107});108test('getBranch', t => {109 const b = new Blocks();110 // Single branch111 b.createBlock({112 id: 'foo',113 opcode: 'TEST_BLOCK',114 next: null,115 fields: {},116 inputs: {117 SUBSTACK: {118 name: 'SUBSTACK',119 block: 'foo2',120 shadow: null121 }122 },123 topLevel: true124 });125 b.createBlock({126 id: 'foo2',127 opcode: 'TEST_BLOCK',128 next: null,129 fields: {},130 inputs: {},131 topLevel: false132 });133 const branch = b.getBranch('foo');134 t.equals(branch, 'foo2');135 const notBranch = b.getBranch('?');136 t.equals(notBranch, null);137 t.end();138});139test('getBranch2', t => {140 const b = new Blocks();141 // Second branch142 b.createBlock({143 id: 'foo',144 opcode: 'TEST_BLOCK',145 next: null,146 fields: {},147 inputs: {148 SUBSTACK: {149 name: 'SUBSTACK',150 block: 'foo2',151 shadow: null152 },153 SUBSTACK2: {154 name: 'SUBSTACK2',155 block: 'foo3',156 shadow: null157 }158 },159 topLevel: true160 });161 b.createBlock({162 id: 'foo2',163 opcode: 'TEST_BLOCK',164 next: null,165 fields: {},166 inputs: {},167 topLevel: false168 });169 b.createBlock({170 id: 'foo3',171 opcode: 'TEST_BLOCK',172 next: null,173 fields: {},174 inputs: {},175 topLevel: false176 });177 const branch1 = b.getBranch('foo', 1);178 const branch2 = b.getBranch('foo', 2);179 t.equals(branch1, 'foo2');180 t.equals(branch2, 'foo3');181 t.end();182});183test('getBranch with none', t => {184 const b = new Blocks();185 b.createBlock({186 id: 'foo',187 opcode: 'TEST_BLOCK',188 next: null,189 fields: {},190 inputs: {},191 topLevel: true192 });193 const noBranch = b.getBranch('foo');194 t.equals(noBranch, null);195 t.end();196});197test('getOpcode', t => {198 const b = new Blocks();199 const block = {200 id: 'foo',201 opcode: 'TEST_BLOCK',202 next: null,203 fields: {},204 inputs: {},205 topLevel: true206 };207 b.createBlock(block);208 const opcode = b.getOpcode(block);209 t.equals(opcode, 'TEST_BLOCK');210 const undefinedBlock = b.getBlock('?');211 const undefinedOpcode = b.getOpcode(undefinedBlock);212 t.equals(undefinedOpcode, null);213 t.end();214});215// Block events tests216test('create', t => {217 const b = new Blocks();218 b.createBlock({219 id: 'foo',220 opcode: 'TEST_BLOCK',221 next: null,222 fields: {},223 inputs: {},224 topLevel: true225 });226 t.type(b._blocks.foo, 'object');227 t.equal(b._blocks.foo.opcode, 'TEST_BLOCK');228 t.notEqual(b._scripts.indexOf('foo'), -1);229 t.end();230});231test('move', t => {232 const b = new Blocks();233 b.createBlock({234 id: 'foo',235 opcode: 'TEST_BLOCK',236 next: null,237 fields: {},238 inputs: {},239 topLevel: true240 });241 b.createBlock({242 id: 'bar',243 opcode: 'TEST_BLOCK',244 next: null,245 fields: {},246 inputs: {},247 topLevel: true248 });249 // Attach 'bar' to the end of 'foo'250 b.moveBlock({251 id: 'bar',252 newParent: 'foo'253 });254 t.equal(b._scripts.length, 1);255 t.equal(Object.keys(b._blocks).length, 2);256 t.equal(b._blocks.foo.next, 'bar');257 // Detach 'bar' from 'foo'258 b.moveBlock({259 id: 'bar',260 oldParent: 'foo'261 });262 t.equal(b._scripts.length, 2);263 t.equal(Object.keys(b._blocks).length, 2);264 t.equal(b._blocks.foo.next, null);265 t.end();266});267test('move into empty', t => {268 const b = new Blocks();269 b.createBlock({270 id: 'foo',271 opcode: 'TEST_BLOCK',272 next: null,273 fields: {},274 inputs: {},275 topLevel: true276 });277 b.createBlock({278 id: 'bar',279 opcode: 'TEST_BLOCK',280 next: null,281 fields: {},282 inputs: {},283 topLevel: true284 });285 b.moveBlock({286 id: 'bar',287 newInput: 'fooInput',288 newParent: 'foo'289 });290 t.equal(b._blocks.foo.inputs.fooInput.block, 'bar');291 t.end();292});293test('move no obscure shadow', t => {294 const b = new Blocks();295 b.createBlock({296 id: 'foo',297 opcode: 'TEST_BLOCK',298 next: null,299 fields: {},300 inputs: {301 fooInput: {302 name: 'fooInput',303 block: 'x',304 shadow: 'y'305 }306 },307 topLevel: true308 });309 b.createBlock({310 id: 'bar',311 opcode: 'TEST_BLOCK',312 next: null,313 fields: {},314 inputs: {},315 topLevel: true316 });317 b.moveBlock({318 id: 'bar',319 newInput: 'fooInput',320 newParent: 'foo'321 });322 t.equal(b._blocks.foo.inputs.fooInput.block, 'bar');323 t.equal(b._blocks.foo.inputs.fooInput.shadow, 'y');324 t.end();325});326test('change', t => {327 const b = new Blocks();328 b.createBlock({329 id: 'foo',330 opcode: 'TEST_BLOCK',331 next: null,332 fields: {333 someField: {334 name: 'someField',335 value: 'initial-value'336 }337 },338 inputs: {},339 topLevel: true340 });341 // Test that the field is updated342 t.equal(b._blocks.foo.fields.someField.value, 'initial-value');343 b.changeBlock({344 element: 'field',345 id: 'foo',346 name: 'someField',347 value: 'final-value'348 });349 t.equal(b._blocks.foo.fields.someField.value, 'final-value');350 // Invalid cases351 // No `element`352 b.changeBlock({353 id: 'foo',354 name: 'someField',355 value: 'invalid-value'356 });357 t.equal(b._blocks.foo.fields.someField.value, 'final-value');358 // No block ID359 b.changeBlock({360 element: 'field',361 name: 'someField',362 value: 'invalid-value'363 });364 t.equal(b._blocks.foo.fields.someField.value, 'final-value');365 // No such field366 b.changeBlock({367 element: 'field',368 id: 'foo',369 name: 'someWrongField',370 value: 'final-value'371 });372 t.equal(b._blocks.foo.fields.someField.value, 'final-value');373 t.end();374});375test('delete', t => {376 const b = new Blocks();377 b.createBlock({378 id: 'foo',379 opcode: 'TEST_BLOCK',380 next: null,381 fields: {},382 inputs: {},383 topLevel: true384 });385 b.deleteBlock('foo');386 t.type(b._blocks.foo, 'undefined');387 t.equal(b._scripts.indexOf('foo'), -1);388 t.end();389});390test('delete chain', t => {391 // Create a chain of connected blocks and delete the top one.392 // All of them should be deleted.393 const b = new Blocks();394 b.createBlock({395 id: 'foo',396 opcode: 'TEST_BLOCK',397 next: 'foo2',398 fields: {},399 inputs: {},400 topLevel: true401 });402 b.createBlock({403 id: 'foo2',404 opcode: 'TEST_BLOCK',405 next: 'foo3',406 fields: {},407 inputs: {},408 topLevel: false409 });410 b.createBlock({411 id: 'foo3',412 opcode: 'TEST_BLOCK',413 next: null,414 fields: {},415 inputs: {},416 topLevel: false417 });418 b.deleteBlock('foo');419 t.type(b._blocks.foo, 'undefined');420 t.type(b._blocks.foo2, 'undefined');421 t.type(b._blocks.foo3, 'undefined');422 t.equal(b._scripts.indexOf('foo'), -1);423 t.equal(Object.keys(b._blocks).length, 0);424 t.equal(b._scripts.length, 0);425 t.end();426});427test('delete inputs', t => {428 // Create a block with two inputs, one of which has its own input.429 // Delete the block - all of them should be deleted.430 const b = new Blocks();431 b.createBlock({432 id: 'foo',433 opcode: 'TEST_BLOCK',434 next: null,435 fields: {},436 inputs: {437 input1: {438 name: 'input1',439 block: 'foo2',440 shadow: 'foo2'441 },442 SUBSTACK: {443 name: 'SUBSTACK',444 block: 'foo3',445 shadow: null446 }447 },448 topLevel: true449 });450 b.createBlock({451 id: 'foo2',452 opcode: 'TEST_BLOCK',453 next: null,454 fields: {},455 inputs: {},456 topLevel: false457 });458 b.createBlock({459 id: 'foo5',460 opcode: 'TEST_OBSCURED_SHADOW',461 next: null,462 fields: {},463 inputs: {},464 topLevel: false465 });466 b.createBlock({467 id: 'foo3',468 opcode: 'TEST_BLOCK',469 next: null,470 fields: {},471 inputs: {472 subinput: {473 name: 'subinput',474 block: 'foo4',475 shadow: 'foo5'476 }477 },478 topLevel: false479 });480 b.createBlock({481 id: 'foo4',482 opcode: 'TEST_BLOCK',483 next: null,484 fields: {},485 inputs: {},486 topLevel: false487 });488 b.deleteBlock('foo');489 t.type(b._blocks.foo, 'undefined');490 t.type(b._blocks.foo2, 'undefined');491 t.type(b._blocks.foo3, 'undefined');492 t.type(b._blocks.foo4, 'undefined');493 t.type(b._blocks.foo5, 'undefined');494 t.equal(b._scripts.indexOf('foo'), -1);495 t.equal(Object.keys(b._blocks).length, 0);496 t.equal(b._scripts.length, 0);497 t.end();498});499test('updateAssetName function updates name in sound field', t => {500 const b = new Blocks();501 b.createBlock({502 id: 'foo',503 fields: {504 SOUND_MENU: {505 name: 'SOUND_MENU',506 value: 'name1'507 }508 }509 });510 t.equals(b.getBlock('foo').fields.SOUND_MENU.value, 'name1');511 b.updateAssetName('name1', 'name2', 'sound');512 t.equals(b.getBlock('foo').fields.SOUND_MENU.value, 'name2');513 t.end();514});515test('updateAssetName function updates name in costume field', t => {516 const b = new Blocks();517 b.createBlock({518 id: 'foo',519 fields: {520 COSTUME: {521 name: 'COSTUME',522 value: 'name1'523 }524 }525 });526 t.equals(b.getBlock('foo').fields.COSTUME.value, 'name1');527 b.updateAssetName('name1', 'name2', 'costume');528 t.equals(b.getBlock('foo').fields.COSTUME.value, 'name2');529 t.end();530});531test('updateAssetName function updates name in backdrop field', t => {532 const b = new Blocks();533 b.createBlock({534 id: 'foo',535 fields: {536 BACKDROP: {537 name: 'BACKDROP',538 value: 'name1'539 }540 }541 });542 t.equals(b.getBlock('foo').fields.BACKDROP.value, 'name1');543 b.updateAssetName('name1', 'name2', 'backdrop');544 t.equals(b.getBlock('foo').fields.BACKDROP.value, 'name2');545 t.end();546});547test('updateAssetName function updates name in all sprite fields', t => {548 const b = new Blocks();549 b.createBlock({550 id: 'id1',551 fields: {552 TOWARDS: {553 name: 'TOWARDS',554 value: 'name1'555 }556 }557 });558 b.createBlock({559 id: 'id2',560 fields: {561 TO: {562 name: 'TO',563 value: 'name1'564 }565 }566 });567 b.createBlock({568 id: 'id3',569 fields: {570 OBJECT: {571 name: 'OBJECT',572 value: 'name1'573 }574 }575 });576 b.createBlock({577 id: 'id4',578 fields: {579 VIDEOONMENU2: {580 name: 'VIDEOONMENU2',581 value: 'name1'582 }583 }584 });585 b.createBlock({586 id: 'id5',587 fields: {588 DISTANCETOMENU: {589 name: 'DISTANCETOMENU',590 value: 'name1'591 }592 }593 });594 b.createBlock({595 id: 'id6',596 fields: {597 TOUCHINGOBJECTMENU: {598 name: 'TOUCHINGOBJECTMENU',599 value: 'name1'600 }601 }602 });603 b.createBlock({604 id: 'id7',605 fields: {606 CLONE_OPTION: {607 name: 'CLONE_OPTION',608 value: 'name1'609 }610 }611 });612 t.equals(b.getBlock('id1').fields.TOWARDS.value, 'name1');613 t.equals(b.getBlock('id2').fields.TO.value, 'name1');614 t.equals(b.getBlock('id3').fields.OBJECT.value, 'name1');615 t.equals(b.getBlock('id4').fields.VIDEOONMENU2.value, 'name1');616 t.equals(b.getBlock('id5').fields.DISTANCETOMENU.value, 'name1');617 t.equals(b.getBlock('id6').fields.TOUCHINGOBJECTMENU.value, 'name1');618 t.equals(b.getBlock('id7').fields.CLONE_OPTION.value, 'name1');619 b.updateAssetName('name1', 'name2', 'sprite');620 t.equals(b.getBlock('id1').fields.TOWARDS.value, 'name2');621 t.equals(b.getBlock('id2').fields.TO.value, 'name2');622 t.equals(b.getBlock('id3').fields.OBJECT.value, 'name2');623 t.equals(b.getBlock('id4').fields.VIDEOONMENU2.value, 'name2');624 t.equals(b.getBlock('id5').fields.DISTANCETOMENU.value, 'name2');625 t.equals(b.getBlock('id6').fields.TOUCHINGOBJECTMENU.value, 'name2');626 t.equals(b.getBlock('id7').fields.CLONE_OPTION.value, 'name2');627 t.end();628});629test('updateAssetName function updates name according to asset type', t => {630 const b = new Blocks();631 b.createBlock({632 id: 'id1',633 fields: {634 SOUND_MENU: {635 name: 'SOUND_MENU',636 value: 'name1'637 }638 }639 });640 b.createBlock({641 id: 'id2',642 fields: {643 COSTUME: {644 name: 'COSTUME',645 value: 'name1'646 }647 }648 });649 t.equals(b.getBlock('id1').fields.SOUND_MENU.value, 'name1');650 t.equals(b.getBlock('id2').fields.COSTUME.value, 'name1');651 b.updateAssetName('name1', 'name2', 'sound');652 // only sound should get renamed653 t.equals(b.getBlock('id1').fields.SOUND_MENU.value, 'name2');654 t.equals(b.getBlock('id2').fields.COSTUME.value, 'name1');655 t.end();656});657test('updateAssetName only updates given name', t => {658 const b = new Blocks();659 b.createBlock({660 id: 'id1',661 fields: {662 COSTUME: {663 name: 'COSTUME',664 value: 'name1'665 }666 }667 });668 b.createBlock({669 id: 'id2',670 fields: {671 COSTUME: {672 name: 'COSTUME',673 value: 'foo'674 }675 }676 });677 t.equals(b.getBlock('id1').fields.COSTUME.value, 'name1');678 t.equals(b.getBlock('id2').fields.COSTUME.value, 'foo');679 b.updateAssetName('name1', 'name2', 'costume');680 t.equals(b.getBlock('id1').fields.COSTUME.value, 'name2');681 t.equals(b.getBlock('id2').fields.COSTUME.value, 'foo');682 t.end();683});684test('updateAssetName doesn\'t update name if name isn\'t being used', t => {685 const b = new Blocks();686 b.createBlock({687 id: 'id1',688 fields: {689 BACKDROP: {690 name: 'BACKDROP',691 value: 'foo'692 }693 }694 });695 t.equals(b.getBlock('id1').fields.BACKDROP.value, 'foo');696 b.updateAssetName('name1', 'name2', 'backdrop');697 t.equals(b.getBlock('id1').fields.BACKDROP.value, 'foo');698 t.end();699});700test('updateTargetSpecificBlocks changes sprite clicked hat to stage clicked for stage', t => {701 const b = new Blocks();702 b.createBlock({703 id: 'originallySpriteClicked',704 opcode: 'event_whenthisspriteclicked'705 });706 b.createBlock({707 id: 'originallyStageClicked',708 opcode: 'event_whenstageclicked'709 });710 // originallySpriteClicked does not update when on a non-stage target711 b.updateTargetSpecificBlocks(false /* isStage */);712 t.equals(b.getBlock('originallySpriteClicked').opcode, 'event_whenthisspriteclicked');713 // originallySpriteClicked does update when on a stage target714 b.updateTargetSpecificBlocks(true /* isStage */);715 t.equals(b.getBlock('originallySpriteClicked').opcode, 'event_whenstageclicked');716 // originallyStageClicked does not update when on a stage target717 b.updateTargetSpecificBlocks(true /* isStage */);718 t.equals(b.getBlock('originallyStageClicked').opcode, 'event_whenstageclicked');719 // originallyStageClicked does update when on a non-stage target720 b.updateTargetSpecificBlocks(false/* isStage */);721 t.equals(b.getBlock('originallyStageClicked').opcode, 'event_whenthisspriteclicked');722 t.end();723});724test('getAllVariableAndListReferences returns an empty map references when variable blocks do not exist', t => {725 const b = new Blocks();726 t.equal(Object.keys(b.getAllVariableAndListReferences()).length, 0);727 t.end();728});729test('getAllVariableAndListReferences returns references when variable blocks exist', t => {730 const b = new Blocks();731 let varListRefs = b.getAllVariableAndListReferences();732 t.equal(Object.keys(varListRefs).length, 0);733 b.createBlock(adapter(events.mockVariableBlock)[0]);734 b.createBlock(adapter(events.mockListBlock)[0]);735 varListRefs = b.getAllVariableAndListReferences();736 t.equal(Object.keys(varListRefs).length, 2);737 t.equal(Array.isArray(varListRefs['mock var id']), true);738 t.equal(varListRefs['mock var id'].length, 1);739 t.equal(varListRefs['mock var id'][0].type, Variable.SCALAR_TYPE);740 t.equal(varListRefs['mock var id'][0].referencingField.value, 'a mock variable');741 t.equal(Array.isArray(varListRefs['mock list id']), true);742 t.equal(varListRefs['mock list id'].length, 1);743 t.equal(varListRefs['mock list id'][0].type, Variable.LIST_TYPE);744 t.equal(varListRefs['mock list id'][0].referencingField.value, 'a mock list');745 t.end();...
importMarkdown.js
Source:importMarkdown.js
...82 switch (token.type) {83 case 'frontmatter': {84 const lang = 'yaml'85 value = token.text86 block = this.createBlock('pre', {87 functionType: token.type,88 lang89 })90 const codeBlock = this.createBlock('code', {91 lang92 })93 value94 .replace(/^\s+/, '')95 .replace(/\s$/, '')96 .split(LINE_BREAKS_REG).forEach(line => {97 const codeLine = this.createBlock('span', {98 text: line,99 lang,100 functionType: 'codeLine'101 })102 this.appendChild(codeBlock, codeLine)103 })104 this.appendChild(block, codeBlock)105 this.appendChild(parentList[0], block)106 break107 }108 case 'hr': {109 value = token.marker110 block = this.createBlock('hr')111 const thematicBreakContent = this.createBlock('span', {112 text: value,113 functionType: 'thematicBreakLine'114 })115 this.appendChild(block, thematicBreakContent)116 this.appendChild(parentList[0], block)117 break118 }119 case 'heading': {120 const { headingStyle, depth, text, marker } = token121 value = headingStyle === 'atx' ? '#'.repeat(+depth) + ` ${text}` : text122 block = this.createBlock(`h${depth}`, {123 headingStyle124 })125 const headingContent = this.createBlock('span', {126 text: value,127 functionType: headingStyle === 'atx' ? 'atxLine' : 'paragraphContent'128 })129 this.appendChild(block, headingContent)130 if (marker) {131 block.marker = marker132 }133 this.appendChild(parentList[0], block)134 break135 }136 case 'multiplemath': {137 value = token.text138 block = this.createContainerBlock(token.type, value)139 this.appendChild(parentList[0], block)140 break141 }142 case 'code': {143 const { codeBlockStyle, text, lang: infostring = '' } = token144 // GH#697, markedjs#1387145 const lang = (infostring || '').match(/\S*/)[0]146 value = text147 if (value.endsWith('\n')) {148 value = value.replace(/\n+$/, '')149 }150 if (/mermaid|flowchart|vega-lite|sequence/.test(lang)) {151 block = this.createContainerBlock(lang, value)152 this.appendChild(parentList[0], block)153 } else {154 block = this.createBlock('pre', {155 functionType: codeBlockStyle === 'fenced' ? 'fencecode' : 'indentcode',156 lang157 })158 const codeBlock = this.createBlock('code', {159 lang160 })161 value.split(LINE_BREAKS_REG).forEach(line => {162 const codeLine = this.createBlock('span', {163 text: line164 })165 codeLine.lang = lang166 codeLine.functionType = 'codeLine'167 this.appendChild(codeBlock, codeLine)168 })169 const inputBlock = this.createBlock('span', {170 text: lang,171 functionType: 'languageInput'172 })173 if (lang && !languageLoaded.has(lang)) {174 languageLoaded.add(lang)175 loadLanguage(lang)176 .then(infoList => {177 if (!Array.isArray(infoList)) return178 // There are three status `loaded`, `noexist` and `cached`.179 // if the status is `loaded`, indicated that it's a new loaded language180 const needRender = infoList.some(({ status }) => status === 'loaded')181 if (needRender) {182 this.render()183 }184 })185 .catch(err => {186 // if no parameter provided, will cause error.187 console.warn(err)188 })189 }190 this.appendChild(block, inputBlock)191 this.appendChild(block, codeBlock)192 this.appendChild(parentList[0], block)193 }194 break195 }196 case 'table': {197 const { header, align, cells } = token198 const table = this.createBlock('table')199 const thead = this.createBlock('thead')200 const tbody = this.createBlock('tbody')201 const theadRow = this.createBlock('tr')202 const restoreTableEscapeCharacters = text => {203 // NOTE: markedjs replaces all escaped "|" ("\|") characters inside a cell with "|".204 // We have to re-escape the chraracter to not break the table.205 return text.replace(/\|/g, '\\|')206 }207 for (const headText of header) {208 const i = header.indexOf(headText)209 const th = this.createBlock('th', {210 text: restoreTableEscapeCharacters(headText)211 })212 Object.assign(th, { align: align[i] || '', column: i })213 this.appendChild(theadRow, th)214 }215 for (const row of cells) {216 const rowBlock = this.createBlock('tr')217 for (const cell of row) {218 const i = row.indexOf(cell)219 const td = this.createBlock('td', {220 text: restoreTableEscapeCharacters(cell)221 })222 Object.assign(td, { align: align[i] || '', column: i })223 this.appendChild(rowBlock, td)224 }225 this.appendChild(tbody, rowBlock)226 }227 Object.assign(table, { row: cells.length, column: header.length - 1 }) // set row and column228 block = this.createBlock('figure')229 block.functionType = 'table'230 this.appendChild(thead, theadRow)231 this.appendChild(block, table)232 this.appendChild(table, thead)233 this.appendChild(table, tbody)234 this.appendChild(parentList[0], block)235 break236 }237 case 'html': {238 const { text } = token239 block = this.createHtmlBlock(text.trim())240 this.appendChild(parentList[0], block)241 break242 }243 case 'text': {244 value = token.text245 while (tokens[0].type === 'text') {246 token = tokens.shift()247 value += `\n${token.text}`248 }249 block = this.createBlock('p')250 const contentBlock = this.createBlock('span', {251 text: value252 })253 this.appendChild(block, contentBlock)254 this.appendChild(parentList[0], block)255 break256 }257 case 'paragraph': {258 value = token.text259 block = this.createBlock('p')260 const contentBlock = this.createBlock('span', {261 text: value262 })263 this.appendChild(block, contentBlock)264 this.appendChild(parentList[0], block)265 break266 }267 case 'blockquote_start': {268 block = this.createBlock('blockquote')269 this.appendChild(parentList[0], block)270 parentList.unshift(block)271 break272 }273 case 'blockquote_end': {274 parentList.shift()275 break276 }277 case 'list_start': {278 const { ordered, listType, start } = token279 block = this.createBlock(ordered === true ? 'ol' : 'ul')280 block.listType = listType281 if (listType === 'order') {282 block.start = /^\d+$/.test(start) ? start : 1283 }284 this.appendChild(parentList[0], block)285 parentList.unshift(block)286 break287 }288 case 'list_end': {289 parentList.shift()290 break291 }292 case 'loose_item_start':293 case 'list_item_start': {294 const { listItemType, bulletMarkerOrDelimiter, checked, type } = token295 block = this.createBlock('li', {296 listItemType: checked !== undefined ? 'task' : listItemType,297 bulletMarkerOrDelimiter,298 isLooseListItem: type === 'loose_item_start'299 })300 if (checked !== undefined) {301 const input = this.createBlock('input', {302 checked303 })304 this.appendChild(block, input)305 }306 this.appendChild(parentList[0], block)307 parentList.unshift(block)308 break309 }310 case 'list_item_end': {311 parentList.shift()312 break313 }314 case 'space': {315 break...
widget.test.js
Source:widget.test.js
1"use strict";2var __importDefault = (this && this.__importDefault) || function (mod) {3 return (mod && mod.__esModule) ? mod : { "default": mod };4};5Object.defineProperty(exports, "__esModule", { value: true });6const widget_1 = require("./widget");7const BlockFactory_1 = __importDefault(require("../BlockFactory"));8const immer_1 = __importDefault(require("immer"));9const enzyme_1 = require("enzyme");10const innerBlockDef = {11 type: "expression",12 id: "exp1",13 contextVarId: "b1",14 expr: { type: "field", table: "t1", column: "text" },15 format: null16};17const widgetDef = {18 id: "w1",19 name: "W1",20 description: "",21 blockDef: innerBlockDef,22 contextVars: [{ id: "b1", name: "B1", type: "row", table: "t1" }],23 contextVarPreviewValues: {}24};25const blockDef = {26 id: "a",27 type: "widget",28 widgetId: "w1",29 contextVarMap: {30 b1: "a1"31 }32};33const widgetLibrary = {34 widgets: {35 w1: widgetDef36 }37};38const contextVars = [39 { id: "a1", name: "A1", type: "text" },40 { id: "a2", name: "A2", type: "text" }41];42describe("getContextVarExprs", () => {43 test("gathers from inner widget and maps", () => {44 const createBlock = new BlockFactory_1.default().createBlock;45 const widgetBlock = new widget_1.WidgetBlock(blockDef);46 // Get expressions47 const exprs = widgetBlock.getContextVarExprs(contextVars[0], {48 widgetLibrary: widgetLibrary,49 createBlock: createBlock50 });51 expect(exprs).toEqual([{ type: "field", table: "t1", column: "text" }]);52 });53 test("gathers from inner widget and maps variables too", () => {54 // Alter widget block to have variable in expression55 const widgetLibrary2 = (0, immer_1.default)(widgetLibrary, (draft) => {56 ;57 draft.widgets.w1.blockDef.expr = { type: "variable", variableId: "b1" };58 });59 const createBlock = new BlockFactory_1.default().createBlock;60 const widgetBlock = new widget_1.WidgetBlock(blockDef);61 // Get expressions62 const exprs = widgetBlock.getContextVarExprs(contextVars[0], {63 widgetLibrary: widgetLibrary2,64 createBlock: createBlock65 });66 expect(exprs).toEqual([{ type: "variable", variableId: "a1" }]);67 });68});69describe("getInitialFilters", () => {70 test("translates", () => {71 const createBlock = jest.fn();72 const widgetBlock = new widget_1.WidgetBlock(blockDef);73 const innerBlock = {74 getInitialFilters: jest.fn()75 };76 // Return inner block77 createBlock.mockReset();78 createBlock.mockReturnValueOnce(innerBlock);79 innerBlock.getInitialFilters.mockReturnValue([{ id: "f1", memo: "m", expr: {} }]);80 const filters = widgetBlock.getInitialFilters("a1", {81 widgetLibrary: widgetLibrary,82 contextVars: [],83 createBlock: createBlock84 });85 expect(filters).toEqual([{ id: "f1", memo: "m", expr: {} }]);86 expect(innerBlock.getInitialFilters.mock.calls[0][0]).toBe("b1");87 });88});89describe("renderInstance", () => {90 let instanceCtx;91 let innerInstanceCtx;92 // Render instance93 beforeEach((done) => {94 const createBlock = jest.fn();95 const widgetBlock = new widget_1.WidgetBlock(blockDef);96 const innerBlock = {97 renderInstance: (instanceCtx) => {98 innerInstanceCtx = instanceCtx;99 done();100 }101 };102 // Return inner block103 createBlock.mockReturnValueOnce(innerBlock);104 instanceCtx = {105 createBlock: createBlock,106 locale: "en",107 database: {},108 schema: {},109 dataSource: {},110 contextVars: contextVars,111 actionLibrary: {},112 widgetLibrary: { widgets: { w1: widgetDef } },113 pageStack: {},114 contextVarValues: { a1: "a1" },115 getContextVarExprValue: jest.fn(),116 onSelectContextVar: jest.fn(),117 setFilter: jest.fn(),118 getFilters: jest.fn(),119 renderChildBlock: jest.fn(),120 registerForValidation: () => {121 return () => { };122 },123 T: (str) => str124 };125 const x = (0, enzyme_1.shallow)(widgetBlock.renderInstance(instanceCtx));126 });127 test("contextVars", () => {128 expect(innerInstanceCtx.contextVars).toEqual(contextVars.concat(widgetDef.contextVars));129 });130 test("contextVarValues maps", () => {131 expect(innerInstanceCtx.contextVarValues.b1).toBe("a1");132 });133 test("getContextVarExprValue maps variables", () => {134 const outerGetContextVarExprValue = jest.fn();135 instanceCtx.getContextVarExprValue = outerGetContextVarExprValue;136 outerGetContextVarExprValue.mockReturnValue("abc");137 const innerExpr = { type: "variable", variableId: "b1" };138 expect(innerInstanceCtx.getContextVarExprValue("b1", innerExpr)).toBe("abc");139 expect(outerGetContextVarExprValue.mock.calls[0][0]).toBe("a1");140 expect(outerGetContextVarExprValue.mock.calls[0][1]).toEqual({ type: "variable", variableId: "a1" });141 });142 test("onSelectContextVar maps", () => {143 innerInstanceCtx.onSelectContextVar("b1", "pk");144 expect(instanceCtx.onSelectContextVar.mock.calls[0]).toEqual(["a1", "pk"]);145 });146 test("setFilter maps", () => {147 innerInstanceCtx.setFilter("b1", {});148 expect(instanceCtx.setFilter.mock.calls[0]).toEqual(["a1", {}]);149 });150});151describe("mapObjectTree", () => {152 test("deep mapping", () => {153 const obj = {154 x: 1,155 y: [{ foo: 1 }]156 };157 expect((0, widget_1.mapObjectTree)(obj, (input) => {158 return input.foo ? { foo: 2 } : input;159 })).toEqual({160 x: 1,161 y: [{ foo: 2 }]162 });163 });...
blocks.test.js
Source:blocks.test.js
1"use strict";2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {3 if (k2 === undefined) k2 = k;4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });5}) : (function(o, m, k, k2) {6 if (k2 === undefined) k2 = k;7 o[k2] = m[k];8}));9var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {10 Object.defineProperty(o, "default", { enumerable: true, value: v });11}) : function(o, v) {12 o["default"] = v;13});14var __importStar = (this && this.__importStar) || function (mod) {15 if (mod && mod.__esModule) return mod;16 var result = {};17 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);18 __setModuleDefault(result, mod);19 return result;20};21var __importDefault = (this && this.__importDefault) || function (mod) {22 return (mod && mod.__esModule) ? mod : { "default": mod };23};24Object.defineProperty(exports, "__esModule", { value: true });25const blocks = __importStar(require("./blocks"));26const BlockFactory_1 = __importDefault(require("./BlockFactory"));27const mwater_expressions_1 = require("mwater-expressions");28const schema = new mwater_expressions_1.Schema();29test("drops left", () => {30 const source = { id: "a", type: "dummy" };31 const target = { id: "b", type: "dummy" };32 const result = blocks.dropBlock(source, target, blocks.DropSide.left);33 expect(result.type).toBe("horizontal");34 expect(result.items[0]).toBe(source);35 expect(result.items[1]).toBe(target);36});37test("findBlockAncestry", () => {38 const createBlock = new BlockFactory_1.default().createBlock;39 // Create simple tree40 const blockDef = {41 id: "a1",42 type: "horizontal",43 align: "justify",44 items: [45 {46 id: "b1",47 type: "horizontal",48 align: "justify",49 items: [{ id: "c1", type: "horizontal", items: [] }]50 }51 ]52 };53 expect(blocks.findBlockAncestry(blockDef, createBlock, [], "a1", schema).map((b) => b.blockDef.id)).toEqual(["a1"]);54 expect(blocks.findBlockAncestry(blockDef, createBlock, [], "b1", schema).map((b) => b.blockDef.id)).toEqual(["a1", "b1"]);55 expect(blocks.findBlockAncestry(blockDef, createBlock, [], "c1", schema).map((b) => b.blockDef.id)).toEqual([56 "a1",57 "b1",58 "c1"59 ]);60 expect(blocks.findBlockAncestry(blockDef, createBlock, [], "x", schema)).toBeNull();61});62test("findBlockAncestry with queryTable", () => {63 const createBlock = new BlockFactory_1.default().createBlock;64 // Root cv65 const rootContextVars = [{ id: "cv1", type: "rowset", table: "t1", name: "CV1" }];66 // Create simple tree67 const blockDef = {68 id: "qt1",69 type: "queryTable",70 rowsetContextVarId: "cv1",71 mode: "singleRow",72 headers: [],73 contents: [{ id: "c1", type: "horizontal", items: [] }]74 };75 const ancestry = blocks.findBlockAncestry(blockDef, createBlock, rootContextVars, "c1", schema);76 expect(ancestry).toEqual([77 { blockDef: blockDef, contextVars: rootContextVars },78 {79 blockDef: blockDef.contents[0],80 contextVars: rootContextVars.concat({ id: "qt1_row", name: "Table row of CV1", type: "row", table: "t1" })81 }82 ]);83});84test("getBlockTree", () => {85 const createBlock = new BlockFactory_1.default().createBlock;86 // Create simple tree87 const blockDef = {88 id: "a1",89 type: "horizontal",90 items: [91 {92 id: "b1",93 type: "horizontal",94 align: "justify",95 items: [{ id: "c1", type: "horizontal", align: "justify", items: [] }]96 }97 ]98 };99 expect(blocks.getBlockTree(blockDef, createBlock, [], schema).map((b) => b.blockDef.id)).toEqual(["a1", "b1", "c1"]);100});101test("createExprVariables", () => {102 expect(blocks.createExprVariables([{ id: "cv1", type: "row", name: "Cv1", table: "t1" }])).toEqual([103 { id: "cv1", type: "id", name: { _base: "en", en: "Cv1" }, idTable: "t1" }104 ]);105 expect(blocks.createExprVariables([{ id: "cv1", type: "text", name: "Cv1" }])).toEqual([106 { id: "cv1", type: "text", name: { _base: "en", en: "Cv1" } }107 ]);108 expect(blocks.createExprVariables([{ id: "cv1", type: "rowset", name: "Cv1", table: "t1" }])).toEqual([109 { id: "cv1", type: "boolean", name: { _base: "en", en: "Cv1" }, table: "t1" }110 ]);111});112test("duplicateBlockDef with queryTable", () => {113 const createBlock = new BlockFactory_1.default().createBlock;114 // Root cv115 const rootContextVars = [{ id: "cv1", type: "rowset", table: "t1", name: "CV1" }];116 // Create simple tree117 const blockDef = {118 id: "qt1",119 type: "queryTable",120 rowsetContextVarId: "cv1",121 mode: "singleRow",122 headers: [],123 contents: [{ id: "c1", type: "horizontal", items: [] }]124 };125 const duplicate = blocks.duplicateBlockDef(blockDef, createBlock);126 expect(duplicate.id).not.toBe(blockDef.id);127 expect(duplicate.contents[0].id).not.toBe(blockDef.contents[0].id);...
transforms.js
Source:transforms.js
...16 {17 type: 'block',18 blocks: [ 'coblocks/gallery-stacked' ],19 transform: ( attributes ) => (20 createBlock( metadata.name, {21 ...GalleryTransforms( attributes ),22 } )23 ),24 },25 {26 type: 'block',27 blocks: [ 'coblocks/gallery-carousel' ],28 transform: ( attributes ) => (29 createBlock( metadata.name, {30 ...GalleryTransforms( attributes ),31 } )32 ),33 },34 {35 type: 'block',36 blocks: [ 'coblocks/gallery-thumbnails' ],37 transform: ( attributes ) => (38 createBlock( metadata.name, {39 ...GalleryTransforms( attributes ),40 } )41 ),42 },43 {44 type: 'block',45 blocks: [ 'coblocks/gallery-offset' ],46 transform: ( attributes ) => (47 createBlock( metadata.name, {48 ...GalleryTransforms( attributes ),49 } )50 ),51 },52 {53 type: 'block',54 blocks: [ 'coblocks/gallery-auto-height' ],55 transform: ( attributes ) => (56 createBlock( metadata.name, {57 ...GalleryTransforms( attributes ),58 } )59 ),60 },61 {62 type: 'block',63 blocks: [ 'blockgallery/stacked' ],64 transform: ( attributes ) => (65 createBlock( metadata.name, {66 ...GalleryTransforms( attributes ),67 } )68 ),69 },70 {71 type: 'block',72 blocks: [ 'blockgallery/masonry' ],73 transform: ( attributes ) => (74 createBlock( metadata.name, {75 ...GalleryTransforms( attributes ),76 } )77 ),78 },79 {80 type: 'block',81 blocks: [ 'blockgallery/carousel' ],82 transform: ( attributes ) => (83 createBlock( metadata.name, {84 ...GalleryTransforms( attributes ),85 } )86 ),87 },88 {89 type: 'block',90 blocks: [ 'core/gallery' ],91 transform: ( attributes ) => (92 createBlock( metadata.name, {93 ...GalleryTransforms( attributes ),94 } )95 ),96 },97 {98 type: 'block',99 isMultiBlock: true,100 blocks: [ 'core/image' ],101 transform: ( attributes ) => {102 const validImages = filter( attributes, ( { id, url } ) => id && url );103 if ( validImages.length > 0 ) {104 return createBlock( metadata.name, {105 images: validImages.map( ( { id, url, alt, caption } ) => ( { id, url, alt, caption } ) ),106 ids: validImages.map( ( { id } ) => id ),107 } );108 }109 return createBlock( metadata.name );110 },111 },112 {113 type: 'prefix',114 prefix: ':masonry',115 transform: function( content ) {116 return createBlock( metadata.name, {117 content,118 } );119 },120 },121 ],122 to: [123 {124 type: 'block',125 blocks: [ 'core/gallery' ],126 transform: ( attributes ) => (127 createBlock( 'core/gallery', {128 ...GalleryTransforms( attributes ),129 } )130 ),131 },132 ],133};...
CreateBlock.js
Source:CreateBlock.js
1import React, { useState } from "react";2import { useMutation } from "@apollo/react-hooks";3import gql from "graphql-tag";4import { makeStyles } from "@material-ui/core/styles";5import Paper from "@material-ui/core/Paper";6import Typography from "@material-ui/core/Typography";7import Button from "@material-ui/core/Button";8import CreateBlockTextField from "./CreateBlockTextField";9const useStyles = makeStyles(theme => ({10 root: {11 width: "100%",12 flexGrow: 113 },14 button: {15 marginTop: theme.spacing(1),16 marginRight: theme.spacing(1)17 },18 actionsContainer: {19 marginBottom: theme.spacing(2)20 },21 resetContainer: {22 padding: theme.spacing(3)23 },24 container: {25 display: "flex",26 flexWrap: "wrap"27 }28}));29const CREATE_BLOCK = gql`30 mutation CreateBlock($name: String!) {31 CreateBlock(name: $name) {32 name33 }34 }35`;36export default function CreateBlock({ data, GET_BLOCKS }) {37 const classes = useStyles();38 const [name, setName] = useState("");39 const [CreateBlock] = useMutation(40 CREATE_BLOCK,41 {42 update(cache, { data: { CreateBlock } }) {43 const { Block } = cache.readQuery({ query: GET_BLOCKS });44 cache.writeQuery({45 query: GET_BLOCKS,46 data: { Block: Block.concat([CreateBlock]) },47 })48 }49 }50 );51 const handleReset = () => {52 setName("");53 };54 return (55 <div className={classes.root} /*justifyContent="flex-start"*/>56 <form className={classes.container} noValidate autoComplete="off">57 <CreateBlockTextField58 name={name}59 setName={setName}60 />61 </form>62 63 <Button64 onClick={e => {65 CreateBlock({66 variables: { name: name }67 });68 }}69 className={classes.button}70 color="primary"71 variant="contained"72 >73 Submit74 </Button>75 </div>76 );...
index.js
Source:index.js
...7import "./plugin.scss";8import SwitcherControls from "./components/SwitcherControls";9const LayoutSwitcher = () => {10 const layouts = {11 default: [createBlock("core/paragraph", {})],12 hero: [13 createBlock("core/cover", { align: "full" }),14 createBlock("core/button", {15 text: __("Layout Switcher", "antaresplugin"),16 align: "center"17 }),18 createBlock("core/columns", { columns: 3 })19 ],20 featured: [21 createBlock("core/heading", {}),22 createBlock("core/spacer", { height: "10" }),23 createBlock("core/media-text", { align: "full" }),24 createBlock("core/spacer", { height: "40" }),25 createBlock("core/quote", {}),26 createBlock("core/spacer", { height: "20" }),27 createBlock("core/media-text", { mediaPosition: "right" }),28 createBlock("core/paragraph", {29 placeholder: __("Outro Text", "antaresplugin")30 })31 ]32 };33 return (34 <Fragment>35 <PluginSidebarMoreMenuItem target="jsforwpadvgb-layout-switcher">36 {__("Layout Switcher", "antaresplugin")}37 </PluginSidebarMoreMenuItem>38 <PluginSidebar39 name="jsforwpadvgb-layout-switcher"40 title={__("Layout Switcher", "antaresplugin")}41 >42 <SwitcherControls icons={icons} layouts={layouts} />...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const elementHandle = await page.$('div');7 const block = await elementHandle._createBlock('div');8 await page.setContent(block);9 await page.screenshot({ path: 'example.png' });10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const block = await page._createBlock('div', {18 });19 await page.setContent(block);20 await page.screenshot({ path: 'example.png' });21 await browser.close();22})();23[MIT](LICENSE)
Using AI Code Generation
1const { chromium } = require("playwright");2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const block = await page._client.send("DOMDebugger.createBlock", {6 attributes: { "data-test-id": "block" },7 });8 console.log(block);9 await browser.close();10})();
Using AI Code Generation
1const { chromium, webkit, firefox } = require('playwright');2const { createBlock } = require('playwright-core/lib/server/frames');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const block = await createBlock(page, 'div', {}, 'Hello World!');8 console.log(block.outerHTML);9 await browser.close();10})();
Using AI Code Generation
1const { createBlock } = require( '@wordpress/e2e-test-utils' );2const blockName = 'core/paragraph';3const blockAttributes = {4};5const createdBlock = await createBlock( blockName, blockAttributes );6const { createNewPost } = require( '@wordpress/e2e-test-utils' );7await createNewPost();8const { deleteBlock } = require( '@wordpress/e2e-test-utils' );9await deleteBlock( 'block-client-id' );10const { getEditedPostContent } = require( '@wordpress/e2e-test-utils' );11const editedPostContent = await getEditedPostContent();12const { insertBlock } = require( '@wordpress/e2e-test-utils' );13await insertBlock( 'Paragraph' );
Using AI Code Generation
1const { chromium } = require('playwright');2const path = require('path');3const fs = require('fs');4const { expect } = require('chai');5(async () => {6 const browser = await chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 const block = await page._createBlock({ name: 'div' });10 const block2 = await page._createBlock({11 attributes: { id: 'test' },12 });13 const block3 = await page._createBlock({14 attributes: { id: 'test' },15 styles: { 'background-color': 'red' },16 });17 const block4 = await page._createBlock({18 attributes: { id: 'test' },19 styles: { 'background-color': 'red' },20 });21 const block5 = await page._createBlock({22 attributes: { id: 'test' },23 styles: { 'background-color': 'red' },24 { name: 'div', attributes: { id: 'test' }, styles: { 'background-color': 'red' }, content: 'test' },25 { name: 'div', attributes: { id: 'test' }, styles: { 'background-color': 'red' }, content: 'test' },26 });27 const block6 = await page._createBlock({28 attributes: { id: 'test' },29 styles: { 'background-color': 'red' },30 { name: 'div', attributes: { id: 'test' }, styles: { 'background-color': 'red' }, content: 'test' },31 { name: 'div', attributes: { id: 'test' }, styles: { 'background-color': 'red' }, content: 'test' },
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const block = await page._client.send('DOM.createBlock', {6 attributes: {7 style: 'border: 1px solid red; height: 100px; width: 100px; position: absolute; left: 0px; top: 0px;',8 }9 });10 await page._client.send('DOM.appendChild', {11 parentNodeId: await page._client.send('DOM.getDocument', {}).then(res => res.root.nodeId),12 });13 await page._client.send('DOM.setOuterHTML', {14 outerHTML: '<div id="block1" style="border: 1px solid red; height: 100px; width: 100px; position: absolute; left: 0px; top: 0px;">Hello World</div>'15 });16 await page._client.send('DOM.removeChildNodes', {17 nodeId: await page._client.send('DOM.getDocument', {}).then(res => res.root.nodeId),18 });19 await browser.close();20})();
Using AI Code Generation
1const createBlock = require('@playwright/test').createBlock;2const block = createBlock('test', async ({ page }) => {3});4const createFixture = require('@playwright/test').createFixture;5const server = createFixture(async ({}, runTest) => {6 const server = await TestServer.create();7 await runTest(server);8 await server.stop();9});10const createTest = require('@playwright/test').createTest;11const test = createTest('test', async ({ page }) => {12});13### createBlock(name, fn, options)14### createFixture(name, fn, options)15### createTest(name, fn, options)
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!