kame-remocon 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0120ea3770eb1a69977bced26ed7d508d588104444091336495f70a4d2f0e31c
4
- data.tar.gz: 76a684647d92c156a8f0ac2f390a4ad0b3206853223736fb4fbb5afb696c782f
3
+ metadata.gz: 18ad27c2216af93b47a919d1edfe7f8f85104e4b4b0e8489db78987588f420e9
4
+ data.tar.gz: 3d707f62afacfb522aa1aa2480705be16ed69b908f925ee97cdf2845ead075c6
5
5
  SHA512:
6
- metadata.gz: 45ce6b97b71e6c0871918b286610fc68545886dd32741fdc6e265b426e95b96de53b59f1ce94bc11a76633baba75a0423f5077a97a3bff38d117a589c2a63a26
7
- data.tar.gz: daf15be3c1a10e473c441d40495b8fb5b2561adf724e408963d57e3c7d479c77f043525eb1c1327da4ef3c65c8de8d9767d61e46ff4395679f884f3c97a9ec0b
6
+ metadata.gz: e343e857259af437ca47568404efbf3fc8e1b713c1412e7767c56b8b0c9790b0bd7d8ba1d548fe147c52b47e6e3a38b0745acaeb40a31a11924a2edad6fafcde
7
+ data.tar.gz: 4d3975a4252f5ca6995f42ca09a09edad7c18a69b50e506c66111353835604c6b6fb23edc0d9e3d45f0debf2865c925e4f69c0bcf917bb3ccf79309bca270e0d
@@ -9,6 +9,10 @@ class Kame::Remocon::Opal::Canvas
9
9
  Context.new `#@native.getContext(type)`
10
10
  end
11
11
 
12
+ def image_data
13
+ `#@native.toDataURL()`.sub(/^.*,/, "")
14
+ end
15
+
12
16
  class Context
13
17
  include Native
14
18
  include Native::Helpers
@@ -4,6 +4,7 @@ require_relative "./image"
4
4
 
5
5
  class Kame::Remocon::Opal::Turtle
6
6
  attr_accessor :default_color
7
+ attr_reader :code
7
8
 
8
9
  class Pos
9
10
  attr_reader :x, :y
@@ -59,6 +60,10 @@ class Kame::Remocon::Opal::Turtle
59
60
  end
60
61
  end
61
62
 
63
+ def image_data
64
+ @canvas.image_data
65
+ end
66
+
62
67
  def draw_kame
63
68
  (x, y) = @pos.canvas_coordinate
64
69
 
@@ -70,15 +75,17 @@ class Kame::Remocon::Opal::Turtle
70
75
  @context.set_transform(1, 0, 0, 1, 0, 0)
71
76
  end
72
77
 
73
- def exec(program, wait=0)
78
+ def exec(code, wait=0, &callback)
79
+ @code = code
74
80
  clear
75
81
  reset
76
82
  commander = Commander.new
77
- commander.instance_eval program
78
- exec_commands(commander.commands, wait: wait)
83
+ commander.instance_eval code
84
+ exec_commands(commander.commands, wait: wait, &callback)
79
85
  end
80
86
 
81
- def exec_commands(commands, wait: nil)
87
+ def exec_commands(commands, wait: nil, &callback)
88
+ callback ||= Proc.new {}
82
89
  wait ||= @wait
83
90
  if wait > 0
84
91
  exec = Proc.new do
@@ -98,7 +105,10 @@ class Kame::Remocon::Opal::Turtle
98
105
  interval = wait * 1000
99
106
  %x(
100
107
  var timer = setInterval(function() {
101
- if (!exec()) { clearInterval(timer); }
108
+ if (!exec()) {
109
+ callback.$call();
110
+ clearInterval(timer);
111
+ }
102
112
  }, interval);
103
113
  )
104
114
  else
@@ -109,9 +119,11 @@ class Kame::Remocon::Opal::Turtle
109
119
  end
110
120
  if @kame.complete
111
121
  draw_kame
122
+ callback.call
112
123
  else
113
124
  @kame.onload do
114
125
  draw_kame
126
+ callback.call
115
127
  end
116
128
  end
117
129
  end
@@ -21,7 +21,7 @@ class Kame::Remocon::Opal::AppView
21
21
  state :bg_color, "black"
22
22
 
23
23
  def initialize
24
- @program = <<~PROG
24
+ @code= <<~PROG
25
25
  pen_down
26
26
  forward 100
27
27
  turn_left 90
@@ -33,25 +33,29 @@ class Kame::Remocon::Opal::AppView
33
33
  PROG
34
34
  end
35
35
 
36
+ def self.render(parent, &block)
37
+ Hyalite.render(Kame::Remocon::Opal::AppView.el(on_mounted: block), parent)
38
+ end
39
+
36
40
  def mounted(canvas)
41
+ @canvas = canvas
37
42
  @turtle = Kame::Remocon::Opal::Turtle.new(canvas)
38
- @turtle.exec @program
43
+ @turtle.exec @code
44
+ @code_getter = -> { @refs[:program].value }
39
45
 
40
46
  if Kame::Remocon::Opal::Config.ws_enabled?
41
47
  @remote = DRb::DRbObject.new_with_uri "ws://127.0.0.1:9292"
42
48
  DRb.start_service("ws://127.0.0.1:9292/callback")
43
49
  @remote.set_turtle DRb::DRbObject.new(@turtle)
44
50
  end
51
+
52
+ @props[:on_mounted]&.call(@turtle, @remote)
45
53
  end
46
54
 
47
55
  def exec
48
- @program = @refs[:program].value
56
+ @code = @refs[:program].value
49
57
  wait = @refs[:wait][:checked] ? 0.3 : 0
50
- @turtle.exec @program, wait
51
- end
52
-
53
- def create_image
54
- set_state(render_image: true)
58
+ @turtle.exec @code, wait
55
59
  end
56
60
 
57
61
  def set_background
@@ -61,19 +65,16 @@ class Kame::Remocon::Opal::AppView
61
65
  end
62
66
 
63
67
  def render
64
- program = @program
68
+ code = @code
65
69
  render_image = @state[:render_image]
66
70
  bg_color = @state[:bg_color]
67
71
 
68
72
  div do
69
73
  div do
70
74
  Kame::Remocon::Opal::CanvasView.el(onMounted: -> canvas { mounted(canvas) }, render_image: render_image, bg_color: bg_color)
71
- div({class: "wrap-code-text"}, textarea({style: {width: "400px", height: "400px"}, ref: :program}, program))
75
+ div({class: "wrap-code-text"}, textarea({style: {width: "400px", height: "400px"}, ref: :program}, code))
72
76
  end
73
- Hyalite.create_element(:p, {class: "exec-button"}, button({onClick: -> { exec }, name: "exec"}, "実行する"))
74
-
75
- div do
76
- h2(nil, "設定")
77
+ div({class: :setting}) do
77
78
  ul do
78
79
  li do
79
80
  input({type: :checkbox, checked: true, id: :wait, ref: :wait})
@@ -84,8 +85,8 @@ class Kame::Remocon::Opal::AppView
84
85
  label({for: :bg_color}, "黒背景")
85
86
  end
86
87
  end
87
- #button({onClick: -> { create_image }, name: "create_image"}, "画像を作成")
88
88
  end
89
+ Hyalite.create_element(:p, {class: "exec-button"}, button({onClick: -> { exec }, name: "exec"}, "実行する"))
89
90
  end
90
91
  end
91
92
  end
@@ -23,9 +23,6 @@ class Kame::Remocon::Opal::CanvasView
23
23
 
24
24
  div({class: "wrap-canvas"}) do
25
25
  canvas(width: "400", height: "400", id: :canvas, ref: :canvas, style: {"background-color": bg_color})
26
- if image
27
- img(src: image, style: {"background-color": bg_color})
28
- end
29
26
  end
30
27
  end
31
28
  end
@@ -1,5 +1,5 @@
1
1
  module Kame
2
2
  module Remocon
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kame-remocon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-19 00:00:00.000000000 Z
11
+ date: 2019-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal