Skip to content

Add broadcast block #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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: 6 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ GEM
database_rewinder (0.0.2)
diff-lcs (1.2.5)
docile (1.1.5)
dxruby (1.4.0)
dxruby_sdl (0.0.13)
rsdl
rubysdl (~> 2.1.3)
Expand All @@ -98,7 +97,6 @@ GEM
eventmachine (1.0.4)
execjs (2.0.2)
ffi (1.9.8)
ffi (1.9.8-x86-mingw32)
flatstrap-sass (2.3.1.0)
font-awesome-rails (~> 3.0.2.0)
sass (~> 3.2)
Expand All @@ -107,8 +105,6 @@ GEM
formatador (0.2.5)
gherkin (2.12.2)
multi_json (~> 1.3)
gherkin (2.12.2-x86-mingw32)
multi_json (~> 1.3)
guard (2.12.5)
formatador (>= 0.2.4)
listen (~> 2.7)
Expand Down Expand Up @@ -172,8 +168,6 @@ GEM
netrc (0.10.2)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
nokogiri (1.6.1-x86-mingw32)
mini_portile (~> 0.5.0)
notiffany (0.0.6)
nenv (~> 0.1)
shellany (~> 0.0)
Expand Down Expand Up @@ -279,11 +273,6 @@ GEM
dxruby_sdl (~> 0.0.13)
mime-types (~> 1.6)
smalrubot (~> 0.0.6)
smalruby (0.1.10-x86-mingw32)
activesupport
dxruby (= 1.4.0)
mime-types (~> 1.6)
smalrubot (~> 0.0.6)
spring (1.2.0)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
Expand All @@ -299,7 +288,6 @@ GEM
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.8)
sqlite3 (1.3.8-x86-mingw32)
teaspoon (0.7.9)
railties (>= 3.2.5, < 5)
term-ansicolor (1.3.0)
Expand Down Expand Up @@ -328,8 +316,6 @@ GEM
raindrops (~> 0.7)
websocket (1.0.7)
websocket-driver (0.3.2)
win32-process (0.7.4)
ffi (>= 1.0.0)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand Down Expand Up @@ -379,3 +365,9 @@ DEPENDENCIES
turnip
uglifier (>= 1.3.0)
unicorn

RUBY VERSION
ruby 2.1.5p273

BUNDLED WITH
1.12.0.pre.2
2 changes: 1 addition & 1 deletion app/assets/javascripts/blocks/control.js.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Blockly.Blocks['<%= n %>'] =
@setTooltip('')

Blockly.Ruby['<%= n %>'] = (block) ->
count = Blockly.Ruby.valueToCode(@, 'COUNT', Blockly.Ruby.ORDER_NONE) || 0
count = Blockly.Ruby.valueToCode(@, 'COUNT', Blockly.Ruby.ORDER_STRING_CONVERSION) || 0
branch = Blockly.Ruby.statementToCode(block, 'DO') || '\n'
"#{count}.times do\n" + branch + 'end\n'

Expand Down
56 changes: 56 additions & 0 deletions app/assets/javascripts/blocks/events.js.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,59 @@ Blockly.Blocks['<%= n %>'] =
Blockly.Ruby['<%= n %>'] = (block) ->
char = @getCharacterFieldValue()
Blockly.Ruby.characterEvent_(block, 'DO', 'hit', char)

# [▼メッセージ]
<% n = "#{category}_messages" %>
Blockly.Blocks['<%= n %>'] =
init: ()->
messages = [
[<%= bm('.messages1') %>, 'messages1'],
[<%= bm('.messages2') %>, 'messages2'],
]
@setHelpUrl('')
@setColour(<%= color %>)
@interpolateMsg(<%= bm('.messages') %>,
['NAME', new Blockly.FieldDropdown(messages)],
Blockly.ALIGN_RIGHT)
@setOutput(true, 'String')
@setTooltip('')

Blockly.Ruby['<%= n %>'] = (block) ->
code = Blockly.Ruby.quote_(@getFieldValue('NAME'))
[code, Blockly.Ruby.ORDER_ATOMIC]

# [▼メッセージ]を受け取ったとき
<% n = '#{category}_when_i_receive' %>
Blockly.Blocks['<%= n %>'] =
init: ()->
@setHelpUrl('')
@setColour(<%= color %>)
@interpolateMsg(<%= bm('.when_i_receive') %>,
['TEXT', null, Blockly.ALIGN_RIGHT],
Blockly.ALIGN_RIGHT)
@appendStatementInput('DO')
@setPreviousStatement(true)
@setNextStatement(true)
@setTooltip('')

Blockly.Ruby['<%= n %>'] = (block) ->
arg = Blockly.Ruby.valueToCode(@, 'TEXT', Blockly.Ruby.ORDER_NONE) || ''
Blockly.Ruby.characterEvent_(block, 'DO', 'receive', arg)

# [▼メッセージ]を送る
<% n = '#{category}_broadcast' %>
Blockly.Blocks['<%= n %>'] =
init: ()->
@setHelpUrl('')
@setColour(<%= color %>)
@interpolateMsg(<%= bm('.broadcast') %>,
['TEXT', null, Blockly.ALIGN_RIGHT],
Blockly.ALIGN_RIGHT)
@setInputsInline(true)
@setPreviousStatement(true)
@setNextStatement(true)
@setTooltip('')

Blockly.Ruby['<%= n %>'] = (block) ->
arg = Blockly.Ruby.valueToCode(@, 'TEXT', Blockly.Ruby.ORDER_NONE) || ''
Blockly.Ruby.characterMethodCall_('broadcast', arg)
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
8 changes: 8 additions & 0 deletions app/assets/javascripts/msg/en_us.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ Blockly.Msg.BLOCKS_EVENTS_ON_START = 'when Run clicked';
Blockly.Msg.BLOCKS_EVENTS_ON_KEY_PUSH_OR_DOWN = 'when %1 key %2';
Blockly.Msg.BLOCKS_EVENTS_ON_CLICK = 'when this sprite clicked';
Blockly.Msg.BLOCKS_EVENTS_ON_HIT = 'when %1 hit';
Blockly.Msg.BLOCKS_EVENTS_MESSAGES = '%1';
Blockly.Msg.BLOCKS_EVENTS_MESSAGES1 = 'message1';
Blockly.Msg.BLOCKS_EVENTS_MESSAGES2 = 'message2';
Blockly.Msg.BLOCKS_EVENTS_WHEN_I_RECEIVE = 'when I receive %1';
Blockly.Msg.BLOCKS_EVENTS_BROADCAST = 'broadcast %1';
// Blockly.Msg.BLOCKS_EVENTS_BROADCAST_AND_WAIT = 'broadcast %1 and wait';


// blocks/sensing.js.coffee.erb
Expand Down Expand Up @@ -205,6 +211,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
10 changes: 9 additions & 1 deletion app/assets/javascripts/msg/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ Blockly.Msg.BLOCKS_MOTION_SELF_ANGLE = '■向き';

// blocks/events.js.coffee.erb
Blockly.Msg.BLOCKS_EVENTS_ON_START = '♣実行ボタンがクリックされたとき';
Blockly.Msg.BLOCKS_EVENTS_ON_KEY_PUSH_OR_DOWN = '♣キーボードの %1 が %2 のとき';
Blockly.Msg.BLOCKS_EVENTS_ON_KEY_PUSH_OR_DOWN = '♣キーボードの %1 が %2 とき';
Blockly.Msg.BLOCKS_EVENTS_ON_CLICK = '♣キャラクターがクリックされたとき';
Blockly.Msg.BLOCKS_EVENTS_ON_HIT = '♣%1 にぶつかったとき';
Blockly.Msg.BLOCKS_EVENTS_MESSAGES = '%1';
Blockly.Msg.BLOCKS_EVENTS_MESSAGES1 = 'メッセージ1';
Blockly.Msg.BLOCKS_EVENTS_MESSAGES2 = 'メッセージ2'
Blockly.Msg.BLOCKS_EVENTS_WHEN_I_RECEIVE = '♣%1 を受け取ったとき';
Blockly.Msg.BLOCKS_EVENTS_BROADCAST = '♣%1 を送る';
// Blockly.Msg.BLOCKS_EVENTS_BROADCAST_AND_WAIT = '♣%1 を送って、待つ';


// blocks/sensing.js.coffee.erb
Expand Down Expand Up @@ -209,6 +215,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
20 changes: 20 additions & 0 deletions app/models/concerns/ruby_to_block/block/control_times.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module RubyToBlock
module Block
class ControlTimes < Base
blocknize '^\s*(.+)\.times\s+do\s*$', statement: true, indent: true

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

do_block = Block.new('null')
block = new(statements: { DO: do_block })
process_value_string(context, block, md2[1], :COUNT)
context.statement_stack.push([type, block])
context.current_block.sibling = block
context.current_block = do_block
true
end
end
end
end
18 changes: 18 additions & 0 deletions app/models/concerns/ruby_to_block/block/events_broadcast.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
module RubyToBlock
module Block
class EventBroadcast < CharacterEvent
blocknize ['^\s*',
CHAR_RE,
'broadcast\(\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, MESSAGE: md2[2])
true
end
end
end
end
18 changes: 18 additions & 0 deletions app/models/concerns/ruby_to_block/block/events_when_i_receive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
module RubyToBlock
module Block
class EventBroadcast < CharacterEvent
blocknize ['^\s*',
CHAR_RE,
'on\(:receive,\s*("[^"),]*")\)\s+do',
'\s*$'].join(''),
statement: true, indent: true

def self.process_match_data(md, context)
md2 = regexp.match(md[type])
add_character_event_blocks(context, md2[1], new, MESSAGE: md2[2])
true
end
end
end
end
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
19 changes: 17 additions & 2 deletions app/views/editor/_toolbox_default.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@

- category = 'sound'
%category{:name => tt('.sound')}

-# [▼プリセット音声]の音を鳴らす
%block{:type => "#{category}_play"}
%value{:name => 'NAME'}
Expand All @@ -272,8 +273,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 Expand Up @@ -304,6 +307,18 @@
-# [▼キャラクター]にぶつかったとき
%block{:type => "#{category}_on_hit"}

-# [▼メッセージ]を受け取ったとき
%block{:type => '#{category}_when_i_receive'}
= toolbox_text_value('TEXT', tt('.text'))

-# [▼メッセージ]を送る
%block{:type => '#{category}_broadcast'}
= toolbox_text_value('TEXT', tt('.text'))

-# [▼メッセージ]を送って、待つ
-#%block{:type => '#{category}_broadcast_and_wait'}
-# = toolbox_text_value('TEXT', tt('.message'))

- category = 'control'
%category{:name => tt('.control')}
-# ( )秒待つ
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ en:
hello: "Hello!"
world: "world"
text: "text"
message: "message"

character_modal:
name: "Name"
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ja:
hello: "こんにちは!"
world: "あいうえお"
text: "文章"
message: "メッセージ"

character_modal:
name: "名前"
Expand Down
Loading