smalruby-editor 0.1.1-x86-mingw32 → 0.1.2-x86-mingw32
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.
- checksums.yaml +4 -4
- data/app/assets/demos/default.xml +1 -1
- data/app/assets/javascripts/application.js +1 -0
- data/app/assets/javascripts/blocks/blockly.js.coffee.erb +1 -1
- data/app/assets/javascripts/blocks/events.js.coffee.erb +2 -3
- data/app/assets/javascripts/blocks/field_character.js.coffee.erb +108 -0
- data/app/assets/javascripts/blocks/hardware.js.coffee.erb +35 -2
- data/app/assets/javascripts/blocks/motion.js.coffee.erb +4 -4
- data/app/assets/javascripts/blocks/operators.js.coffee.erb +27 -29
- data/app/assets/javascripts/blocks/sensing.js.coffee.erb +4 -6
- data/app/assets/javascripts/generators/ruby.js.coffee.erb +21 -19
- data/app/assets/javascripts/models/character.js.coffee +21 -0
- data/app/assets/javascripts/views/character_modal_view.js.coffee +24 -3
- data/app/views/editor/_character_modal.html.haml +1 -1
- data/app/views/editor/_toolbox.html.haml +7 -3
- data/lib/smalruby_editor/version.rb +1 -1
- data/public/assets/{application-0c2ae32cd8822cec7ba6e445e2501010.js → application-735e172a0df828da16d22f5d3c26671f.js} +294 -59
- data/public/assets/{application-0c2ae32cd8822cec7ba6e445e2501010.js.gz → application-735e172a0df828da16d22f5d3c26671f.js.gz} +0 -0
- data/public/assets/{default-7f438ebd7f8ab6ef65c5b9744786e57f.xml → default-5d1886100d7c8961e9962bbc4bb0c714.xml} +1 -1
- data/public/assets/manifest-1f254fa92a71ba4faad0f99136daeed8.json +1 -1
- data/spec/acceptance/block_mode/blocks/hardware/servo_set_position.feature +104 -0
- data/spec/acceptance/block_mode/blocks/operators/and_or.feature +61 -0
- data/spec/acceptance/block_mode/blocks/operators/four_arithmetic_and_compares.feature +85 -0
- data/spec/acceptance/block_mode/blocks/operators/index_of.feature +60 -0
- data/spec/acceptance/block_mode/blocks/operators/length.feature +52 -0
- data/spec/acceptance/block_mode/blocks/operators/math_method.feature +109 -0
- data/spec/acceptance/block_mode/blocks/operators/negate.feature +47 -0
- data/spec/acceptance/block_mode/blocks/operators/rand.feature +60 -0
- data/spec/acceptance/block_mode/blocks/operators/round.feature +52 -0
- data/spec/acceptance/block_mode/blocks/operators/true_false.feature +36 -0
- data/spec/acceptance/block_mode/blocks/ruby/expression.feature +36 -0
- data/spec/acceptance/block_mode/blocks/ruby/p.feature +34 -0
- data/spec/acceptance/block_mode/blocks/ruby/statement_comment.feature +25 -0
- data/spec/javascripts/models/character_spec.coffee +44 -5
- data/spec/steps/ace_steps.rb +9 -0
- data/spec/steps/block_mode_steps.rb +14 -0
- data/spec/steps/fix_turnip.rb +35 -0
- data/spec/steps/text_editor_steps.rb +1 -0
- data/spec/teaspoon_env.rb +1 -1
- data/spec/turnip_helper.rb +1 -0
- metadata +34 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96882af4698c86e6f93655993010b2e4c3fb7bdd
|
4
|
+
data.tar.gz: 744c0843a58a6ee7a8c2831d69ee6ad81278c86f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 831ca11f66993f73f36ee423244eb39ad0e2ff7e983ea021c317e0899e8bff26d71c59ffffe98a7cb72a02dfd462d525a142d81864aa7d51fe05fbc853e3f103
|
7
|
+
data.tar.gz: b26681dd47e00bef42f77433fc2cdbf615421187435e7f3530176888815b936b74740fd2b72219c3c7ce905b936cd4a5a2a4ab3c88d9d4b57e2cb7dcd525b835
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<% n = "#{category}_number" %>
|
6
6
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
7
7
|
code = parseFloat(@getFieldValue('NUM'))
|
8
|
-
order = if code < 0 then Blockly.Ruby.
|
8
|
+
order = if code < 0 then Blockly.Ruby.ORDER_UNARY_MINUS_SIGN else Blockly.Ruby.ORDER_ATOMIC
|
9
9
|
[code, order]
|
10
10
|
|
11
11
|
|
@@ -69,7 +69,7 @@ Blockly.Blocks['<%= n %>'] =
|
|
69
69
|
@setHelpUrl('')
|
70
70
|
@setColour(<%= color %>)
|
71
71
|
@appendDummyInput()
|
72
|
-
.appendField(new
|
72
|
+
.appendField(new Smalruby.FieldCharacter(), 'CHAR') # TODO
|
73
73
|
.appendField('にぶつかったとき')
|
74
74
|
@appendStatementInput('DO')
|
75
75
|
@setPreviousStatement(true)
|
@@ -77,6 +77,5 @@ Blockly.Blocks['<%= n %>'] =
|
|
77
77
|
@setTooltip('')
|
78
78
|
|
79
79
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
80
|
-
char =
|
81
|
-
.getName(block.getFieldValue('CHAR'), Blockly.Variables.NAME_TYPE)
|
80
|
+
char = @getFieldValue('CHAR')
|
82
81
|
Blockly.Ruby.characterEvent_(block, 'DO', 'hit', char)
|
@@ -0,0 +1,108 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
goog.provide('Smalruby.FieldCharacter')
|
4
|
+
|
5
|
+
goog.require('Blockly.FieldDropdown')
|
6
|
+
|
7
|
+
|
8
|
+
Smalruby.FieldCharacter = (character, opt_changeHandler) ->
|
9
|
+
if opt_changeHandler
|
10
|
+
changeHandler = (value) =>
|
11
|
+
retVal = Smalruby.FieldCharacter.dropdownChange.call(@, value)
|
12
|
+
if retVal
|
13
|
+
newVal = retVal
|
14
|
+
else
|
15
|
+
retVal = @getValue()
|
16
|
+
opt_changeHandler.call(@, newVal)
|
17
|
+
retVal
|
18
|
+
else
|
19
|
+
changeHandler = Smalruby.FieldCharacter.dropdownChange
|
20
|
+
|
21
|
+
Smalruby.FieldCharacter.superClass_.constructor
|
22
|
+
.call(@, Smalruby.FieldCharacter.dropdownCreate, changeHandler)
|
23
|
+
|
24
|
+
charSet = Smalruby.Collections.CharacterSet
|
25
|
+
charSet.on('add', @onCharacterSetAdd_, @)
|
26
|
+
charSet.on('remove', @onCharacterSetRemove_, @)
|
27
|
+
charSet.on('reset', @onCharacterSetReset_, @)
|
28
|
+
|
29
|
+
@character = Smalruby.FieldCharacter.NullCharacter
|
30
|
+
|
31
|
+
unless character
|
32
|
+
character = Smalruby.Collections.CharacterSet.first()
|
33
|
+
@setCharacter(character)
|
34
|
+
|
35
|
+
goog.inherits(Smalruby.FieldCharacter, Blockly.FieldDropdown)
|
36
|
+
|
37
|
+
Smalruby.FieldCharacter.prototype.setCharacter = (character) ->
|
38
|
+
return if character == @character
|
39
|
+
|
40
|
+
@character.unlink(@)
|
41
|
+
@character.off('change:name', @onCharacterChangeName_, @)
|
42
|
+
@character = if character then character else Smalruby.FieldCharacter.NullCharacter
|
43
|
+
@character.link(@)
|
44
|
+
@character.on('change:name', @onCharacterChangeName_, @)
|
45
|
+
|
46
|
+
@setValue(@character.get('name'))
|
47
|
+
|
48
|
+
Smalruby.FieldCharacter.prototype.onCharacterSetAdd_ = (model, collection, options) ->
|
49
|
+
if @character == Smalruby.FieldCharacter.NullCharacter
|
50
|
+
@setCharacter(model)
|
51
|
+
|
52
|
+
Smalruby.FieldCharacter.prototype.onCharacterSetRemove_ = (model, collection, options) ->
|
53
|
+
if model == @character
|
54
|
+
@setCharacter()
|
55
|
+
|
56
|
+
Smalruby.FieldCharacter.prototype.onCharacterSetReset_ = (collection, options) ->
|
57
|
+
if @character == Smalruby.FieldCharacter.NullCharacter
|
58
|
+
@setCharacter(collection.first())
|
59
|
+
else
|
60
|
+
@setCharacter(collection.findWhere({ name: @getValue() }))
|
61
|
+
|
62
|
+
Smalruby.FieldCharacter.prototype.onCharacterChangeName_ = (model, value, options) ->
|
63
|
+
@setValue(value)
|
64
|
+
|
65
|
+
Smalruby.FieldCharacter.prototype.clone = ->
|
66
|
+
new Smalruby.FieldCharacter(@character, @changeHandler_)
|
67
|
+
|
68
|
+
Smalruby.FieldCharacter.prototype.dispose = ->
|
69
|
+
charSet = Smalruby.Collections.CharacterSet
|
70
|
+
charSet.off('add', @onCharacterSetAdd_, @)
|
71
|
+
charSet.off('remove', @onCharacterSetRemove_, @)
|
72
|
+
charSet.off('reset', @onCharacterSetReset_, @)
|
73
|
+
@setCharacter()
|
74
|
+
|
75
|
+
Blockly.FieldDropdown.prototype.dispose.call(@)
|
76
|
+
|
77
|
+
Smalruby.FieldCharacter.prototype.setText = (value) ->
|
78
|
+
# HACK: XMLをロードしたときにキャラクターとリンクさせる
|
79
|
+
unless @character
|
80
|
+
@character = Smalruby.FieldCharacter.NullCharacter
|
81
|
+
charSet = Smalruby.Collections.CharacterSet
|
82
|
+
@setCharacter(charSet.findWhere({ name: value }))
|
83
|
+
Blockly.FieldDropdown.prototype.setText.call(@, value)
|
84
|
+
|
85
|
+
Smalruby.FieldCharacter.dropdownCreate = ->
|
86
|
+
charSet = Smalruby.Collections.CharacterSet
|
87
|
+
if charSet.length > 0
|
88
|
+
Smalruby.Collections.CharacterSet.map (c) ->
|
89
|
+
n = c.get('name')
|
90
|
+
[n, n]
|
91
|
+
else
|
92
|
+
[[Smalruby.FieldCharacter.NullCharacter.get('name'), '']]
|
93
|
+
|
94
|
+
Smalruby.FieldCharacter.dropdownChange = (value) ->
|
95
|
+
c = Smalruby.Collections.CharacterSet.findWhere({ name: value })
|
96
|
+
if c
|
97
|
+
@setCharacter(c)
|
98
|
+
value
|
99
|
+
else
|
100
|
+
null
|
101
|
+
|
102
|
+
Smalruby.FieldCharacter.NullCharacter =
|
103
|
+
get: (name) ->
|
104
|
+
'キャラクターなし'
|
105
|
+
on: -> $.noop
|
106
|
+
off: -> $.noop
|
107
|
+
link: -> $.noop
|
108
|
+
unlink: -> $.noop
|
@@ -9,12 +9,16 @@
|
|
9
9
|
window.SmalrubyEditor.Hardware =
|
10
10
|
Type: 'Arduino' # 種別
|
11
11
|
DioPins: [2..13] # デジタルIOピン
|
12
|
+
PwmPins: [3, 5, 6, 9, 10, 11] # デジタルIOピンのうちPWMに対応しているピン
|
12
13
|
AiPins: [0..5] # アナログ入力ピン
|
13
14
|
|
14
15
|
dioPinDropdown =
|
15
16
|
(["D#{n}", "D#{n}"] for n in window.SmalrubyEditor.Hardware.DioPins)
|
16
17
|
|
17
18
|
pwmPinDropdown =
|
19
|
+
(["D#{n}", "D#{n}"] for n in window.SmalrubyEditor.Hardware.PwmPins)
|
20
|
+
|
21
|
+
rgbLedPinDropdown =
|
18
22
|
(["D#{n}", "D#{n}"] for n in [3, 9])
|
19
23
|
|
20
24
|
aiPinDropdown =
|
@@ -81,7 +85,7 @@ Blockly.Blocks['<%= n %>'] =
|
|
81
85
|
.appendField('RGB LED')
|
82
86
|
.appendField(new Blockly.FieldDropdown(acDropdown), 'AC')
|
83
87
|
.appendField('コモン')
|
84
|
-
.appendField(new Blockly.FieldDropdown(
|
88
|
+
.appendField(new Blockly.FieldDropdown(rgbLedPinDropdown), 'PIN')
|
85
89
|
.appendField('を')
|
86
90
|
.appendField(new Blockly.FieldColour('#ff0000'), 'COLOUR')
|
87
91
|
.appendField('にする')
|
@@ -109,7 +113,7 @@ Blockly.Blocks['<%= n %>'] =
|
|
109
113
|
.appendField('RGB LED')
|
110
114
|
.appendField(new Blockly.FieldDropdown(acDropdown), 'AC')
|
111
115
|
.appendField('コモン')
|
112
|
-
.appendField(new Blockly.FieldDropdown(
|
116
|
+
.appendField(new Blockly.FieldDropdown(rgbLedPinDropdown), 'PIN')
|
113
117
|
.appendField('をオフにする')
|
114
118
|
@setPreviousStatement(true)
|
115
119
|
@setNextStatement(true)
|
@@ -209,6 +213,35 @@ Blockly.Blocks['<%= n %>'] =
|
|
209
213
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
210
214
|
"seven_segment_display.off\n"
|
211
215
|
|
216
|
+
# 「サーボ」サブジャンル
|
217
|
+
|
218
|
+
# 「サーボ[▼ピン]を( )度(5~180)にする」ブロック
|
219
|
+
<% n = "#{category}_servo_set_position" %>
|
220
|
+
Blockly.Blocks['<%= n %>'] =
|
221
|
+
init: ()->
|
222
|
+
@setHelpUrl('')
|
223
|
+
@setColour(<%= color %>)
|
224
|
+
@appendDummyInput()
|
225
|
+
.appendField('サーボ')
|
226
|
+
.appendField(new Blockly.FieldDropdown(pwmPinDropdown), 'PIN')
|
227
|
+
.appendField('を')
|
228
|
+
@appendValueInput('POS')
|
229
|
+
.setCheck('Number')
|
230
|
+
@appendDummyInput()
|
231
|
+
.appendField('度(5~180)にする')
|
232
|
+
@setInputsInline(true)
|
233
|
+
@setPreviousStatement(true)
|
234
|
+
@setNextStatement(true)
|
235
|
+
@setTooltip('')
|
236
|
+
|
237
|
+
Blockly.Ruby['<%= n %>'] = (block) ->
|
238
|
+
pin = @getFieldValue('PIN') #p sensor("A0").value
|
239
|
+
#p sensor("A0").value.class
|
240
|
+
#p(sensor("A0").value / 6)
|
241
|
+
|
242
|
+
pos = Blockly.Ruby.valueToCode(@, 'POS', Blockly.Ruby.ORDER_FUNCTION_CALL) || '5'
|
243
|
+
Blockly.Ruby.characterMethodCall_("servo(#{Blockly.Ruby.quote_(pin)}).position = #{pos}")
|
244
|
+
|
212
245
|
# 「ボタン」サブジャンル
|
213
246
|
|
214
247
|
# 条件:ボタン[▼]を押している
|
@@ -90,14 +90,14 @@ Blockly.Blocks['<%= n %>'] =
|
|
90
90
|
@setHelpUrl('')
|
91
91
|
@setColour(<%= color %>)
|
92
92
|
@appendDummyInput()
|
93
|
-
.appendField(new
|
93
|
+
.appendField(new Smalruby.FieldCharacter(), 'CHAR')
|
94
94
|
.appendField('へ向ける')
|
95
95
|
@setPreviousStatement(true)
|
96
96
|
@setNextStatement(true)
|
97
97
|
@setTooltip('')
|
98
98
|
|
99
99
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
100
|
-
char =
|
100
|
+
char = @getFieldValue('CHAR')
|
101
101
|
Blockly.Ruby.characterMethodCall_('point_towards', char)
|
102
102
|
|
103
103
|
# x座標を( )、y座標を( )にする
|
@@ -144,14 +144,14 @@ Blockly.Blocks['<%= n %>'] =
|
|
144
144
|
@setHelpUrl('')
|
145
145
|
@setColour(<%= color %>)
|
146
146
|
@appendDummyInput()
|
147
|
-
.appendField(new
|
147
|
+
.appendField(new Smalruby.FieldCharacter(), 'CHAR')
|
148
148
|
.appendField('へ行く')
|
149
149
|
@setPreviousStatement(true)
|
150
150
|
@setNextStatement(true)
|
151
151
|
@setTooltip('')
|
152
152
|
|
153
153
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
154
|
-
|
154
|
+
char = @getFieldValue('CHAR')
|
155
155
|
"#{Blockly.Ruby.rn()}go_to(#{var0})\n"
|
156
156
|
|
157
157
|
# ( )秒でx座標を( )、y座標を( )に変える
|
@@ -11,11 +11,11 @@
|
|
11
11
|
# 変数:( ) / ( )
|
12
12
|
<%
|
13
13
|
[
|
14
|
-
['add', '+', 'ADDITIVE', '+'],
|
15
|
-
['minus', 'ー', 'ADDITIVE', '-'],
|
16
|
-
['multiply', '×', 'MULTIPLICATIVE', '*'],
|
17
|
-
['divide', '÷', 'MULTIPLICATIVE', '/'],
|
18
|
-
].each do |suffix, operator_label, order_suffix, operator|
|
14
|
+
['add', '+', 'ADDITIVE', '+', '0', '0'],
|
15
|
+
['minus', 'ー', 'ADDITIVE', '-', '0', '0'],
|
16
|
+
['multiply', '×', 'MULTIPLICATIVE', '*', '0', '0'],
|
17
|
+
['divide', '÷', 'MULTIPLICATIVE', '/', '0', '1'],
|
18
|
+
].each do |suffix, operator_label, order_suffix, operator, default_a, default_b|
|
19
19
|
n = "#{category}_#{suffix}"
|
20
20
|
%>
|
21
21
|
|
@@ -24,8 +24,8 @@ Blockly.Blocks['<%= n %>'] =
|
|
24
24
|
@setHelpUrl('')
|
25
25
|
@setColour(<%= color %>)
|
26
26
|
@interpolateMsg('%1<%= operator_label %>%2',
|
27
|
-
|
28
|
-
|
27
|
+
['A', null, Blockly.ALIGN_RIGHT],
|
28
|
+
['B', null, Blockly.ALIGN_RIGHT],
|
29
29
|
Blockly.ALIGN_RIGHT)
|
30
30
|
@setInputsInline(true)
|
31
31
|
@setOutput(true, null)
|
@@ -33,8 +33,8 @@ Blockly.Blocks['<%= n %>'] =
|
|
33
33
|
|
34
34
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
35
35
|
order = Blockly.Ruby.ORDER_<%= order_suffix %>
|
36
|
-
a = Blockly.Ruby.valueToCode(block, 'A', order) || '
|
37
|
-
b = Blockly.Ruby.valueToCode(block, 'B', order) || '
|
36
|
+
a = Blockly.Ruby.valueToCode(block, 'A', order) || '<%= default_a %>'
|
37
|
+
b = Blockly.Ruby.valueToCode(block, 'B', order) || '<%= default_b %>'
|
38
38
|
[a + ' <%= operator %> ' + b, order]
|
39
39
|
<% end %>
|
40
40
|
|
@@ -45,12 +45,12 @@ Blockly.Ruby['<%= n %>'] = (block) ->
|
|
45
45
|
# 条件:( ) > ( )
|
46
46
|
<%
|
47
47
|
[
|
48
|
-
['
|
49
|
-
['
|
50
|
-
['compare_eq', '=', '=='],
|
51
|
-
['
|
52
|
-
['
|
53
|
-
].each do |suffix, operator_label, operator|
|
48
|
+
['compare_lt', '<', '<', 'RELATIONAL'],
|
49
|
+
['compare_lte', '≦', '<=', 'RELATIONAL'],
|
50
|
+
['compare_eq', '=', '==', 'EQUALS'],
|
51
|
+
['compare_gte', '≧', '>=', 'RELATIONAL'],
|
52
|
+
['compare_gt', '>', '>', 'RELATIONAL'],
|
53
|
+
].each do |suffix, operator_label, operator, order_suffix|
|
54
54
|
n = "#{category}_#{suffix}"
|
55
55
|
%>
|
56
56
|
|
@@ -67,7 +67,7 @@ Blockly.Blocks['<%= n %>'] =
|
|
67
67
|
@setTooltip('')
|
68
68
|
|
69
69
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
70
|
-
order = Blockly.Ruby.
|
70
|
+
order = Blockly.Ruby.ORDER_<%= order_suffix %>;
|
71
71
|
a = Blockly.Ruby.valueToCode(block, 'A', order) || '0'
|
72
72
|
b = Blockly.Ruby.valueToCode(block, 'B', order) || '0'
|
73
73
|
[a + ' <%= operator %> ' + b, order]
|
@@ -88,10 +88,9 @@ Blockly.Blocks['<%= n %>'] =
|
|
88
88
|
@setTooltip('')
|
89
89
|
|
90
90
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
91
|
-
|
92
|
-
|
93
|
-
b
|
94
|
-
["rand(#{a}..#{b})", order]
|
91
|
+
a = Blockly.Ruby.valueToCode(block, 'A', Blockly.Ruby.ORDER_RANGE) || '0'
|
92
|
+
b = Blockly.Ruby.valueToCode(block, 'B', Blockly.Ruby.ORDER_RANGE) || '0'
|
93
|
+
["rand(#{a}..#{b})", Blockly.Ruby.ORDER_FUNCTION_CALL]
|
95
94
|
|
96
95
|
# 条件:< > かつ < >
|
97
96
|
# 条件:< > または < >
|
@@ -136,11 +135,11 @@ Blockly.Blocks['<%= n %>'] =
|
|
136
135
|
@setTooltip('')
|
137
136
|
|
138
137
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
139
|
-
order = Blockly.Ruby.
|
138
|
+
order = Blockly.Ruby.ORDER_UNARY_SIGN
|
140
139
|
a = Blockly.Ruby.valueToCode(block, 'A', order) || 'true'
|
141
140
|
["!#{a}", order]
|
142
141
|
|
143
|
-
# 変数:( )の
|
142
|
+
# 変数:( )の( )番目
|
144
143
|
<% n = "#{category}_index_of" %>
|
145
144
|
Blockly.Blocks['<%= n %>'] =
|
146
145
|
init: ()->
|
@@ -155,12 +154,11 @@ Blockly.Blocks['<%= n %>'] =
|
|
155
154
|
@setTooltip('')
|
156
155
|
|
157
156
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
158
|
-
|
159
|
-
|
160
|
-
index
|
161
|
-
["#{a}[#{index}]", order]
|
157
|
+
a = Blockly.Ruby.valueToCode(block, 'A', Blockly.Ruby.ORDER_FUNCTION_CALL) || '""'
|
158
|
+
index = Blockly.Ruby.valueToCode(block, 'INDEX', Blockly.Ruby.ORDER_INDEX) || '0'
|
159
|
+
["#{a}[#{index}]", Blockly.Ruby.ORDER_FUNCTION_CALL]
|
162
160
|
|
163
|
-
# 変数:
|
161
|
+
# 変数:( )の長さ
|
164
162
|
<% n = "#{category}_length" %>
|
165
163
|
Blockly.Blocks['<%= n %>'] =
|
166
164
|
init: ()->
|
@@ -194,8 +192,8 @@ Blockly.Blocks['<%= n %>'] =
|
|
194
192
|
|
195
193
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
196
194
|
order = Blockly.Ruby.ORDER_MULTIPLICATIVE
|
197
|
-
a = Blockly.Ruby.valueToCode(block, 'A', order) || '
|
198
|
-
b = Blockly.Ruby.valueToCode(block, 'B', order) || '
|
195
|
+
a = Blockly.Ruby.valueToCode(block, 'A', order) || '1'
|
196
|
+
b = Blockly.Ruby.valueToCode(block, 'B', order) || '1'
|
199
197
|
["#{a} % #{b}", order]
|
200
198
|
|
201
199
|
# 変数:( )を丸める
|
@@ -98,14 +98,13 @@ Blockly.Blocks['<%= n %>'] =
|
|
98
98
|
@setHelpUrl('')
|
99
99
|
@setColour(<%= color %>)
|
100
100
|
@appendDummyInput()
|
101
|
-
.appendField(new
|
101
|
+
.appendField(new Smalruby.FieldCharacter(), 'CHAR')
|
102
102
|
.appendField('に触れた')
|
103
103
|
@setOutput(true, 'Boolean')
|
104
104
|
@setTooltip('')
|
105
105
|
|
106
106
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
107
|
-
char =
|
108
|
-
.getName(block.getFieldValue('CHAR'), Blockly.Variables.NAME_TYPE)
|
107
|
+
char = @getFieldValue('CHAR')
|
109
108
|
Blockly.Ruby.characterMethodCallInput_('hit?', char)
|
110
109
|
|
111
110
|
# [ ]と聞いて待つ
|
@@ -186,15 +185,14 @@ Blockly.Blocks['<%= n %>'] =
|
|
186
185
|
@setHelpUrl('')
|
187
186
|
@setColour(<%= color %>)
|
188
187
|
@appendDummyInput()
|
189
|
-
.appendField(new
|
188
|
+
.appendField(new Smalruby.FieldCharacter(), 'CHAR')
|
190
189
|
.appendField('の')
|
191
190
|
.appendField(new Blockly.FieldDropdown(dropdown), 'PROPERTY')
|
192
191
|
@setOutput(true, ['Number', 'String'])
|
193
192
|
@setTooltip('')
|
194
193
|
|
195
194
|
Blockly.Ruby['<%= n %>'] = (block) ->
|
196
|
-
char =
|
197
|
-
.getName(block.getFieldValue('CHAR'), Blockly.Variables.NAME_TYPE)
|
195
|
+
char = @getFieldValue('CHAR')
|
198
196
|
property = @getFieldValue('PROPERTY')
|
199
197
|
c = Smalruby.Collections.CharacterSet.findWhere({ name: char })
|
200
198
|
Blockly.Ruby.characterMethodCallInput_(property, null, { object: c })
|
@@ -10,28 +10,30 @@ break elsif module retry unless __ENCODING__
|
|
10
10
|
case end next return until
|
11
11
|
'.split(/\s+/)
|
12
12
|
|
13
|
-
# TODO: 確認すること
|
14
13
|
Blockly.Ruby.ORDER_ATOMIC = 0 # 0 "" ...
|
15
14
|
Blockly.Ruby.ORDER_COLLECTION = 1 # tuples, lists, dictionaries
|
16
15
|
Blockly.Ruby.ORDER_STRING_CONVERSION = 1 # `expression...`
|
17
|
-
Blockly.Ruby.ORDER_MEMBER = 2
|
18
|
-
Blockly.Ruby.
|
19
|
-
Blockly.Ruby.
|
20
|
-
Blockly.Ruby.ORDER_UNARY_SIGN =
|
21
|
-
Blockly.Ruby.
|
22
|
-
Blockly.Ruby.
|
23
|
-
Blockly.Ruby.
|
24
|
-
Blockly.Ruby.
|
25
|
-
Blockly.Ruby.
|
26
|
-
Blockly.Ruby.
|
27
|
-
Blockly.Ruby.
|
28
|
-
Blockly.Ruby.
|
29
|
-
|
30
|
-
Blockly.Ruby.
|
31
|
-
Blockly.Ruby.ORDER_LOGICAL_AND =
|
32
|
-
Blockly.Ruby.ORDER_LOGICAL_OR =
|
33
|
-
Blockly.Ruby.
|
34
|
-
Blockly.Ruby.
|
16
|
+
Blockly.Ruby.ORDER_MEMBER = 2 # ::
|
17
|
+
Blockly.Ruby.ORDER_INDEX = 3 # []
|
18
|
+
Blockly.Ruby.ORDER_FUNCTION_CALL = 4 # ()
|
19
|
+
Blockly.Ruby.ORDER_UNARY_SIGN = 5 # +(単項) ! ~
|
20
|
+
Blockly.Ruby.ORDER_EXPONENTIATION = 6 # **
|
21
|
+
Blockly.Ruby.ORDER_UNARY_MINUS_SIGN = 7 # -(単項)
|
22
|
+
Blockly.Ruby.ORDER_MULTIPLICATIVE = 8 # * / %
|
23
|
+
Blockly.Ruby.ORDER_ADDITIVE = 9 # + -
|
24
|
+
Blockly.Ruby.ORDER_BITWISE_SHIFT = 10 # << >>
|
25
|
+
Blockly.Ruby.ORDER_BITWISE_AND = 11 # &
|
26
|
+
Blockly.Ruby.ORDER_BITWISE_XOR = 12 # ^
|
27
|
+
Blockly.Ruby.ORDER_BITWISE_OR = 12 # |
|
28
|
+
Blockly.Ruby.ORDER_RELATIONAL = 13 # > >= < <=
|
29
|
+
Blockly.Ruby.ORDER_EQUALS = 14 # <=> == === != =~ !~
|
30
|
+
Blockly.Ruby.ORDER_LOGICAL_AND = 15 # &&
|
31
|
+
Blockly.Ruby.ORDER_LOGICAL_OR = 16 # ||
|
32
|
+
Blockly.Ruby.ORDER_RANGE = 17 # .. ...
|
33
|
+
Blockly.Ruby.ORDER_CONDITIONAL = 18 # ?:(条件演算子)
|
34
|
+
Blockly.Ruby.ORDER_ASSIGNMENT = 19 # =(+=, -= ... )
|
35
|
+
Blockly.Ruby.ORDER_NOT = 20 # not
|
36
|
+
Blockly.Ruby.ORDER_AND_OR = 21 # and or
|
35
37
|
Blockly.Ruby.ORDER_NONE = 99 # (...)
|
36
38
|
|
37
39
|
Blockly.Ruby.INFINITE_LOOP_TRAP = null
|
@@ -14,6 +14,27 @@ Smalruby.Character = Backbone.Model.extend({
|
|
14
14
|
if @get('costumes').length == 0
|
15
15
|
@set({ costumes: [Smalruby.Character.PRESET_COSTUMES[0]] })
|
16
16
|
|
17
|
+
validate: (attrs, options) ->
|
18
|
+
errors = []
|
19
|
+
|
20
|
+
name = attrs.name
|
21
|
+
if _.isUndefined(name) || _.isNull(name) ||
|
22
|
+
(_.isString(name) && name.length == 0)
|
23
|
+
errors.push
|
24
|
+
attr: 'name'
|
25
|
+
message: 'Name is required'
|
26
|
+
|
27
|
+
if _.isString(name) &&
|
28
|
+
name.match(/^[0-9A-Z]|[!\"\#$%&\'()\-=^~\\|@`\[{;+:*\]},<.>/?]/)
|
29
|
+
errors.push
|
30
|
+
attr: 'name'
|
31
|
+
message: 'Name is invalid'
|
32
|
+
|
33
|
+
if errors.length > 0
|
34
|
+
return errors
|
35
|
+
|
36
|
+
return
|
37
|
+
|
17
38
|
link: (object) ->
|
18
39
|
@objects.push(object)
|
19
40
|
@objects = _.uniq(@objects)
|
@@ -37,9 +37,11 @@ Smalruby.CharacterModalView = Backbone.View.extend
|
|
37
37
|
true
|
38
38
|
|
39
39
|
self = @
|
40
|
-
|
40
|
+
changeNameFunc = (e) ->
|
41
41
|
self.model.set({ name: $(@).val() })
|
42
42
|
self.nameChanged = true
|
43
|
+
@$el.find('input[name="character[name]"]').change(changeNameFunc)
|
44
|
+
@$el.find('input[name="character[name]"]').keyup(changeNameFunc)
|
43
45
|
|
44
46
|
@$el.find('input[name="character[x]"]').change (e) ->
|
45
47
|
self.model.set({ x: $(@).val() })
|
@@ -55,11 +57,14 @@ Smalruby.CharacterModalView = Backbone.View.extend
|
|
55
57
|
@listenTo(@model, 'change:y', @onChangeY)
|
56
58
|
@listenTo(@model, 'change:angle', @onChangeAngle)
|
57
59
|
@listenTo(@model, 'change:costumes', @onChangeCostumes)
|
60
|
+
@listenTo(@model, 'change', @onChange)
|
58
61
|
|
59
|
-
@
|
62
|
+
@callAllOnChangeAttributes_()
|
60
63
|
|
61
64
|
render: ->
|
65
|
+
@onChange(@model)
|
62
66
|
@$el.modal('show')
|
67
|
+
|
63
68
|
# HACK: ダイアログを表示して500ms程度待たないと画像のサイズが取得できなかった
|
64
69
|
f = ->
|
65
70
|
if @readImageSizeflag
|
@@ -74,7 +79,7 @@ Smalruby.CharacterModalView = Backbone.View.extend
|
|
74
79
|
if @readImageSizeflag
|
75
80
|
setTimeout(_.bind(f, @), 1)
|
76
81
|
|
77
|
-
|
82
|
+
callAllOnChangeAttributes_: ->
|
78
83
|
@onChangeName(@model, @model.get('name'))
|
79
84
|
@onChangeX(@model, @model.get('x'))
|
80
85
|
@onChangeY(@model, @model.get('y'))
|
@@ -118,6 +123,22 @@ Smalruby.CharacterModalView = Backbone.View.extend
|
|
118
123
|
else
|
119
124
|
@readImageSizeflag = true
|
120
125
|
|
126
|
+
onChange: (model, options) ->
|
127
|
+
return unless @target
|
128
|
+
|
129
|
+
@$el.find('.control-group[for="character[name]"]').removeClass('error')
|
130
|
+
@$el.find('#character-modal-ok-button').removeClass('disabled').removeAttr('disabled')
|
131
|
+
|
132
|
+
unless @model.isValid()
|
133
|
+
@$el.find('.control-group[for="character[name]"]').addClass('error')
|
134
|
+
@$el.find('#character-modal-ok-button').addClass('disabled').attr({ disabled: 'disabled' })
|
135
|
+
|
136
|
+
name = @model.get('name')
|
137
|
+
if @target.get('name') != name &&
|
138
|
+
Smalruby.Collections.CharacterSet.findWhere({ name: name })
|
139
|
+
@$el.find('.control-group[for="character[name]"]').addClass('error')
|
140
|
+
@$el.find('#character-modal-ok-button').addClass('disabled').attr({ disabled: 'disabled' })
|
141
|
+
|
121
142
|
onSelectCostume: (e) ->
|
122
143
|
e.preventDefault()
|
123
144
|
|
@@ -22,7 +22,6 @@
|
|
22
22
|
|
23
23
|
-# [▼]へ向ける
|
24
24
|
%block{:type => "#{category}_point_towards_character"}
|
25
|
-
= toolbox_character_field
|
26
25
|
|
27
26
|
-# x座標を( )、y座標を( )にする
|
28
27
|
%block{:type => "#{category}_set_x_y"}
|
@@ -247,12 +246,12 @@
|
|
247
246
|
= toolbox_number_value('A', 1)
|
248
247
|
= toolbox_number_value('B', 10)
|
249
248
|
|
250
|
-
-# 変数:( )の
|
249
|
+
-# 変数:( )の( )番目
|
251
250
|
%block{:type => "#{category}_index_of"}
|
252
251
|
= toolbox_text_value('A', 'あいうえお')
|
253
252
|
= toolbox_number_value('INDEX', 1)
|
254
253
|
|
255
|
-
-# 変数:
|
254
|
+
-# 変数:( )の長さ
|
256
255
|
%block{:type => "#{category}_length"}
|
257
256
|
= toolbox_text_value('A', 'あいうえお')
|
258
257
|
|
@@ -363,6 +362,11 @@
|
|
363
362
|
-# -# LCDをクリアする
|
364
363
|
-# %block{:type => "#{category}_lcd_clear"}
|
365
364
|
|
365
|
+
%category{:name => 'サーボ'}
|
366
|
+
-# サーボ[▼ピン]を( )度(5~180)にする
|
367
|
+
%block{:type => "#{category}_servo_set_position"}
|
368
|
+
= toolbox_number_value('POS', 90)
|
369
|
+
|
366
370
|
-#%category{:name => 'ボタン'}
|
367
371
|
-# -# 条件:ボタン[▼]を押している
|
368
372
|
-# %block{:type => "#{category}_button_down"}
|