reight 0.1.6 → 0.1.7
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 +4 -4
- data/ChangeLog.md +52 -0
- data/Rakefile +4 -1
- data/VERSION +1 -1
- data/lib/reight/all.rb +6 -2
- data/lib/reight/app/map/brush.rb +1 -1
- data/lib/reight/app/map/brush_base.rb +3 -3
- data/lib/reight/app/map/canvas.rb +4 -13
- data/lib/reight/app/map/chips.rb +6 -2
- data/lib/reight/app/map/editor.rb +4 -4
- data/lib/reight/app/map/line.rb +5 -5
- data/lib/reight/app/map/rect.rb +2 -2
- data/lib/reight/app/navigator.rb +27 -27
- data/lib/reight/app/runner.rb +106 -84
- data/lib/reight/app/sound/brush.rb +32 -0
- data/lib/reight/app/sound/canvas.rb +190 -0
- data/lib/reight/app/sound/editor.rb +170 -10
- data/lib/reight/app/sound/eraser.rb +28 -0
- data/lib/reight/app/sound/tool.rb +29 -0
- data/lib/reight/app/sound.rb +4 -0
- data/lib/reight/app/sprite/canvas.rb +18 -15
- data/lib/reight/app/sprite/chips.rb +6 -1
- data/lib/reight/app/sprite/color.rb +3 -1
- data/lib/reight/app/sprite/editor.rb +15 -28
- data/lib/reight/app/sprite/line.rb +1 -1
- data/lib/reight/app/sprite/shape.rb +1 -1
- data/lib/reight/app.rb +19 -1
- data/lib/reight/button.rb +7 -4
- data/lib/reight/chip.rb +24 -6
- data/lib/reight/context.rb +168 -0
- data/lib/reight/helpers.rb +2 -2
- data/lib/reight/index.rb +76 -0
- data/lib/reight/map.rb +131 -11
- data/lib/reight/project.rb +34 -6
- data/lib/reight/reight.rb +1 -3
- data/lib/reight/sound.rb +238 -0
- data/lib/reight/sprite.rb +42 -0
- data/lib/reight/text.rb +116 -0
- data/lib/reight.rb +7 -3
- data/reight.gemspec +7 -7
- data/res/icons.png +0 -0
- data/test/helper.rb +16 -0
- data/test/test_map.rb +7 -7
- data/test/test_map_chunk.rb +6 -6
- data/test/test_sprite.rb +28 -0
- metadata +39 -30
- data/lib/reight/app/music/editor.rb +0 -25
- data/lib/reight/app/music.rb +0 -1
@@ -3,23 +3,183 @@ using Reight
|
|
3
3
|
|
4
4
|
class Reight::SoundEditor < Reight::App
|
5
5
|
|
6
|
+
def canvas()
|
7
|
+
@canvas ||= Canvas.new self
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup()
|
11
|
+
super
|
12
|
+
history.disable do
|
13
|
+
tones[0].click
|
14
|
+
tools[0].click
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
def draw()
|
7
19
|
background 200
|
20
|
+
sprite(*sprites)
|
21
|
+
super
|
22
|
+
end
|
8
23
|
|
9
|
-
|
10
|
-
|
24
|
+
def key_pressed()
|
25
|
+
super
|
26
|
+
case key_code
|
27
|
+
when ENTER then play_or_stop.click
|
28
|
+
when :b then brush.click
|
29
|
+
when :e then eraser.click
|
30
|
+
when /^[#{(1..Reight::Sound::Note::TONES.size).to_a.join}]$/
|
31
|
+
tones[key_code.to_s.to_i - 1].click
|
32
|
+
end
|
33
|
+
end
|
11
34
|
|
12
|
-
|
13
|
-
|
14
|
-
|
35
|
+
def window_resized()
|
36
|
+
super
|
37
|
+
index.sprite.tap do |sp|
|
38
|
+
sp.w, sp.h = 32, BUTTON_SIZE
|
39
|
+
sp.x = SPACE
|
40
|
+
sp.y = NAVIGATOR_HEIGHT + SPACE
|
41
|
+
end
|
42
|
+
bpm.sprite.tap do |sp|
|
43
|
+
sp.w, sp.h = 40, BUTTON_SIZE
|
44
|
+
sp.x = index.sprite.right + SPACE
|
45
|
+
sp.y = index.sprite.y
|
46
|
+
end
|
47
|
+
edits.map(&:sprite).each.with_index do |sp, i|
|
48
|
+
sp.w, sp.h = 32, BUTTON_SIZE
|
49
|
+
sp.x = bpm.sprite.right + SPACE + (sp.w + 1) * i
|
50
|
+
sp.y = bpm.sprite.y
|
51
|
+
end
|
52
|
+
controls.map(&:sprite).each.with_index do |sp, i|
|
53
|
+
sp.w, sp.h = 32, BUTTON_SIZE
|
54
|
+
sp.x = SPACE + (sp.w + 1) * i
|
55
|
+
sp.y = height - (SPACE + sp.h)
|
56
|
+
end
|
57
|
+
tools.map(&:sprite).each.with_index do |sp, i|
|
58
|
+
sp.w = sp.h = BUTTON_SIZE
|
59
|
+
sp.x = controls.last.sprite.right + SPACE * 2 + (sp.w + 1) * i
|
60
|
+
sp.y = controls.last.sprite.y
|
61
|
+
end
|
62
|
+
tones.map(&:sprite).each.with_index do |sp, i|
|
63
|
+
sp.w = sp.h = BUTTON_SIZE
|
64
|
+
sp.x = tools.last.sprite.right + SPACE * 2 + (sp.w + 1) * i
|
65
|
+
sp.y = tools.last.sprite.y
|
66
|
+
end
|
67
|
+
canvas.sprite.tap do |sp|
|
68
|
+
sp.x = SPACE
|
69
|
+
sp.y = index.sprite.bottom + SPACE
|
70
|
+
sp.right = width - SPACE
|
71
|
+
sp.bottom = tools.first.sprite.y - SPACE
|
72
|
+
end
|
73
|
+
end
|
15
74
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
75
|
+
def undo(flash: true)
|
76
|
+
history.undo do |action|
|
77
|
+
case action
|
78
|
+
in [:put_note, ti, ni, _] then canvas.sound.remove ti, ni
|
79
|
+
in [:delete_note, ti, ni, tone] then canvas.sound.add ti, ni, tone
|
80
|
+
end
|
81
|
+
self.flash 'Undo!' if flash
|
20
82
|
end
|
83
|
+
end
|
21
84
|
|
22
|
-
|
85
|
+
def redo(flash: true)
|
86
|
+
history.redo do |action|
|
87
|
+
case action
|
88
|
+
in [:put_note, ti, ni, tone] then canvas.sound.add ti, ni, tone
|
89
|
+
in [:delete_note, ti, ni, _] then canvas.sound.remove ti, ni
|
90
|
+
end
|
91
|
+
self.flash 'Redo!' if flash
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def sprites()
|
98
|
+
[index, bpm, *edits, *controls, *tools, *tones, canvas]
|
99
|
+
.map(&:sprite) + super
|
100
|
+
end
|
101
|
+
|
102
|
+
def index()
|
103
|
+
@index ||= Reight::Index.new do |index|
|
104
|
+
canvas.sound = project.sounds[index] ||= Reight::Sound.new
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def bpm()
|
109
|
+
@bpm ||= Reight::Text.new(
|
110
|
+
canvas.sound.bpm, label: 'BPM ', regexp: /^\-?\d+$/
|
111
|
+
) do |str, text|
|
112
|
+
bpm = str.to_i.clamp(0, Reight::Sound::BPM_MAX)
|
113
|
+
next text.revert if bpm <= 0
|
114
|
+
text.value = canvas.sound.bpm = bpm
|
115
|
+
canvas.save
|
116
|
+
end.tap do |text|
|
117
|
+
canvas.sound_changed {text.value = _1.bpm}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def edits()
|
122
|
+
@edits ||= [
|
123
|
+
Reight::Button.new(name: 'Clear All Notes', label: 'Clear') {
|
124
|
+
canvas.sound.clear
|
125
|
+
canvas.save
|
126
|
+
},
|
127
|
+
Reight::Button.new(name: 'Delete Sound', label: 'Delete') {
|
128
|
+
project.sounds.delete_at index.index
|
129
|
+
canvas.sound = project.sounds[index.index] ||= Reight::Sound.new
|
130
|
+
canvas.save
|
131
|
+
},
|
132
|
+
]
|
133
|
+
end
|
134
|
+
|
135
|
+
def controls()
|
136
|
+
@controls ||= [play_or_stop]
|
137
|
+
end
|
138
|
+
|
139
|
+
def play_or_stop()
|
140
|
+
@play_or_stop ||= Reight::Button.new(name: 'Play Sound', label: 'Play') {|b|
|
141
|
+
played = -> {b.name, b.label = 'Stop Sound', 'Stop'}
|
142
|
+
stopped = -> {b.name, b.label = 'Play Sound', 'Play'}
|
143
|
+
if canvas.sound.playing?
|
144
|
+
canvas.sound.stop
|
145
|
+
stopped.call
|
146
|
+
else
|
147
|
+
canvas.sound.play {stopped.call}
|
148
|
+
played.call
|
149
|
+
end
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
def tools()
|
154
|
+
@tools ||= group brush, eraser
|
155
|
+
end
|
156
|
+
|
157
|
+
def brush = @brush ||= Brush.new(self) {canvas.tool = _1}
|
158
|
+
def eraser = @eraser ||= Eraser.new(self) {canvas.tool = _1}
|
159
|
+
|
160
|
+
def tones()
|
161
|
+
@tones ||= group(*Reight::Sound::Note::TONES.map.with_index {|tone, index|
|
162
|
+
name = tone.to_s.capitalize.gsub('_', '.')
|
163
|
+
name += ' Wave' if name !~ /noise/i
|
164
|
+
color = Canvas::TONE_COLORS[tone]
|
165
|
+
Reight::Button.new name: name, icon: icon(index, 3, 8) do
|
166
|
+
canvas.tone = tone
|
167
|
+
Reight::Sound::Note.new(60, tone).play 120 if active?
|
168
|
+
end.tap do |b|
|
169
|
+
b.instance_variable_set :@color, color
|
170
|
+
class << b
|
171
|
+
alias draw_ draw
|
172
|
+
def draw
|
173
|
+
draw_
|
174
|
+
no_fill
|
175
|
+
stroke @color
|
176
|
+
stroke_weight 1
|
177
|
+
w, h = sprite.width, sprite.height
|
178
|
+
line 3, h - 1, w - 3, h - 1
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
})
|
23
183
|
end
|
24
184
|
|
25
185
|
end# SoundEditor
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Reight::SoundEditor::Eraser < Reight::SoundEditor::Tool
|
2
|
+
|
3
|
+
def initialize(app, &block)
|
4
|
+
super app, icon: app.icon(3, 2, 8), &block
|
5
|
+
set_help left: name
|
6
|
+
end
|
7
|
+
|
8
|
+
def erase(x, y, button)
|
9
|
+
canvas.delete x, y
|
10
|
+
end
|
11
|
+
|
12
|
+
def canvas_pressed(x, y, button)
|
13
|
+
return unless button == LEFT
|
14
|
+
canvas.begin_editing
|
15
|
+
erase x, y, button
|
16
|
+
end
|
17
|
+
|
18
|
+
def canvas_released(x, y, button)
|
19
|
+
return unless button == LEFT
|
20
|
+
canvas.end_editing
|
21
|
+
end
|
22
|
+
|
23
|
+
def canvas_dragged(x, y, button)
|
24
|
+
return unless button == LEFT
|
25
|
+
erase x, y, button
|
26
|
+
end
|
27
|
+
|
28
|
+
end# Eraser
|
@@ -0,0 +1,29 @@
|
|
1
|
+
using Reight
|
2
|
+
|
3
|
+
|
4
|
+
class Reight::SoundEditor::Tool < Reight::Button
|
5
|
+
|
6
|
+
def initialize(app, *a, **k, &b)
|
7
|
+
super(*a, **k, &b)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :app
|
12
|
+
|
13
|
+
def canvas = app.canvas
|
14
|
+
|
15
|
+
def history = app.history
|
16
|
+
|
17
|
+
def name = self.class.name.split('::').last
|
18
|
+
|
19
|
+
def pick_tone(x, y)
|
20
|
+
canvas.tone = canvas.tone_at x, y
|
21
|
+
end
|
22
|
+
|
23
|
+
def canvas_pressed( x, y, button) = nil
|
24
|
+
def canvas_released(x, y, button) = nil
|
25
|
+
def canvas_moved( x, y) = nil
|
26
|
+
def canvas_dragged( x, y, button) = nil
|
27
|
+
def canvas_clicked( x, y, button) = nil
|
28
|
+
|
29
|
+
end# Tool
|
data/lib/reight/app/sound.rb
CHANGED
@@ -6,17 +6,19 @@ class Reight::SpriteEditor::Canvas
|
|
6
6
|
include Reight::Hookable
|
7
7
|
|
8
8
|
def initialize(app, image, path)
|
9
|
-
hook :
|
9
|
+
hook :color_changed
|
10
10
|
|
11
11
|
@app, @image, @path = app, image, path
|
12
|
-
@tool, @color, @selection = nil, [255, 255, 255], nil
|
12
|
+
@tool, @color, @selection = nil, [255, 255, 255, 255], nil
|
13
13
|
|
14
14
|
@app.history.disable do
|
15
15
|
set_frame 0, 0, 16, 16
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
attr_accessor :tool
|
20
|
+
|
21
|
+
attr_reader :x, :y, :w, :h, :color
|
20
22
|
|
21
23
|
def width = @image.width
|
22
24
|
|
@@ -27,11 +29,6 @@ class Reight::SpriteEditor::Canvas
|
|
27
29
|
@app.project.save
|
28
30
|
end
|
29
31
|
|
30
|
-
def tool=(tool)
|
31
|
-
@tool = tool
|
32
|
-
tool_changed! tool
|
33
|
-
end
|
34
|
-
|
35
32
|
def set_frame(x, y, w, h)
|
36
33
|
old = [@x, @y, @w, @h]
|
37
34
|
new = correct_bounds x, y, w, h
|
@@ -76,6 +73,7 @@ class Reight::SpriteEditor::Canvas
|
|
76
73
|
g.clip(*(selection || frame))
|
77
74
|
g.push do
|
78
75
|
g.translate x, y
|
76
|
+
g.blend_mode REPLACE
|
79
77
|
block.call g
|
80
78
|
end
|
81
79
|
end
|
@@ -85,24 +83,24 @@ class Reight::SpriteEditor::Canvas
|
|
85
83
|
tmp = sub_image x, y, w, h
|
86
84
|
tmp.update_pixels {|pixels| block.call pixels}
|
87
85
|
@image.begin_draw do |g|
|
88
|
-
g.
|
86
|
+
g.blend tmp, 0, 0, w, h, x, y, w, h, REPLACE
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
92
90
|
def sub_image(x, y, w, h)
|
93
91
|
create_graphics(w, h).tap do |g|
|
94
|
-
g.begin_draw {g.
|
92
|
+
g.begin_draw {g.blend @image, x, y, w, h, 0, 0, w, h, REPLACE}
|
95
93
|
end
|
96
94
|
end
|
97
95
|
|
98
96
|
def pixel_at(x, y)
|
99
|
-
img = sub_image x, y, 1, 1
|
97
|
+
img = sub_image self.x + x, self.y + y, 1, 1
|
100
98
|
img.load_pixels
|
101
99
|
c = img.pixels[0]
|
102
100
|
[red(c), green(c), blue(c), alpha(c)].map &:to_i
|
103
101
|
end
|
104
102
|
|
105
|
-
def clear(frame, color:
|
103
|
+
def clear(frame, color:)
|
106
104
|
paint do |g|
|
107
105
|
g.fill(*color)
|
108
106
|
g.no_stroke
|
@@ -127,7 +125,7 @@ class Reight::SpriteEditor::Canvas
|
|
127
125
|
x, y, w, h = frame
|
128
126
|
create_graphics(w, h).tap do |g|
|
129
127
|
g.begin_draw do
|
130
|
-
g.
|
128
|
+
g.blend @image, x, y, w, h, 0, 0, w, h, REPLACE
|
131
129
|
end
|
132
130
|
end
|
133
131
|
end
|
@@ -135,13 +133,13 @@ class Reight::SpriteEditor::Canvas
|
|
135
133
|
def apply_frame(image, x, y)
|
136
134
|
@image.begin_draw do |g|
|
137
135
|
w, h = image.width, image.height
|
138
|
-
g.
|
136
|
+
g.blend image, 0, 0, w, h, x, y, w, h, REPLACE
|
139
137
|
end
|
140
138
|
save
|
141
139
|
end
|
142
140
|
|
143
141
|
def sprite()
|
144
|
-
@sprite ||= Sprite.new.tap do |sp|
|
142
|
+
@sprite ||= RubySketch::Sprite.new.tap do |sp|
|
145
143
|
pos = -> {to_image sp.mouse_x, sp.mouse_y}
|
146
144
|
sp.draw {draw}
|
147
145
|
sp.mouse_pressed {tool&.canvas_pressed( *pos.call, sp.mouse_button)}
|
@@ -171,6 +169,11 @@ class Reight::SpriteEditor::Canvas
|
|
171
169
|
def draw()
|
172
170
|
sp = sprite
|
173
171
|
clip sp.x, sp.y, sp.w, sp.h
|
172
|
+
|
173
|
+
fill 0
|
174
|
+
no_stroke
|
175
|
+
rect 0, 0, sp.w, sp.h
|
176
|
+
|
174
177
|
copy @image, x, y, w, h, 0, 0, sp.w, sp.h if @image && x && y && w && h
|
175
178
|
|
176
179
|
sx, sy = sp.w / w, sp.h / h
|
@@ -31,6 +31,11 @@ class Reight::SpriteEditor::Chips
|
|
31
31
|
def draw()
|
32
32
|
sp = sprite
|
33
33
|
clip sp.x, sp.y, sp.w, sp.h
|
34
|
+
|
35
|
+
fill 0
|
36
|
+
no_stroke
|
37
|
+
rect 0, 0, sp.w, sp.h
|
38
|
+
|
34
39
|
translate(*clamp_offset(@offset).to_a)
|
35
40
|
image @image, 0, 0
|
36
41
|
|
@@ -63,7 +68,7 @@ class Reight::SpriteEditor::Chips
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def sprite()
|
66
|
-
@sprite ||= Sprite.new.tap do |sp|
|
71
|
+
@sprite ||= RubySketch::Sprite.new.tap do |sp|
|
67
72
|
sp.draw {draw}
|
68
73
|
sp.mouse_pressed {mouse_pressed sp.mouse_x, sp.mouse_y}
|
69
74
|
sp.mouse_released {mouse_released sp.mouse_x, sp.mouse_y}
|
@@ -4,8 +4,9 @@ using Reight
|
|
4
4
|
class Reight::SpriteEditor::Color < Reight::Button
|
5
5
|
|
6
6
|
def initialize(color, &clicked)
|
7
|
-
super name:
|
7
|
+
super name: color[0, 3].map {_1.to_s(16).upcase}.join, &clicked
|
8
8
|
@color = color
|
9
|
+
set_help name: "##{name}"
|
9
10
|
end
|
10
11
|
|
11
12
|
attr_reader :color
|
@@ -15,6 +16,7 @@ class Reight::SpriteEditor::Color < Reight::Button
|
|
15
16
|
|
16
17
|
fill(*color)
|
17
18
|
no_stroke
|
19
|
+
blend_mode REPLACE
|
18
20
|
rect 0, 0, sp.w, sp.h
|
19
21
|
|
20
22
|
if active?
|
@@ -7,14 +7,10 @@ class Reight::SpriteEditor < Reight::App
|
|
7
7
|
@canvas ||= Canvas.new(
|
8
8
|
self,
|
9
9
|
project.chips_image,
|
10
|
-
project.chips_image_path
|
11
|
-
).tap do |canvas|
|
12
|
-
canvas. tool_changed {update_active_tool}
|
13
|
-
canvas.color_changed {update_active_color}
|
14
|
-
end
|
10
|
+
project.chips_image_path)
|
15
11
|
end
|
16
12
|
|
17
|
-
def
|
13
|
+
def setup()
|
18
14
|
super
|
19
15
|
history.disable do
|
20
16
|
colors[7].click
|
@@ -32,7 +28,7 @@ class Reight::SpriteEditor < Reight::App
|
|
32
28
|
|
33
29
|
def key_pressed()
|
34
30
|
super
|
35
|
-
shift, ctrl, cmd =
|
31
|
+
shift, ctrl, cmd = [SHIFT, CONTROL, COMMAND].map {pressing? _1}
|
36
32
|
ch = chips
|
37
33
|
case key_code
|
38
34
|
when LEFT then ch.set_frame ch.x - ch.size, ch.y, ch.size, ch.size
|
@@ -64,19 +60,18 @@ class Reight::SpriteEditor < Reight::App
|
|
64
60
|
sp.bottom = height - SPACE
|
65
61
|
end
|
66
62
|
colors.map {_1.sprite}.each.with_index do |sp, index|
|
67
|
-
sp.
|
68
|
-
sp.
|
63
|
+
sp.h *= 0.8
|
64
|
+
sp.x = chips.sprite.right + SPACE + sp.w * (index % 8)
|
65
|
+
sp.y = height - (SPACE + sp.h * (4 - index / 8))
|
69
66
|
end
|
70
67
|
tools.map {_1.sprite}.each.with_index do |sp, index|
|
71
|
-
|
72
|
-
|
73
|
-
sp.x = colors.last.sprite.right + SPACE + (sp.w + 1) * index
|
74
|
-
sp.y = colors.first.sprite.y + (sp.h + 1) * line
|
68
|
+
sp.x = colors.first.sprite.x + (sp.w + 1) * index
|
69
|
+
sp.y = colors.first.sprite.y - (SPACE / 2 + sp.h)
|
75
70
|
end
|
76
71
|
canvas.sprite.tap do |sp|
|
77
72
|
sp.x = chips.sprite.right + SPACE
|
78
73
|
sp.y = chips.sprite.y
|
79
|
-
sp.bottom =
|
74
|
+
sp.bottom = tools.first.sprite.top - SPACE / 2
|
80
75
|
sp.w = sp.h
|
81
76
|
end
|
82
77
|
chip_sizes.map {_1.sprite}.each.with_index do |sp, index|
|
@@ -149,7 +144,7 @@ class Reight::SpriteEditor < Reight::App
|
|
149
144
|
canvas.deselect
|
150
145
|
canvas.begin_editing do
|
151
146
|
canvas.paint do |g|
|
152
|
-
g.
|
147
|
+
g.blend image, 0, 0, w, h, x, y, w, h, REPLACE
|
153
148
|
end
|
154
149
|
end
|
155
150
|
canvas.select canvas.x + x, canvas.y + y, w, h
|
@@ -222,7 +217,11 @@ class Reight::SpriteEditor < Reight::App
|
|
222
217
|
@colors ||= project.palette_colors.map {|color|
|
223
218
|
rgb = self.color(color)
|
224
219
|
.then {[red(_1), green(_1), blue(_1), alpha(_1)]}.map &:to_i
|
225
|
-
Color.new(rgb)
|
220
|
+
Color.new(rgb) do
|
221
|
+
canvas.color = rgb
|
222
|
+
end.tap do |c|
|
223
|
+
canvas.color_changed {c.active = _1 == rgb}
|
224
|
+
end
|
226
225
|
}
|
227
226
|
end
|
228
227
|
|
@@ -257,16 +256,4 @@ class Reight::SpriteEditor < Reight::App
|
|
257
256
|
types[chip.sensor? ? 1 : 0].click
|
258
257
|
end
|
259
258
|
|
260
|
-
def update_active_tool()
|
261
|
-
tools.each do |tool|
|
262
|
-
tool.active = tool == canvas.tool
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
def update_active_color()
|
267
|
-
colors.each do |button|
|
268
|
-
button.active = button.color == canvas.color
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
259
|
end# SpriteEditor
|
@@ -6,7 +6,7 @@ class Reight::SpriteEditor::Shape < Reight::SpriteEditor::Tool
|
|
6
6
|
def initialize(app, shape, fill, &block)
|
7
7
|
@shape, @fill = shape, fill
|
8
8
|
icon_index = [:rect, :ellipse].product([false, true]).index([shape, fill])
|
9
|
-
super app, icon: app.icon(icon_index +
|
9
|
+
super app, icon: app.icon(icon_index + 5, 2, 8), &block
|
10
10
|
set_help left: name, right: 'Pick Color'
|
11
11
|
end
|
12
12
|
|
data/lib/reight/app.rb
CHANGED
@@ -11,8 +11,16 @@ class Reight::App
|
|
11
11
|
NAVIGATOR_HEIGHT = BUTTON_SIZE + 2
|
12
12
|
CHIPS_WIDTH = 128
|
13
13
|
|
14
|
+
PALETTE_COLORS = %w[
|
15
|
+
#00000000 #742f29 #ab5236 #f18459 #f7cca9 #ee044e #b8023f #7e2553
|
16
|
+
#452d32 #5f574f #a28879 #c2c3c7 #fdf1e8 #f6acc5 #f277a8 #e40dab
|
17
|
+
#1d2c53 #3363b0 #42a5a1 #56adff #64dff6 #bd9adf #83759c #644788
|
18
|
+
#1e5359 #2d8750 #3eb250 #4fe436 #95f041 #f8ec27 #f3a207 #e26b02
|
19
|
+
]
|
20
|
+
|
14
21
|
def initialize(project)
|
15
22
|
@project = project
|
23
|
+
@active = false
|
16
24
|
end
|
17
25
|
|
18
26
|
attr_reader :project
|
@@ -30,6 +38,10 @@ class Reight::App
|
|
30
38
|
buttons
|
31
39
|
end
|
32
40
|
|
41
|
+
def active?()
|
42
|
+
@active
|
43
|
+
end
|
44
|
+
|
33
45
|
def pressing?(key)
|
34
46
|
pressing_keys.include? key
|
35
47
|
end
|
@@ -57,12 +69,18 @@ class Reight::App
|
|
57
69
|
|
58
70
|
def activated()
|
59
71
|
add_world world if world
|
72
|
+
@setup ||= true.tap {setup}
|
73
|
+
@active = true
|
60
74
|
end
|
61
75
|
|
62
76
|
def deactivated()
|
77
|
+
@active = false
|
63
78
|
remove_world world if world
|
64
79
|
end
|
65
80
|
|
81
|
+
def setup()
|
82
|
+
end
|
83
|
+
|
66
84
|
def draw()
|
67
85
|
navigator.draw
|
68
86
|
end
|
@@ -112,7 +130,7 @@ class Reight::App
|
|
112
130
|
|
113
131
|
def world()
|
114
132
|
@world ||= SpriteWorld.new.tap do |w|
|
115
|
-
w.add_sprite
|
133
|
+
sprites.each {w.add_sprite _1}
|
116
134
|
end
|
117
135
|
end
|
118
136
|
|
data/lib/reight/button.rb
CHANGED
@@ -13,10 +13,12 @@ class Reight::Button
|
|
13
13
|
super()
|
14
14
|
|
15
15
|
hook :clicked
|
16
|
-
self.clicked(&clicked)
|
16
|
+
self.clicked(&clicked) if clicked
|
17
17
|
self.clicked {r8.flash name}
|
18
18
|
end
|
19
19
|
|
20
|
+
attr_accessor :name, :icon, :label
|
21
|
+
|
20
22
|
def draw()
|
21
23
|
sp = sprite
|
22
24
|
no_stroke
|
@@ -39,12 +41,13 @@ class Reight::Button
|
|
39
41
|
end
|
40
42
|
|
41
43
|
if @label
|
44
|
+
y = pressing? ? 1 : 0
|
42
45
|
text_size r8.project.font_size - 1
|
43
46
|
text_align CENTER, CENTER
|
44
47
|
fill 100, 100, 100
|
45
|
-
text @label, 0, 1, sp.w, sp.h
|
48
|
+
text @label, 0, y + 1, sp.w, sp.h
|
46
49
|
fill 255, 255, 255
|
47
|
-
text @label, 0,
|
50
|
+
text @label, 0, y, sp.w, sp.h
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
@@ -72,7 +75,7 @@ class Reight::Button
|
|
72
75
|
def disabled? = !enabled?
|
73
76
|
|
74
77
|
def sprite()
|
75
|
-
@sprite ||= Sprite.new(physics: false).tap do |sp|
|
78
|
+
@sprite ||= RubySketch::Sprite.new(physics: false).tap do |sp|
|
76
79
|
sp.draw {draw}
|
77
80
|
sp.mouse_pressed {pressed sp.mouse_x, sp.mouse_y}
|
78
81
|
sp.mouse_released {released sp.mouse_x, sp.mouse_y}
|
data/lib/reight/chip.rb
CHANGED
@@ -7,7 +7,7 @@ class Reight::Chip
|
|
7
7
|
|
8
8
|
def initialize(id, image, x, y, w, h, pos: nil, shape: nil, sensor: nil)
|
9
9
|
@id, @image, @x, @y, @w, @h, @pos, @shape, @sensor =
|
10
|
-
|
10
|
+
id, image, x, y, w, h, pos, shape, (sensor || false)
|
11
11
|
end
|
12
12
|
|
13
13
|
attr_accessor :shape
|
@@ -27,6 +27,7 @@ class Reight::Chip
|
|
27
27
|
def with(**kwargs)
|
28
28
|
id, image, x, y, w, h, pos, shape, sensor =
|
29
29
|
kwargs.values_at :id, :image, :x, :y, :w, :h, :pos, :shape, :sensor
|
30
|
+
#kwargs => {id:, image:, x:, y:, w:, h:, pos:, shape:, sensor:}
|
30
31
|
self.class.new(
|
31
32
|
id || @id,
|
32
33
|
image || @image,
|
@@ -46,8 +47,9 @@ class Reight::Chip
|
|
46
47
|
when :circle then [true, RubySketch::Circle.new(0, 0, w)]
|
47
48
|
else [false, nil]
|
48
49
|
end
|
49
|
-
Sprite.new(
|
50
|
-
0, 0, w, h,
|
50
|
+
Reight::Sprite.new(
|
51
|
+
0, 0, w, h, chip: self,
|
52
|
+
image: image, offset: [x, y], shape: shape, physics: physics
|
51
53
|
).tap do |sp|
|
52
54
|
sp.x, sp.y = pos.x, pos.y if pos
|
53
55
|
if physics
|
@@ -57,6 +59,14 @@ class Reight::Chip
|
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
62
|
+
def sprite()
|
63
|
+
@sprite ||= to_sprite
|
64
|
+
end
|
65
|
+
|
66
|
+
def clear_sprite()
|
67
|
+
@sprite = nil
|
68
|
+
end
|
69
|
+
|
60
70
|
def to_hash()
|
61
71
|
{
|
62
72
|
id: id, x: x, y: y, w: w, h: h
|
@@ -67,7 +77,8 @@ class Reight::Chip
|
|
67
77
|
end
|
68
78
|
end
|
69
79
|
|
70
|
-
|
80
|
+
# @private
|
81
|
+
def cmp__(o)
|
71
82
|
a = [@id, @image.object_id, @x, @y, @w, @h, @pos, @shape, @sensor]
|
72
83
|
b = o.instance_eval {[@id, @image.object_id, @x, @y, @w, @h, @pos, @shape, @sensor]}
|
73
84
|
a <=> b
|
@@ -76,6 +87,7 @@ class Reight::Chip
|
|
76
87
|
def self.restore(hash, image)
|
77
88
|
id, x, y, w, h, pos, shape, sensor =
|
78
89
|
hash.values_at :id, :x, :y, :w, :h, :pos, :shape, :sensor
|
90
|
+
#hash => {id:, x:, y:, w:, h:, pos:, shape:, sensor:}
|
79
91
|
new(
|
80
92
|
id, image, x, y, w, h, pos: pos&.then {create_vector(*_1)},
|
81
93
|
shape: shape&.to_sym, sensor: sensor || false)
|
@@ -110,6 +122,10 @@ class Reight::ChipList
|
|
110
122
|
@frame2chip[[x, y, w, h]] ||= create_chip x, y, w, h
|
111
123
|
end
|
112
124
|
|
125
|
+
def each(&block)
|
126
|
+
@id2chip.values.each(&block)
|
127
|
+
end
|
128
|
+
|
113
129
|
def to_hash()
|
114
130
|
{next_id: @next_id, chips: @id2chip.values.map {_1.to_hash}}
|
115
131
|
end
|
@@ -118,14 +134,16 @@ class Reight::ChipList
|
|
118
134
|
@id2chip[id]
|
119
135
|
end
|
120
136
|
|
121
|
-
|
137
|
+
# @private
|
138
|
+
def cmp__(o)
|
122
139
|
a = [@image, @next_id, @id2chip, @frame2chip]
|
123
140
|
b = o.instance_eval {[@image, @next_id, @id2chip, @frame2chip]}
|
124
141
|
a <=> b
|
125
142
|
end
|
126
143
|
|
127
144
|
def self.restore(hash, image)
|
128
|
-
hash
|
145
|
+
next_id, chips = hash.values_at :next_id, :chips
|
146
|
+
#hash => {next_id:, chips:}
|
129
147
|
new(image).tap do |obj|
|
130
148
|
obj.instance_eval do
|
131
149
|
@next_id = next_id
|