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
|
2015-07-27 11:09:35 +02:00
|
|
|
slice = codes.index(interpreter.instruction) #- 1
|
2015-07-26 12:24:00 +02:00
|
|
|
codes.shift( slice ) if slice >= 0
|
2015-07-26 08:04:34 +02:00
|
|
|
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-27 20:29:41 +02:00
|
|
|
div.block_view do
|
|
|
|
div do
|
|
|
|
h4 {"Block: #{block_name}"}
|
2015-07-24 09:01:01 +02:00
|
|
|
button.btn.btn_default { "next" }.on(:click) { interpreter.tick }
|
|
|
|
end
|
2015-07-27 20:29:41 +02:00
|
|
|
block.each do |code|
|
|
|
|
InstructionView :interpreter => interpreter , :instruction => code
|
|
|
|
end
|
2015-07-22 21:05:31 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|