2015-07-22 21:05:31 +02:00
|
|
|
|
2015-07-23 16:26:48 +02:00
|
|
|
require "source_view"
|
2015-07-25 14:28:59 +02:00
|
|
|
require "instruction_view"
|
2015-07-22 21:05:31 +02:00
|
|
|
|
|
|
|
class BlockView
|
|
|
|
|
|
|
|
include React::Component
|
2015-07-23 19:08:40 +02:00
|
|
|
required_param :interpreter
|
2015-07-22 21:05:31 +02:00
|
|
|
|
2015-07-26 08:04:34 +02:00
|
|
|
define_state :block => []
|
|
|
|
define_state :block_name => ""
|
2015-07-24 09:15:58 +02:00
|
|
|
|
2015-07-24 09:01:01 +02:00
|
|
|
before_mount do
|
2015-07-26 08:04:34 +02:00
|
|
|
interpreter.register_event(:instruction_changed, self)
|
|
|
|
update_block
|
2015-07-24 09:01:01 +02:00
|
|
|
end
|
|
|
|
|
2015-07-26 08:04:34 +02:00
|
|
|
def update_block
|
|
|
|
block_name! interpreter.block.name
|
|
|
|
codes = interpreter.block.codes.dup
|
|
|
|
codes.shift while( codes.index(interpreter.instruction) > 1 )
|
|
|
|
codes.pop while(codes.length > 4)
|
|
|
|
block! codes
|
|
|
|
end
|
|
|
|
|
|
|
|
def instruction_changed
|
|
|
|
update_block
|
2015-07-24 09:01:01 +02:00
|
|
|
end
|
2015-07-22 21:05:31 +02:00
|
|
|
|
|
|
|
def render
|
2015-07-24 09:15:58 +02:00
|
|
|
return unless block
|
2015-07-23 16:26:48 +02:00
|
|
|
div.row do
|
2015-07-24 09:01:01 +02:00
|
|
|
div.col_md_5 do
|
2015-07-26 08:04:34 +02:00
|
|
|
SourceView :source => interpreter.instruction.source
|
2015-07-23 16:26:48 +02:00
|
|
|
end
|
2015-07-24 09:01:01 +02:00
|
|
|
div.col_md_5 do
|
2015-07-26 08:04:34 +02:00
|
|
|
h6 { "Block: #{block_name}"}
|
|
|
|
block.each do |code|
|
2015-07-25 14:28:59 +02:00
|
|
|
InstructionView :interpreter => interpreter , :instruction => code
|
2015-07-23 16:26:48 +02:00
|
|
|
end
|
2015-07-22 21:05:31 +02:00
|
|
|
end
|
2015-07-24 09:01:01 +02:00
|
|
|
div.col_md_2 do
|
|
|
|
button.btn.btn_default { "next" }.on(:click) { interpreter.tick }
|
|
|
|
end
|
2015-07-22 21:05:31 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|