Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app/assets/javascripts/blocks/sound.js.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,29 @@ Blockly.Blocks['<%= n %>'] =
Blockly.Ruby['<%= n %>'] = (block) ->
'stop\n'

# 変数:ボリューム
<% n = "#{category}_set_volume" %>
Blockly.Blocks['<%= n %>'] =
init: ()->
@setHelpUrl('')
@setColour(<%= color %>)
@interpolateMsg(<%= bm('.set_volume') %>,
['VOLUME', ['Number'], Blockly.ALIGN_RIGHT]
Blockly.ALIGN_RIGHT)
@setInputsInline(true)
@setPreviousStatement(true)
@setNextStatement(true)
@setTooltip('')

Blockly.Ruby['<%= n %>'] = (block) ->
volume = Blockly.Ruby.valueToCode(@, 'VOLUME', Blockly.Ruby.ORDER_NONE) || '100'
Blockly.Ruby.characterSetVariable_('volume', volume)

<% n = "#{category}_volume" %>
Blockly.Blocks['<%= n %>'] =
init: ()->
@setHelpUrl('')
@setColour(<%= color %>)
@appendDummyInput().appendField('ボリューム')
@appendDummyInput().appendField(<%= bm(".volume") %>)
@setOutput(true, 'Number')
@setTooltip('')

Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/msg/en_us.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ Blockly.Msg.BLOCKS_SOUND_PRESET_SOUNDS_PIANO_RA = 'A of piano';
Blockly.Msg.BLOCKS_SOUND_PRESET_SOUNDS_PIANO_SI = 'B of piano';
Blockly.Msg.BLOCKS_SOUND_PRESET_SOUNDS_PIANO_DO_2 = 'High C of piano';
Blockly.Msg.BLOCKS_SOUND_PLAY = 'play sound %1';
Blockly.Msg.BLOCKS_SOUND_SET_VOLUME = 'set volume to %1 %';
Blockly.Msg.BLOCKS_SOUND_VOLUME = 'volume';


// blocks/looks.js.coffee.erb
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/msg/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ Blockly.Msg.BLOCKS_SOUND_PRESET_SOUNDS_PIANO_RA = 'ピアノのラ';
Blockly.Msg.BLOCKS_SOUND_PRESET_SOUNDS_PIANO_SI = 'ピアノのシ';
Blockly.Msg.BLOCKS_SOUND_PRESET_SOUNDS_PIANO_DO_2 = 'ピアノの高いド';
Blockly.Msg.BLOCKS_SOUND_PLAY = '♪%1 の音を鳴らす';
Blockly.Msg.BLOCKS_SOUND_SET_VOLUME = '♪音量を %1 %にする';
Blockly.Msg.BLOCKS_SOUND_VOLUME = '♪音量';


// blocks/looks.js.coffee.erb
Expand Down
18 changes: 18 additions & 0 deletions app/models/concerns/ruby_to_block/block/sound_set_volume.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
module RubyToBlock
module Block
class SoundSetVolume < CharacterMethodCall
blocknize ['^\s*',
CHAR_RE,
'volume\s*=\s*(\S+)',
'\s*$'].join(''),
statement: true, inline: true

def self.process_match_data(md, context)
md2 = regexp.match(md[type])
add_character_method_call_block(context, md2[1], new, VOLUME: md2[2])
true
end
end
end
end
27 changes: 27 additions & 0 deletions app/models/concerns/ruby_to_block/block/sound_volume.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
module RubyToBlock
module Block
class SoundVolume < Value
include CharacterOperation

blocknize ['^\s*',
CHAR_RE,
'volume',
'\s*$'].join(''),
value: true

def self.process_match_data(md, context)
md2 = regexp.match(md[type])

character = get_character(context, md2[1])
return false if context.receiver != character

block = new
context.add_value(block)
block.character = character

true
end
end
end
end
6 changes: 4 additions & 2 deletions app/views/editor/_toolbox_default.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@
-# すべての音を止める
-#%block{:type => "#{category}_stop"}

-# 変数:ボリューム
-#%block{:type => "#{category}_volume"}
%block{:type => "#{category}_set_volume"}
= toolbox_number_value('VOLUME', 100)

%block{:type => "#{category}_volume"}

- category = 'pen'
%category{:name => tt('.pen')}
Expand Down
81 changes: 81 additions & 0 deletions spec/acceptance/block_mode/blocks/sound/set_volume.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# encoding: utf-8
# language: ja
@javascript
機能: sound_set_volume - 「音量を( )%にする」ブロック
シナリオ: ブロックのみ配置する
前提 "ブロック" タブを表示する

もし 次のブロックを配置する:
"""
%block{:type => "sound_set_volume", :x => "0", :y => "0"}
%value{:name => "VOLUME"}
%block{:type => "math_number"}
%field{:name => "NUM"}<
100
"""
かつ ブロックからソースコードを生成する

ならば テキストエディタのプログラムは "" であること

シナリオ: キャラクターとブロックを配置する
前提 "ブロック" タブを表示する
かつ 次のキャラクターを追加する:
| name | costumes | x | y | angle |
| car1 | car1.png | 0 | 0 | 0 |

もし 次のブロックを配置する:
"""
%block{:type => "character_new", :x => "21", :y => "15"}
%field{:name => "NAME"}<
car1
%statement{:name => "DO"}
%block{:type => "sound_set_volume", :x => "0", :y => "0"}
%value{:name => "VOLUME"}
%block{:type => "math_number"}
%field{:name => "NUM"}<
100
"""
かつ ブロックからソースコードを生成する

ならば テキストエディタのプログラムは以下であること:
"""
require "smalruby"

car1 = Character.new(costume: "costume1:car1.png", x: 0, y: 0, angle: 0)
car1.volume = 100

"""

シナリオ: キャラクターとイベントとブロックを配置する
前提 "ブロック" タブを表示する
かつ 次のキャラクターを追加する:
| name | costumes | x | y | angle |
| car1 | car1.png | 0 | 0 | 0 |

もし 次のブロックを配置する:
"""
%block{:type => "character_new", :x => "21", :y => "15"}
%field{:name => "NAME"}<
car1
%statement{:name => "DO"}
%block{:type => "events_on_start"}
%statement{:name => "DO"}
%block{:type => "sound_set_volume", :x => "0", :y => "0"}
%value{:name => "VOLUME"}
%block{:type => "math_number"}
%field{:name => "NUM"}<
100
"""
かつ ブロックからソースコードを生成する

ならば テキストエディタのプログラムは以下であること:
"""
require "smalruby"

car1 = Character.new(costume: "costume1:car1.png", x: 0, y: 0, angle: 0)

car1.on(:start) do
self.volume = 100
end

"""
31 changes: 31 additions & 0 deletions spec/acceptance/block_mode/blocks/sound/volume.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# encoding: utf-8
# language: ja
@javascript
機能: sound_volume - 「音量」ブロック
背景:
前提 "ブロック" タブを表示する

シナリオ: ブロックを配置する
もし 次のブロックを配置する:
"""
%block{:type => "sound_volume", :x => "0", :y => "0", :inline => "true"}
"""
かつ ブロックからソースコードを生成する

ならば テキストエディタのプログラムは以下を含むこと:
"""
volume
"""

もし 次のブロックを配置する:
"""
%block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true"}
%value{:name => "ARG"}
%block{:type => "sound_volume"}
"""
かつ ブロックからソースコードを生成する

ならば テキストエディタのプログラムは以下を含むこと:
"""
p(volume)
"""
46 changes: 42 additions & 4 deletions spec/models/concerns/ruby_to_block/block/sound_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
describe RubyToBlock::Block, '音ジャンル', to_blocks: true do
parts = <<-EOS
car1.on(:start) do
self.volume = 100
play(name: "piano_do.wav")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここに p(volume)を追加していただきたいです 🙇

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

追加しました 😄
🔚

p(volume)
end
car1.play(name: "piano_do.wav")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここに car1.volume = 100p(car1.volume) を追加していただきたいです 🙇

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

追加しました 😄
🔚

car1.volume = 100
p(car1.volume)
EOS
describe compact_source_code(parts), character_new_data: true do
_parts = parts
Expand All @@ -21,12 +25,28 @@
<statement name="DO">
<block type="events_on_start">
<statement name="DO">
<block type="sound_play" inline="true">
<value name="NAME">
<block type="sound_preset_sounds">
<field name="NAME">piano_do.wav</field>
<block type="sound_set_volume" inline="true">
<value name="VOLUME">
<block type="math_number">
<field name="NUM">100</field>
</block>
</value>
<next>
<block type="sound_play" inline="true">
<value name="NAME">
<block type="sound_preset_sounds">
<field name="NAME">piano_do.wav</field>
</block>
</value>
<next>
<block type="ruby_p" inline="true">
<value name="ARG">
<block type="sound_volume" />
</value>
</block>
</next>
</block>
</next>
</block>
</statement>
<next>
Expand All @@ -36,6 +56,24 @@
<field name="NAME">piano_do.wav</field>
</block>
</value>
<next>
<block type="sound_set_volume" inline="true">
<value name="VOLUME">
<block type="math_number">
<field name="NUM">100</field>
</block>
</value>
<next>
<block type="ruby_p" inline="true">
<value name="ARG">
<block type="ruby_expression">
<field name="EXP">car1.volume</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
Expand Down