@@ -643,7 +643,7 @@ ocargo.LevelEditor = function(levelId) {
643
643
return ;
644
644
}
645
645
646
- const regex = / ^ ( \w ? [ ] ? ) * $ / ;
646
+ const regex = / ^ [ \w ] * $ / ;
647
647
const validString = regex . exec ( nameInput . val ( ) ) ;
648
648
if ( ! validString ) {
649
649
ocargo . Drawing . startPopup (
@@ -1685,7 +1685,7 @@ ocargo.LevelEditor = function(levelId) {
1685
1685
var bBox = image . getBBox ( ) ;
1686
1686
imageWidth = bBox . width ;
1687
1687
imageHeight = bBox . height ;
1688
-
1688
+
1689
1689
var paperPosition = paper . position ( ) ;
1690
1690
originX = x - paperPosition . left + paper . scrollLeft ( ) - imageWidth / 2 ;
1691
1691
originY = y - paperPosition . top + paper . scrollTop ( ) - imageHeight / 2 ;
@@ -1697,7 +1697,7 @@ ocargo.LevelEditor = function(levelId) {
1697
1697
}
1698
1698
1699
1699
function onDragEnd ( ) {
1700
-
1700
+
1701
1701
if ( trashcanOpen ) {
1702
1702
cow . destroy ( ) ;
1703
1703
unmarkOldCowSquare ( controlledCoord , cow ) ;
@@ -1714,15 +1714,15 @@ ocargo.LevelEditor = function(levelId) {
1714
1714
else {
1715
1715
var cowX = paperX ;
1716
1716
var cowY = paperY ;
1717
-
1717
+
1718
1718
if ( paperWidth < paperX + imageWidth ) {
1719
1719
cowX = paperWidth - imageWidth
1720
1720
}
1721
-
1721
+
1722
1722
if ( paperHeight < paperY + imageHeight ) {
1723
1723
cowY = paperHeight - imageHeight
1724
1724
}
1725
-
1725
+
1726
1726
image . transform ( 't' + cowX + ',' + cowY ) ;
1727
1727
}
1728
1728
}
@@ -1875,12 +1875,12 @@ ocargo.LevelEditor = function(levelId) {
1875
1875
internalCow . destroy ( ) ;
1876
1876
}
1877
1877
}
1878
-
1878
+
1879
1879
if ( ! trashcanOpen ) {
1880
1880
setCowMarkingsOnMouseUp ( controlledCoord , internalCow ) ;
1881
1881
adjustCowGroupMinMaxFields ( internalCow ) ;
1882
1882
}
1883
-
1883
+
1884
1884
$ ( document )
1885
1885
. off ( 'mousemove' , handleDraggableCowDragging )
1886
1886
. off ( 'mouseup mouseleave' , handleDraggableCowMouseUp ) ;
@@ -2416,7 +2416,7 @@ ocargo.LevelEditor = function(levelId) {
2416
2416
"><path class="blocklyPath" stroke="none" fill="#5b80a5" d="m 0,0 H 111.34375 v 30 H 0 V 20 c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 z
2417
2417
"></path><path class="blocklyPathLight" stroke="#8ca6c0" d="m 0.5,0.5 H 110.84375 M 110.84375,0.5 M 0.5,29.5 V 18.5 m -7.36,-0.5 q -1.52,-5.5 0,-11 m 7.36,1 V 0.5 H 1
2418
2418
"></path><text class="blocklyText" y="12.5" transform="translate(10,5)">pigeons</text><g transform="translate(71.34375,5)"><image height="20px" width="30px" xlink:href="/static/game/image/pigeon.svg" alt=""></image></g></g></svg>` ;
2419
-
2419
+
2420
2420
const cowHTML = `<svg class="block_image"><g transform="translate(10,0)" <path="" class="blocklyPathDark" fill="#496684" d="m 0,0 H 93.40625 v 30 H 0 V 20 c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 z
2421
2421
"><path class="blocklyPath" stroke="none" fill="#5b80a5" d="m 0,0 H 93.40625 v 30 H 0 V 20 c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 z
2422
2422
"></path><path class="blocklyPathLight" stroke="#8ca6c0" d="m 0.5,0.5 H 92.90625 M 92.90625,0.5 M 0.5,29.5 V 18.5 m -7.36,-0.5 q -1.52,-5.5 0,-11 m 7.36,1 V 0.5 H 1
@@ -2545,17 +2545,55 @@ ocargo.LevelEditor = function(levelId) {
2545
2545
state . python_view_enabled = language === 'blocklyWithPythonView' ;
2546
2546
state . python_enabled = language === 'python' || language === 'both' ;
2547
2547
2548
+ const regex = / ^ [ \w . ? ! ' , ] * $ / ;
2549
+ const subtitleValue = $ ( '#subtitle' ) . val ( ) ;
2550
+ const descriptionValue = $ ( '#description' ) . val ( ) ;
2551
+ const hintValue = $ ( '#hint' ) . val ( ) ;
2552
+
2548
2553
// Description and hint data
2549
- if ( $ ( '#subtitle' ) . val ( ) . length > 0 ) {
2550
- state . subtitle = $ ( '#subtitle' ) . val ( ) ;
2554
+ if ( subtitleValue . length > 0 ) {
2555
+ if ( regex . exec ( subtitleValue ) ) {
2556
+ state . subtitle = subtitleValue ;
2557
+ }
2558
+ else {
2559
+ ocargo . Drawing . startPopup (
2560
+ "Oh no!" ,
2561
+ "You used some invalid characters for your level subtitle." ,
2562
+ "Try saving your level again using only" +
2563
+ " letters, numbers and standard punctuation."
2564
+ ) ;
2565
+ return
2566
+ }
2551
2567
}
2552
2568
2553
- if ( $ ( '#description' ) . val ( ) . length > 0 ) {
2554
- state . lesson = $ ( '#description' ) . val ( ) ;
2569
+ if ( descriptionValue . length > 0 ) {
2570
+ if ( regex . exec ( descriptionValue ) ) {
2571
+ state . lesson = descriptionValue ;
2572
+ }
2573
+ else {
2574
+ ocargo . Drawing . startPopup (
2575
+ "Oh no!" ,
2576
+ "You used some invalid characters for your level description." ,
2577
+ "Try saving your level again using only" +
2578
+ " letters and numbers and standard punctuation."
2579
+ ) ;
2580
+ return
2581
+ }
2555
2582
}
2556
2583
2557
- if ( $ ( '#hint' ) . val ( ) . length > 0 ) {
2558
- state . hint = $ ( '#hint' ) . val ( ) ;
2584
+ if ( hintValue . length > 0 ) {
2585
+ if ( regex . exec ( hintValue ) ) {
2586
+ state . hint = hintValue ;
2587
+ }
2588
+ else {
2589
+ ocargo . Drawing . startPopup (
2590
+ "Oh no!" ,
2591
+ "You used some invalid characters for your level hint." ,
2592
+ "Try saving your level again using only" +
2593
+ " letters and numbers and standard punctuation."
2594
+ ) ;
2595
+ return
2596
+ }
2559
2597
}
2560
2598
2561
2599
// Other data
0 commit comments