smalruby-editor 0.1.24 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +9 -0
  3. data/app/assets/javascripts/blocks/hardware.js.coffee.erb +147 -62
  4. data/app/assets/javascripts/blocks/sensing.js.coffee.erb +4 -0
  5. data/app/assets/javascripts/msg/en_us.js +34 -12
  6. data/app/assets/javascripts/msg/ja.js +35 -15
  7. data/app/helpers/editor_helper.rb +2 -1
  8. data/app/models/concerns/ruby_to_block/block/{hardware_button_down_or_up.rb → hardware_button_pressed_or_released.rb} +3 -3
  9. data/app/models/concerns/ruby_to_block/block/{hardware_led_on.rb → hardware_led_turn_off.rb} +2 -2
  10. data/app/models/concerns/ruby_to_block/block/{hardware_led_off.rb → hardware_led_turn_on.rb} +2 -2
  11. data/app/models/concerns/ruby_to_block/block/hardware_operation.rb +2 -0
  12. data/app/models/concerns/ruby_to_block/block/{hardware_rgb_led_on.rb → hardware_rgb_led_set_color.rb} +2 -2
  13. data/app/models/concerns/ruby_to_block/block/{hardware_rgb_led_off.rb → hardware_rgb_led_turn_off.rb} +2 -2
  14. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_action.rb +22 -0
  15. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_action_with_sec.rb +24 -0
  16. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_led_turn_on_or_off.rb +22 -0
  17. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_light_sensor_value.rb +28 -0
  18. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_touch_sensor_pressed_or_released.rb +29 -0
  19. data/app/models/concerns/ruby_to_block/block/hardware_two_wheel_drive_car_commands.rb +3 -1
  20. data/app/views/editor/_toolbox.html.haml +30 -17
  21. data/app/views/layouts/application.html.erb +3 -1
  22. data/config/locales/en.yml +1 -0
  23. data/config/locales/ja.yml +1 -0
  24. data/lib/smalruby_editor/blockly_message_helper.rb +2 -1
  25. data/lib/smalruby_editor/version.rb +1 -1
  26. data/lib/tasks/release.rake +0 -0
  27. data/smalruby-editor.gemspec +1 -1
  28. data/spec/acceptance/block_mode/blocks/hardware/{button_down_or_up.feature → button_pressed_or_released.feature} +15 -15
  29. data/spec/acceptance/block_mode/blocks/hardware/led_turn_off.feature +67 -0
  30. data/spec/acceptance/block_mode/blocks/hardware/led_turn_on.feature +67 -0
  31. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_set_color.feature +79 -0
  32. data/spec/acceptance/block_mode/blocks/hardware/{button_not_use_pullup.feature → rgb_led_turn_off.feature} +30 -18
  33. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_action.feature +107 -0
  34. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_action_with_sec.feature +151 -0
  35. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_led_turn_on_or_off.feature +73 -0
  36. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_light_sensor_value.feature +92 -0
  37. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_motor_speed.feature +116 -0
  38. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_touch_sensor_pressed_or_released.feature +108 -0
  39. data/spec/models/concerns/ruby_to_block/block/hardware_spec.rb +359 -36
  40. data/spec/models/concerns/ruby_to_block_spec.rb +8 -8
  41. data/spec/steps/block_mode_steps.rb +8 -0
  42. metadata +43 -35
  43. data/app/models/concerns/ruby_to_block/block/hardware_button_not_use_pullup.rb +0 -18
  44. data/app/models/concerns/ruby_to_block/block/hardware_on_button_down_or_up.rb +0 -19
  45. data/app/models/concerns/ruby_to_block/block/hardware_on_sensor_change.rb +0 -17
  46. data/spec/acceptance/block_mode/blocks/hardware/led_off.feature +0 -75
  47. data/spec/acceptance/block_mode/blocks/hardware/led_on.feature +0 -75
  48. data/spec/acceptance/block_mode/blocks/hardware/on_button_down_or_up.feature +0 -87
  49. data/spec/acceptance/block_mode/blocks/hardware/on_sensor_change.feature +0 -81
  50. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_off.feature +0 -81
  51. data/spec/acceptance/block_mode/blocks/hardware/rgb_led_on.feature +0 -87
@@ -12,15 +12,15 @@ init_hardware
12
12
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
13
13
 
14
14
  car1.on(:start) do
15
- led("D4").on
16
- rgb_led_cathode("D9").on(color: [255, 0, 0])
15
+ led("D4").turn_on
16
+ rgb_led_cathode("D9").color = [255, 0, 0]
17
17
  two_wheel_drive_car("D6").forward
18
18
  end
19
- car1.led("D4").off
20
- car1.rgb_led_cathode("D9").off
19
+ car1.led("D4").turn_off
20
+ car1.rgb_led_cathode("D9").turn_off
21
21
  car1.two_wheel_drive_car("D6").backward
22
22
 
23
- car1.on(:sensor_change, "A0") do
23
+ car1.on(:start) do
24
24
  if sensor("A0").value < 200
25
25
  two_wheel_drive_car("D6").turn_left
26
26
  two_wheel_drive_car("D6").turn_right
@@ -46,10 +46,10 @@ end
46
46
  <statement name="DO">
47
47
  <block type="events_on_start">
48
48
  <statement name="DO">
49
- <block type="hardware_led_on">
49
+ <block type="hardware_led_turn_on">
50
50
  <field name="PIN">D4</field>
51
51
  <next>
52
- <block type="hardware_rgb_led_on">
52
+ <block type="hardware_rgb_led_set_color">
53
53
  <field name="AC">cathode</field>
54
54
  <field name="PIN">D9</field>
55
55
  <field name="COLOUR">#ff0000</field>
@@ -63,18 +63,17 @@ end
63
63
  </block>
64
64
  </statement>
65
65
  <next>
66
- <block type="hardware_led_off">
66
+ <block type="hardware_led_turn_off">
67
67
  <field name="PIN">D4</field>
68
68
  <next>
69
- <block type="hardware_rgb_led_off">
69
+ <block type="hardware_rgb_led_turn_off">
70
70
  <field name="AC">cathode</field>
71
71
  <field name="PIN">D9</field>
72
72
  <next>
73
73
  <block type="hardware_two_wheel_drive_car_backward">
74
74
  <field name="PIN">D6</field>
75
75
  <next>
76
- <block type="hardware_on_sensor_change">
77
- <field name="PIN">A0</field>
76
+ <block type="events_on_start">
78
77
  <statement name="DO">
79
78
  <block type="control_if" inline="true">
80
79
  <value name="COND">
@@ -387,14 +386,12 @@ require "smalruby"
387
386
  init_hardware
388
387
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
389
388
 
390
- car1.on(:button_down, "D3") do
391
- p(button("D3").up?)
392
- p(button("D3").down?)
393
- button("D3").not_use_pullup
389
+ car1.on(:start) do
390
+ p(button("D3").released?)
391
+ p(button("D3").pressed?)
394
392
  end
395
- p(car1.button("D3").up?)
396
- p(car1.button("D3").down?)
397
- car1.button("D3").not_use_pullup
393
+ p(car1.button("D3").released?)
394
+ p(car1.button("D3").pressed?)
398
395
  EOS
399
396
  describe compact_source_code(parts) do
400
397
  _parts = parts
@@ -407,30 +404,23 @@ car1.button("D3").not_use_pullup
407
404
  <block type="character_new">
408
405
  <field name="NAME">car1</field>
409
406
  <statement name="DO">
410
- <block type="hardware_on_button_down_or_up">
411
- <field name="PIN">D3</field>
412
- <field name="DOU">down</field>
407
+ <block type="events_on_start">
413
408
  <statement name="DO">
414
409
  <block type="ruby_p" inline="true">
415
410
  <value name="ARG">
416
- <block type="hardware_button_down_or_up">
411
+ <block type="hardware_button_pressed_or_released">
417
412
  <field name="PIN">D3</field>
418
- <field name="DOU">up</field>
413
+ <field name="POR">released</field>
419
414
  </block>
420
415
  </value>
421
416
  <next>
422
417
  <block type="ruby_p" inline="true">
423
418
  <value name="ARG">
424
- <block type="hardware_button_down_or_up">
419
+ <block type="hardware_button_pressed_or_released">
425
420
  <field name="PIN">D3</field>
426
- <field name="DOU">down</field>
421
+ <field name="POR">pressed</field>
427
422
  </block>
428
423
  </value>
429
- <next>
430
- <block type="hardware_button_not_use_pullup">
431
- <field name="PIN">D3</field>
432
- </block>
433
- </next>
434
424
  </block>
435
425
  </next>
436
426
  </block>
@@ -438,22 +428,355 @@ car1.button("D3").not_use_pullup
438
428
  <next>
439
429
  <block type="ruby_p" inline="true">
440
430
  <value name="ARG">
441
- <block type="hardware_button_down_or_up">
431
+ <block type="hardware_button_pressed_or_released">
442
432
  <field name="PIN">D3</field>
443
- <field name="DOU">up</field>
433
+ <field name="POR">released</field>
444
434
  </block>
445
435
  </value>
446
436
  <next>
447
437
  <block type="ruby_p" inline="true">
448
438
  <value name="ARG">
449
- <block type="hardware_button_down_or_up">
439
+ <block type="hardware_button_pressed_or_released">
450
440
  <field name="PIN">D3</field>
451
- <field name="DOU">down</field>
441
+ <field name="POR">pressed</field>
452
442
  </block>
453
443
  </value>
444
+ </block>
445
+ </next>
446
+ </block>
447
+ </next>
448
+ </block>
449
+ </statement>
450
+ </block>
451
+ XML
452
+ end
453
+ end
454
+
455
+ parts = <<-EOS
456
+ require "smalruby"
457
+
458
+ init_hardware
459
+ car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
460
+
461
+ car1.on(:start) do
462
+ smalrubot_v3.forward
463
+ smalrubot_v3.backward
464
+ smalrubot_v3.turn_left
465
+ smalrubot_v3.turn_right
466
+ smalrubot_v3.stop
467
+
468
+ smalrubot_v3.forward(sec: 0.5)
469
+ smalrubot_v3.backward(sec: 0.4)
470
+ smalrubot_v3.turn_left(sec: 0.3)
471
+ smalrubot_v3.turn_right(sec: 0.2)
472
+ smalrubot_v3.stop(sec: 0.1)
473
+
474
+ p(smalrubot_v3.left_touch_sensor.pressed?)
475
+ p(smalrubot_v3.left_touch_sensor.released?)
476
+ p(smalrubot_v3.right_touch_sensor.pressed?)
477
+ p(smalrubot_v3.right_touch_sensor.released?)
478
+
479
+ p(smalrubot_v3.light_sensor.value)
480
+
481
+ smalrubot_v3.red_led.turn_on
482
+ smalrubot_v3.green_led.turn_off
483
+ end
484
+ car1.smalrubot_v3.forward
485
+ car1.smalrubot_v3.backward
486
+ car1.smalrubot_v3.turn_left
487
+ car1.smalrubot_v3.turn_right
488
+ car1.smalrubot_v3.stop
489
+
490
+ car1.smalrubot_v3.forward(sec: 0.5)
491
+ car1.smalrubot_v3.backward(sec: 0.4)
492
+ car1.smalrubot_v3.turn_left(sec: 0.3)
493
+ car1.smalrubot_v3.turn_right(sec: 0.2)
494
+ car1.smalrubot_v3.stop(sec: 0.1)
495
+
496
+ p(car1.smalrubot_v3.left_touch_sensor.pressed?)
497
+ p(car1.smalrubot_v3.left_touch_sensor.released?)
498
+ p(car1.smalrubot_v3.right_touch_sensor.pressed?)
499
+ p(car1.smalrubot_v3.right_touch_sensor.released?)
500
+
501
+ p(car1.smalrubot_v3.light_sensor.value)
502
+
503
+ car1.smalrubot_v3.red_led.turn_on
504
+ car1.smalrubot_v3.green_led.turn_off
505
+ EOS
506
+ describe compact_source_code(parts) do
507
+ _parts = parts
508
+ let(:data) { _parts }
509
+
510
+ it '結果が正しいこと' do
511
+ should eq_block_xml(<<-XML)
512
+ <character name="car1" x="0" y="0" angle="0" costumes="car1.png" />
513
+ <block type="hardware_init_hardware" />
514
+ <block type="character_new">
515
+ <field name="NAME">car1</field>
516
+ <statement name="DO">
517
+ <block type="events_on_start">
518
+ <statement name="DO">
519
+ <block type="hardware_smalrubot_v3_action" inline="true">
520
+ <field name="ACTION">forward</field>
521
+ <next>
522
+ <block type="hardware_smalrubot_v3_action" inline="true">
523
+ <field name="ACTION">backward</field>
454
524
  <next>
455
- <block type="hardware_button_not_use_pullup">
456
- <field name="PIN">D3</field>
525
+ <block type="hardware_smalrubot_v3_action" inline="true">
526
+ <field name="ACTION">turn_left</field>
527
+ <next>
528
+ <block type="hardware_smalrubot_v3_action" inline="true">
529
+ <field name="ACTION">turn_right</field>
530
+ <next>
531
+ <block type="hardware_smalrubot_v3_action" inline="true">
532
+ <field name="ACTION">stop</field>
533
+ <next>
534
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
535
+ <field name="ACTION">forward</field>
536
+ <value name="SEC">
537
+ <block type="math_number">
538
+ <field name="NUM">0.5</field>
539
+ </block>
540
+ </value>
541
+ <next>
542
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
543
+ <field name="ACTION">backward</field>
544
+ <value name="SEC">
545
+ <block type="math_number">
546
+ <field name="NUM">0.4</field>
547
+ </block>
548
+ </value>
549
+ <next>
550
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
551
+ <field name="ACTION">turn_left</field>
552
+ <value name="SEC">
553
+ <block type="math_number">
554
+ <field name="NUM">0.3</field>
555
+ </block>
556
+ </value>
557
+ <next>
558
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
559
+ <field name="ACTION">turn_right</field>
560
+ <value name="SEC">
561
+ <block type="math_number">
562
+ <field name="NUM">0.2</field>
563
+ </block>
564
+ </value>
565
+ <next>
566
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
567
+ <field name="ACTION">stop</field>
568
+ <value name="SEC">
569
+ <block type="math_number">
570
+ <field name="NUM">0.1</field>
571
+ </block>
572
+ </value>
573
+ <next>
574
+ <block type="ruby_p" inline="true">
575
+ <value name="ARG">
576
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
577
+ <field name="LOR">left</field>
578
+ <field name="POR">pressed</field>
579
+ </block>
580
+ </value>
581
+ <next>
582
+ <block type="ruby_p" inline="true">
583
+ <value name="ARG">
584
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
585
+ <field name="LOR">left</field>
586
+ <field name="POR">released</field>
587
+ </block>
588
+ </value>
589
+ <next>
590
+ <block type="ruby_p" inline="true">
591
+ <value name="ARG">
592
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
593
+ <field name="LOR">right</field>
594
+ <field name="POR">pressed</field>
595
+ </block>
596
+ </value>
597
+ <next>
598
+ <block type="ruby_p" inline="true">
599
+ <value name="ARG">
600
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
601
+ <field name="LOR">right</field>
602
+ <field name="POR">released</field>
603
+ </block>
604
+ </value>
605
+ <next>
606
+ <block type="ruby_p" inline="true">
607
+ <value name="ARG">
608
+ <block type="hardware_smalrubot_v3_light_sensor_value" />
609
+ </value>
610
+ <next>
611
+ <block type="hardware_smalrubot_v3_led_turn_on_or_off" inline="true">
612
+ <field name="COLOUR">red</field>
613
+ <field name="OOO">turn_on</field>
614
+ <next>
615
+ <block type="hardware_smalrubot_v3_led_turn_on_or_off" inline="true">
616
+ <field name="COLOUR">green</field>
617
+ <field name="OOO">turn_off</field>
618
+ </block>
619
+ </next>
620
+ </block>
621
+ </next>
622
+ </block>
623
+ </next>
624
+ </block>
625
+ </next>
626
+ </block>
627
+ </next>
628
+ </block>
629
+ </next>
630
+ </block>
631
+ </next>
632
+ </block>
633
+ </next>
634
+ </block>
635
+ </next>
636
+ </block>
637
+ </next>
638
+ </block>
639
+ </next>
640
+ </block>
641
+ </next>
642
+ </block>
643
+ </next>
644
+ </block>
645
+ </next>
646
+ </block>
647
+ </next>
648
+ </block>
649
+ </next>
650
+ </block>
651
+ </statement>
652
+ <next>
653
+ <block type="hardware_smalrubot_v3_action" inline="true">
654
+ <field name="ACTION">forward</field>
655
+ <next>
656
+ <block type="hardware_smalrubot_v3_action" inline="true">
657
+ <field name="ACTION">backward</field>
658
+ <next>
659
+ <block type="hardware_smalrubot_v3_action" inline="true">
660
+ <field name="ACTION">turn_left</field>
661
+ <next>
662
+ <block type="hardware_smalrubot_v3_action" inline="true">
663
+ <field name="ACTION">turn_right</field>
664
+ <next>
665
+ <block type="hardware_smalrubot_v3_action" inline="true">
666
+ <field name="ACTION">stop</field>
667
+ <next>
668
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
669
+ <field name="ACTION">forward</field>
670
+ <value name="SEC">
671
+ <block type="math_number">
672
+ <field name="NUM">0.5</field>
673
+ </block>
674
+ </value>
675
+ <next>
676
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
677
+ <field name="ACTION">backward</field>
678
+ <value name="SEC">
679
+ <block type="math_number">
680
+ <field name="NUM">0.4</field>
681
+ </block>
682
+ </value>
683
+ <next>
684
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
685
+ <field name="ACTION">turn_left</field>
686
+ <value name="SEC">
687
+ <block type="math_number">
688
+ <field name="NUM">0.3</field>
689
+ </block>
690
+ </value>
691
+ <next>
692
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
693
+ <field name="ACTION">turn_right</field>
694
+ <value name="SEC">
695
+ <block type="math_number">
696
+ <field name="NUM">0.2</field>
697
+ </block>
698
+ </value>
699
+ <next>
700
+ <block type="hardware_smalrubot_v3_action_with_sec" inline="true">
701
+ <field name="ACTION">stop</field>
702
+ <value name="SEC">
703
+ <block type="math_number">
704
+ <field name="NUM">0.1</field>
705
+ </block>
706
+ </value>
707
+ <next>
708
+ <block type="ruby_p" inline="true">
709
+ <value name="ARG">
710
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
711
+ <field name="LOR">left</field>
712
+ <field name="POR">pressed</field>
713
+ </block>
714
+ </value>
715
+ <next>
716
+ <block type="ruby_p" inline="true">
717
+ <value name="ARG">
718
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
719
+ <field name="LOR">left</field>
720
+ <field name="POR">released</field>
721
+ </block>
722
+ </value>
723
+ <next>
724
+ <block type="ruby_p" inline="true">
725
+ <value name="ARG">
726
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
727
+ <field name="LOR">right</field>
728
+ <field name="POR">pressed</field>
729
+ </block>
730
+ </value>
731
+ <next>
732
+ <block type="ruby_p" inline="true">
733
+ <value name="ARG">
734
+ <block type="hardware_smalrubot_v3_touch_sensor_pressed_or_released">
735
+ <field name="LOR">right</field>
736
+ <field name="POR">released</field>
737
+ </block>
738
+ </value>
739
+ <next>
740
+ <block type="ruby_p" inline="true">
741
+ <value name="ARG">
742
+ <block type="hardware_smalrubot_v3_light_sensor_value" />
743
+ </value>
744
+ <next>
745
+ <block type="hardware_smalrubot_v3_led_turn_on_or_off" inline="true">
746
+ <field name="COLOUR">red</field>
747
+ <field name="OOO">turn_on</field>
748
+ <next>
749
+ <block type="hardware_smalrubot_v3_led_turn_on_or_off" inline="true">
750
+ <field name="COLOUR">green</field>
751
+ <field name="OOO">turn_off</field>
752
+ </block>
753
+ </next>
754
+ </block>
755
+ </next>
756
+ </block>
757
+ </next>
758
+ </block>
759
+ </next>
760
+ </block>
761
+ </next>
762
+ </block>
763
+ </next>
764
+ </block>
765
+ </next>
766
+ </block>
767
+ </next>
768
+ </block>
769
+ </next>
770
+ </block>
771
+ </next>
772
+ </block>
773
+ </next>
774
+ </block>
775
+ </next>
776
+ </block>
777
+ </next>
778
+ </block>
779
+ </next>
457
780
  </block>
458
781
  </next>
459
782
  </block>