cyberarm_engine 0.25.0 → 0.30.0

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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/Gemfile.lock +37 -25
  7. data/LICENSE.txt +21 -21
  8. data/README.md +74 -74
  9. data/Rakefile +10 -10
  10. data/assets/shaders/fragment/g_buffer.glsl +30 -30
  11. data/assets/shaders/fragment/lighting.glsl +115 -115
  12. data/assets/shaders/include/light_struct.glsl +11 -11
  13. data/assets/shaders/include/material_struct.glsl +16 -16
  14. data/assets/shaders/vertex/g_buffer.glsl +28 -28
  15. data/assets/shaders/vertex/lighting.glsl +24 -24
  16. data/assets/textures/ui/circle.png +0 -0
  17. data/assets/textures/ui/circle_small.png +0 -0
  18. data/assets/textures/ui/rounded.png +0 -0
  19. data/assets/textures/ui/rounded_bottom.png +0 -0
  20. data/assets/textures/ui/rounded_left.png +0 -0
  21. data/assets/textures/ui/rounded_left_bottom.png +0 -0
  22. data/assets/textures/ui/rounded_left_top.png +0 -0
  23. data/assets/textures/ui/rounded_right.png +0 -0
  24. data/assets/textures/ui/rounded_right_bottom.png +0 -0
  25. data/assets/textures/ui/rounded_right_top.png +0 -0
  26. data/assets/textures/ui/rounded_small.png +0 -0
  27. data/assets/textures/ui/rounded_tiny.png +0 -0
  28. data/assets/textures/ui/rounded_top.png +0 -0
  29. data/assets/textures/ui/square.png +0 -0
  30. data/bin/console +14 -14
  31. data/bin/setup +8 -8
  32. data/cyberarm_engine.gemspec +35 -36
  33. data/lib/cyberarm_engine/animator.rb +219 -219
  34. data/lib/cyberarm_engine/background.rb +156 -158
  35. data/lib/cyberarm_engine/background_image.rb +93 -93
  36. data/lib/cyberarm_engine/background_nine_slice.rb +182 -142
  37. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  38. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  39. data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
  40. data/lib/cyberarm_engine/cache.rb +4 -4
  41. data/lib/cyberarm_engine/common.rb +133 -131
  42. data/lib/cyberarm_engine/config_file.rb +46 -46
  43. data/lib/cyberarm_engine/console/command.rb +157 -157
  44. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  45. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  46. data/lib/cyberarm_engine/console.rb +248 -248
  47. data/lib/cyberarm_engine/event_bus.rb +39 -0
  48. data/lib/cyberarm_engine/game_object.rb +244 -244
  49. data/lib/cyberarm_engine/game_state.rb +134 -124
  50. data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +111 -111
  51. data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
  52. data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
  53. data/lib/cyberarm_engine/model/material.rb +21 -21
  54. data/lib/cyberarm_engine/model/mesh.rb +131 -131
  55. data/lib/cyberarm_engine/model/parser.rb +74 -74
  56. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  57. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  58. data/lib/cyberarm_engine/model.rb +216 -216
  59. data/lib/cyberarm_engine/model_cache.rb +31 -31
  60. data/lib/cyberarm_engine/notification.rb +82 -82
  61. data/lib/cyberarm_engine/notification_manager.rb +241 -241
  62. data/lib/cyberarm_engine/opengl/light.rb +52 -52
  63. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  64. data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -41
  65. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  66. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -167
  67. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -307
  68. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
  69. data/lib/cyberarm_engine/opengl/shader.rb +408 -408
  70. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  71. data/lib/cyberarm_engine/opengl.rb +53 -53
  72. data/lib/cyberarm_engine/pathfinding/graph.rb +64 -0
  73. data/lib/cyberarm_engine/pathfinding/graph_search.rb +6 -0
  74. data/lib/cyberarm_engine/pathfinding/graph_searches/astar_search.rb +6 -0
  75. data/lib/cyberarm_engine/pathfinding/graph_searches/breadth_first_search.rb +27 -0
  76. data/lib/cyberarm_engine/pathfinding/graph_searches/dijkstra_search.rb +6 -0
  77. data/lib/cyberarm_engine/pathfinding/graphs/grid.rb +52 -0
  78. data/lib/cyberarm_engine/ray.rb +56 -56
  79. data/lib/cyberarm_engine/result.rb +19 -0
  80. data/lib/cyberarm_engine/stats.rb +200 -200
  81. data/lib/cyberarm_engine/text.rb +288 -260
  82. data/lib/cyberarm_engine/timer.rb +27 -23
  83. data/lib/cyberarm_engine/transform.rb +296 -296
  84. data/lib/cyberarm_engine/trees/aabb_node.rb +126 -126
  85. data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -55
  86. data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -29
  87. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  88. data/lib/cyberarm_engine/ui/dialog.rb +24 -0
  89. data/lib/cyberarm_engine/ui/dsl.rb +170 -142
  90. data/lib/cyberarm_engine/ui/element.rb +664 -662
  91. data/lib/cyberarm_engine/ui/elements/button.rb +99 -100
  92. data/lib/cyberarm_engine/ui/elements/check_box.rb +58 -54
  93. data/lib/cyberarm_engine/ui/elements/container.rb +413 -407
  94. data/lib/cyberarm_engine/ui/elements/edit_box.rb +200 -179
  95. data/lib/cyberarm_engine/ui/elements/edit_line.rb +299 -297
  96. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  97. data/lib/cyberarm_engine/ui/elements/image.rb +78 -72
  98. data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
  99. data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
  100. data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
  101. data/lib/cyberarm_engine/ui/elements/progress.rb +95 -93
  102. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  103. data/lib/cyberarm_engine/ui/elements/slider.rb +111 -107
  104. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  105. data/lib/cyberarm_engine/ui/elements/text_block.rb +236 -222
  106. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +71 -67
  107. data/lib/cyberarm_engine/ui/elements/widget.rb +45 -0
  108. data/lib/cyberarm_engine/ui/event.rb +54 -54
  109. data/lib/cyberarm_engine/ui/gui_state.rb +402 -326
  110. data/lib/cyberarm_engine/ui/page.rb +39 -0
  111. data/lib/cyberarm_engine/ui/style.rb +94 -61
  112. data/lib/cyberarm_engine/ui/theme.rb +237 -225
  113. data/lib/cyberarm_engine/vector.rb +312 -312
  114. data/lib/cyberarm_engine/version.rb +4 -4
  115. data/lib/cyberarm_engine/window.rb +234 -195
  116. data/lib/cyberarm_engine.rb +88 -76
  117. data/mrbgem.rake +29 -29
  118. metadata +30 -5
@@ -1,179 +1,200 @@
1
- module CyberarmEngine
2
- class Element
3
- class EditBox < EditLine
4
- def initialize(*args)
5
- super(*args)
6
-
7
- @active_line = 0
8
-
9
- @repeatable_keys = [
10
- {
11
- key: Gosu::KB_UP,
12
- down: false,
13
- repeat_delay: 50,
14
- last_repeat: 0,
15
- action: proc { move(:up) }
16
- },
17
- {
18
- key: Gosu::KB_DOWN,
19
- down: false,
20
- repeat_delay: 50,
21
- last_repeat: 0,
22
- action: proc { move(:down) }
23
- }
24
- ]
25
- end
26
-
27
- def update
28
- super
29
-
30
- caret_stay_left_of_last_newline
31
- calculate_active_line
32
-
33
- @repeatable_keys.each do |key|
34
- if key[:down] && (Gosu.milliseconds > key[:last_repeat] + key[:repeat_delay])
35
- key[:action].call
36
- key[:last_repeat] = Gosu.milliseconds
37
- end
38
- end
39
- end
40
-
41
- def draw_caret
42
- Gosu.draw_rect(caret_position, @text.y + @active_line * @text.textobject.height, @caret_width, @caret_height,
43
- @caret_color, @z)
44
- end
45
-
46
- def draw_selection
47
- selection_width = caret_position - selection_start_position
48
-
49
- Gosu.draw_rect(selection_start_position, @text.y, selection_width, @text.textobject.height,
50
- default(:selection_color), @z)
51
- end
52
-
53
- def text_input_position_for(_method)
54
- line = @text_input.text[0...@text_input.caret_pos].lines.last
55
- _x = @text.x + @offset_x
56
-
57
- if @type == :password
58
- _x + @text.width(default(:password_character) * line.length)
59
- else
60
- _x + @text.width(line)
61
- end
62
- end
63
-
64
- def set_position(int)
65
- int = 0 if int < 0
66
- @text_input.selection_start = @text_input.caret_pos = int
67
- end
68
-
69
- def calculate_active_line
70
- sub_text = @text_input.text[0...@text_input.caret_pos]
71
- @active_line = sub_text.lines.size - 1
72
- end
73
-
74
- def caret_stay_left_of_last_newline
75
- @text_input.text += "\n" unless @text_input.text.end_with?("\n")
76
-
77
- eof = @text_input.text.chomp.length
78
- set_position(eof) if @text_input.caret_pos > eof
79
- end
80
-
81
- def caret_position_under_mouse(mouse_x, mouse_y)
82
- active_line = row_at(mouse_y)
83
- right_offset = column_at(mouse_x, mouse_y)
84
-
85
- buffer = @text_input.text.lines[0..active_line].join if active_line != 0
86
- buffer = @text_input.text.lines.first if active_line == 0
87
- line = buffer.lines.last
88
-
89
- if buffer.chars.last == "\n"
90
- (buffer.length - line.length) + right_offset - 1
91
- else
92
- (buffer.length - line.length) + right_offset
93
- end
94
- end
95
-
96
- def move_caret_to_mouse(mouse_x, mouse_y)
97
- set_position(caret_position_under_mouse(mouse_x, mouse_y))
98
- end
99
-
100
- def row_at(y)
101
- ((y - @text.y) / @text.textobject.height).floor
102
- end
103
-
104
- def column_at(x, y)
105
- row = row_at(y)
106
-
107
- buffer = @text_input.text.lines[0..row].join if row != 0
108
- buffer = @text_input.text.lines.first if row == 0
109
-
110
- line = @text_input.text.lines[row]
111
- line ||= ""
112
- column = 0
113
-
114
- line.length.times do |_i|
115
- break if @text.textobject.text_width(line[0...column]) >= (x - @text.x).clamp(0.0, Float::INFINITY)
116
-
117
- column += 1
118
- end
119
-
120
- column
121
- end
122
-
123
- def button_down(id)
124
- super
125
-
126
- @repeatable_keys.detect do |key|
127
- next unless key[:key] == id
128
-
129
- key[:down] = true
130
- key[:last_repeat] = Gosu.milliseconds + key[:repeat_delay]
131
- return true
132
- end
133
-
134
- case id
135
- when Gosu::KB_ENTER, Gosu::KB_RETURN
136
- caret_pos = @text_input.caret_pos
137
- @text_input.text = @text_input.text.insert(@text_input.caret_pos, "\n")
138
- @text_input.caret_pos = @text_input.selection_start = caret_pos + 1
139
- end
140
- end
141
-
142
- def button_up(id)
143
- super
144
-
145
- @repeatable_keys.detect do |key|
146
- if key[:key] == id
147
- key[:down] = false
148
- return true
149
- end
150
- end
151
- end
152
-
153
- def move(direction)
154
- pos = @text_input.caret_pos
155
- line = nil
156
-
157
- case direction
158
- when :up
159
- return if @active_line == 0
160
- when :down
161
- return if @active_line == @text_input.text.chomp.lines
162
-
163
- text = @text_input.text.chomp.lines[0..@active_line].join("\n")
164
- pos = text.length
165
- end
166
-
167
- set_position(pos)
168
- end
169
-
170
- def drag_update(_sender, x, y, _button)
171
- int = caret_position_under_mouse(x, y)
172
- int = 0 if int < 0
173
- @text_input.caret_pos = int
174
-
175
- :handled
176
- end
177
- end
178
- end
179
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class EditBox < EditLine
4
+ def initialize(*args)
5
+ super(*args)
6
+
7
+ @active_line = 0
8
+
9
+ @repeatable_keys = [
10
+ {
11
+ key: Gosu::KB_UP,
12
+ down: false,
13
+ repeat_delay: 50,
14
+ last_repeat: 0,
15
+ action: proc { move(:up) }
16
+ },
17
+ {
18
+ key: Gosu::KB_DOWN,
19
+ down: false,
20
+ repeat_delay: 50,
21
+ last_repeat: 0,
22
+ action: proc { move(:down) }
23
+ }
24
+ ]
25
+ end
26
+
27
+ def update
28
+ super
29
+
30
+ caret_stay_left_of_last_newline
31
+ calculate_active_line
32
+
33
+ @repeatable_keys.each do |key|
34
+ if key[:down] && (Gosu.milliseconds > key[:last_repeat] + key[:repeat_delay])
35
+ key[:action].call
36
+ key[:last_repeat] = Gosu.milliseconds
37
+ end
38
+ end
39
+ end
40
+
41
+ def draw_caret
42
+ Gosu.draw_rect(caret_position, @text.y + @active_line * @text.textobject.height, @caret_width, @caret_height,
43
+ @caret_color, @z)
44
+ end
45
+
46
+ def draw_selection
47
+ selection_width = caret_position - selection_start_position
48
+ selection_start_line = calculate_line(@text_input.caret_pos)
49
+ selection_end_line = calculate_line(@text_input.selection_start)
50
+
51
+ # pp [selection_width, selection_start_line, selection_end_line]
52
+
53
+ Gosu.draw_rect(selection_start_position, @text.y + selection_start_line * @text.textobject.height, selection_width, @text.textobject.height,
54
+ default(:selection_color), @z)
55
+ end
56
+
57
+ def text_input_position_for(method)
58
+ line = @text_input.text[0...@text_input.send(method)].lines.last
59
+ _x = @text.x + @offset_x
60
+
61
+ if @type == :password
62
+ _x + @text.width(default(:password_character) * line.length) - @style.border_thickness_left
63
+ else
64
+ _x + @text.width(line) - @style.border_thickness_left
65
+ end
66
+ end
67
+
68
+ def set_position(int)
69
+ int = 0 if int < 0
70
+ @text_input.selection_start = @text_input.caret_pos = int
71
+ end
72
+
73
+ def calculate_line(caret_pos = @text_input.caret_pos)
74
+ sub_text = @text_input.text[0...caret_pos].lines.size - 1
75
+ end
76
+
77
+ def calculate_active_line
78
+ @active_line = calculate_line(@text_input.caret_pos)
79
+ end
80
+
81
+ def caret_stay_left_of_last_newline
82
+ @text_input.text += "\n" unless @text_input.text.end_with?("\n")
83
+
84
+ eof = @text_input.text.chomp.length
85
+ set_position(eof) if @text_input.caret_pos > eof
86
+ end
87
+
88
+ def caret_position_under_mouse(mouse_x, mouse_y)
89
+ # get y scroll offset of element to get EditBox's selected row
90
+ y_scroll_offset = 0
91
+ e = parent
92
+ while (e)
93
+ if e.is_a?(Container)
94
+ y_scroll_offset += e.scroll_position.y
95
+
96
+ # root element has no parent so loop will terminate
97
+ e = e.parent
98
+ end
99
+ end
100
+
101
+ active_line = row_at(mouse_y - y_scroll_offset)
102
+ right_offset = column_at(mouse_x, mouse_y - y_scroll_offset)
103
+
104
+ buffer = @text_input.text.lines[0..active_line].join if active_line != 0
105
+ buffer = @text_input.text.lines.first if active_line == 0
106
+ line = buffer.lines.last
107
+
108
+ if buffer.chars.last == "\n"
109
+ (buffer.length - line.length) + right_offset - 1
110
+ else
111
+ (buffer.length - line.length) + right_offset
112
+ end
113
+ end
114
+
115
+ def move_caret_to_mouse(mouse_x, mouse_y)
116
+ set_position(caret_position_under_mouse(mouse_x, mouse_y))
117
+ end
118
+
119
+ def row_at(y)
120
+ ((y - @text.y) / @text.textobject.height).floor
121
+ end
122
+
123
+ def column_at(x, y)
124
+ row = row_at(y)
125
+
126
+ buffer = @text_input.text.lines[0..row].join if row != 0
127
+ buffer = @text_input.text.lines.first if row == 0
128
+
129
+ line = @text_input.text.lines[row]
130
+ line ||= ""
131
+ column = 0
132
+
133
+ line.length.times do |_i|
134
+ break if @text.textobject.text_width(line[0...column]) >= (x - @text.x).clamp(0.0, Float::INFINITY)
135
+
136
+ column += 1
137
+ end
138
+
139
+ column
140
+ end
141
+
142
+ def button_down(id)
143
+ super
144
+
145
+ @repeatable_keys.detect do |key|
146
+ next unless key[:key] == id
147
+
148
+ key[:down] = true
149
+ key[:last_repeat] = Gosu.milliseconds + key[:repeat_delay]
150
+ return true
151
+ end
152
+
153
+ case id
154
+ when Gosu::KB_ENTER, Gosu::KB_RETURN
155
+ caret_pos = @text_input.caret_pos
156
+ @text_input.text = @text_input.text.insert(@text_input.caret_pos, "\n")
157
+ @text_input.caret_pos = @text_input.selection_start = caret_pos + 1
158
+ end
159
+ end
160
+
161
+ def button_up(id)
162
+ super
163
+
164
+ @repeatable_keys.detect do |key|
165
+ if key[:key] == id
166
+ key[:down] = false
167
+ return true
168
+ end
169
+ end
170
+ end
171
+
172
+ def move(direction)
173
+ pos = @text_input.caret_pos
174
+ line = nil
175
+
176
+ case direction
177
+ when :up
178
+ return if @active_line == 0
179
+ when :down
180
+ return if @active_line == @text_input.text.chomp.lines
181
+
182
+ text = @text_input.text.chomp.lines[0..@active_line].join("\n")
183
+ pos = text.length
184
+ end
185
+
186
+ pp [direction, pos, @active_line]
187
+
188
+ set_position(pos)
189
+ end
190
+
191
+ def drag_update(_sender, x, y, _button)
192
+ int = caret_position_under_mouse(x, y)
193
+ int = 0 if int < 0
194
+ @text_input.caret_pos = int
195
+
196
+ :handled
197
+ end
198
+ end
199
+ end
200
+ end