Class: Reight::MapEditor
- Inherits:
-
App
- Object
- App
- Reight::MapEditor
show all
- Defined in:
- lib/reight/app/map/editor.rb
Defined Under Namespace
Classes: Brush, BrushBase, Canvas, Line, Rect, Tool
Constant Summary
Constants inherited
from App
App::BUTTON_SIZE, App::CHIPS_WIDTH, App::INDEX_SIZE, App::NAVIGATOR_HEIGHT, App::PALETTE_COLORS, App::SCREEN_HEIGHT, App::SCREEN_WIDTH, App::SPACE
Instance Attribute Summary
Attributes inherited from App
#project
Instance Method Summary
collapse
Methods inherited from App
#activated, #active?, #control_change, #deactivated, #double_clicked, #flash, #group, #history, #icon, #initialize, #inspect, #key_released, #key_typed, #label, #mouse_clicked, #mouse_dragged, #mouse_moved, #mouse_pressed, #mouse_released, #mouse_wheel, #note_pressed, #note_released, #pressing?, #touch_ended, #touch_moved, #touch_started, #window_moved
Constructor Details
This class inherits a constructor from Reight::App
Instance Method Details
#canvas ⇒ Object
6
7
8
|
# File 'lib/reight/app/map/editor.rb', line 6
def canvas()
@canvas ||= Canvas.new self, project.maps.first
end
|
#chips ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/reight/app/map/editor.rb', line 10
def chips()
@chips ||= Chips.new(self, project.chips).tap do |chips|
chips.offset_changed do |offset|
chips_index.index = chips.offset2index offset
end
end
end
|
#draw ⇒ Object
26
27
28
29
30
|
# File 'lib/reight/app/map/editor.rb', line 26
def draw()
background 200
sprite(*sprites)
super
end
|
#key_pressed ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/reight/app/map/editor.rb', line 32
def key_pressed()
super
shift, ctrl, cmd = %i[shift control command].map {pressing? _1}
case key_code
when LEFT then canvas.x += SCREEN_WIDTH / 2
when RIGHT then canvas.x -= SCREEN_WIDTH / 2
when UP then canvas.y += SCREEN_HEIGHT / 2
when DOWN then canvas.y -= SCREEN_HEIGHT / 2
when :z then shift ? self.redo : undo if ctrl || cmd
when :b then brush.click
when :l then line.click
when :r then (shift ? fill_rect : stroke_rect).click
end
end
|
#redo(flash: true) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/reight/app/map/editor.rb', line 96
def redo(flash: true)
history.redo do |action|
case action
in [:put_chip, x, y, id] then canvas.map.put x, y, project.chips[id]
in [:remove_chip, x, y, id] then canvas.map.remove x, y
in [ :select, _, sel] then canvas.select(*sel)
in [:deselect, _] then canvas.deselect
end
self.flash 'Redo!' if flash
end
end
|
#setup ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/reight/app/map/editor.rb', line 18
def setup()
super
history.disable do
tools[0].click
chip_sizes[0].click
end
end
|
#undo(flash: true) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/reight/app/map/editor.rb', line 84
def undo(flash: true)
history.undo do |action|
case action
in [:put_chip, x, y, id] then canvas.map.remove x, y
in [:remove_chip, x, y, id] then canvas.map.put x, y, project.chips[id]
in [ :select, sel, _] then sel ? canvas.select(*sel) : canvas.deselect
in [:deselect, sel] then canvas.select(*sel)
end
self.flash 'Undo!' if flash
end
end
|
#window_resized ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/reight/app/map/editor.rb', line 47
def window_resized()
super
[chip_sizes, tools].flatten.map(&:sprite)
.each {|sp| sp.w = sp.h = BUTTON_SIZE}
chips_index.sprite.tap do |sp|
sp.w, sp.h = INDEX_SIZE, BUTTON_SIZE
sp.x = SPACE
sp.y = NAVIGATOR_HEIGHT + SPACE
end
chip_sizes.reverse.map {_1.sprite}.each.with_index do |sp, index|
sp.x = SPACE + CHIPS_WIDTH - (sp.w + (sp.w + 1) * index)
sp.y = chips_index.sprite.y
end
chips.sprite.tap do |sp|
sp.x = SPACE
sp.y = chip_sizes.last.sprite.bottom + SPACE
sp.right = chip_sizes.last.sprite.right
sp.bottom = height - SPACE
end
map_index.sprite.tap do |sp|
sp.w, sp.h = INDEX_SIZE, BUTTON_SIZE
sp.x = chip_sizes.last.sprite.right + SPACE
sp.y = chip_sizes.last.sprite.y
end
tools.map {_1.sprite}.each.with_index do |sp, index|
sp.x = chips.sprite.right + SPACE + (sp.w + 1) * index
sp.y = height - (SPACE + sp.h)
end
canvas.sprite.tap do |sp|
sp.x = map_index.sprite.x
sp.y = map_index.sprite.bottom + SPACE
sp.right = width - SPACE
sp.bottom = tools.first.sprite.top - SPACE
end
end
|