cyberarm_engine 0.19.0 → 0.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/LICENSE.txt +21 -21
  7. data/README.md +74 -74
  8. data/Rakefile +10 -10
  9. data/bin/console +14 -14
  10. data/bin/setup +8 -8
  11. data/cyberarm_engine.gemspec +39 -39
  12. data/lib/cyberarm_engine/animator.rb +219 -219
  13. data/lib/cyberarm_engine/background.rb +179 -179
  14. data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
  15. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  16. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  17. data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
  18. data/lib/cyberarm_engine/cache.rb +4 -4
  19. data/lib/cyberarm_engine/common.rb +113 -113
  20. data/lib/cyberarm_engine/config_file.rb +46 -46
  21. data/lib/cyberarm_engine/console/command.rb +157 -157
  22. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  23. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  24. data/lib/cyberarm_engine/console.rb +248 -248
  25. data/lib/cyberarm_engine/game_object.rb +248 -248
  26. data/lib/cyberarm_engine/game_state.rb +97 -97
  27. data/lib/cyberarm_engine/model/material.rb +21 -21
  28. data/lib/cyberarm_engine/model/model_object.rb +131 -131
  29. data/lib/cyberarm_engine/model/parser.rb +74 -74
  30. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  31. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  32. data/lib/cyberarm_engine/model.rb +212 -212
  33. data/lib/cyberarm_engine/model_cache.rb +31 -31
  34. data/lib/cyberarm_engine/opengl/light.rb +50 -50
  35. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  36. data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
  37. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  38. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
  39. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
  40. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
  41. data/lib/cyberarm_engine/opengl/shader.rb +406 -406
  42. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  43. data/lib/cyberarm_engine/opengl.rb +28 -28
  44. data/lib/cyberarm_engine/ray.rb +56 -56
  45. data/lib/cyberarm_engine/stats.rb +21 -21
  46. data/lib/cyberarm_engine/text.rb +197 -197
  47. data/lib/cyberarm_engine/timer.rb +23 -23
  48. data/lib/cyberarm_engine/transform.rb +296 -296
  49. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  50. data/lib/cyberarm_engine/ui/dsl.rb +139 -139
  51. data/lib/cyberarm_engine/ui/element.rb +488 -488
  52. data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
  53. data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
  54. data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
  55. data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
  56. data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
  57. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  58. data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
  59. data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
  60. data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
  61. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  62. data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
  63. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  64. data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
  65. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
  66. data/lib/cyberarm_engine/ui/event.rb +54 -54
  67. data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
  68. data/lib/cyberarm_engine/ui/style.rb +49 -49
  69. data/lib/cyberarm_engine/ui/theme.rb +207 -207
  70. data/lib/cyberarm_engine/vector.rb +293 -293
  71. data/lib/cyberarm_engine/version.rb +4 -4
  72. data/lib/cyberarm_engine/window.rb +120 -120
  73. data/lib/cyberarm_engine.rb +71 -71
  74. metadata +3 -3
@@ -1,248 +1,248 @@
1
- # frozen_string_literal: true
2
-
3
- module CyberarmEngine
4
- class Console
5
- Z = 100_000
6
- PADDING = 2
7
- include Common
8
-
9
- attr_reader :text_input
10
-
11
- def initialize(font: Gosu.default_font_name)
12
- @text_input = Gosu::TextInput.new
13
- @width = window.width / 4 * 3
14
- @height = window.height / 4 * 3
15
-
16
- @input = Text.new("", x: 4, y: @height - (PADDING * 2), z: Console::Z + 1, font: font)
17
- @input.y -= @input.height
18
-
19
- @history = Text.new("", x: 4, z: Console::Z + 1, font: font, border: true, border_color: Gosu::Color::BLACK)
20
- update_history_y
21
-
22
- @command_history = []
23
- @command_history_index = 0
24
-
25
- @memory = ""
26
-
27
- @background_color = Gosu::Color.rgba(0, 0, 0, 200)
28
- @foreground_color = Gosu::Color.rgba(100, 100, 100, 100)
29
- @input_color = Gosu::Color.rgba(100, 100, 100, 200)
30
-
31
- @showing_cursor = false
32
- @active_text_input = nil
33
-
34
- @show_caret = true
35
- @caret_last_change = Gosu.milliseconds
36
- @caret_interval = 250
37
- @caret_color = Gosu::Color::WHITE
38
- @selection_color = Gosu::Color.new(0x5522ff22)
39
- end
40
-
41
- def draw
42
- # Background/Border
43
- draw_rect(0, 0, @width, @height, @background_color, Console::Z)
44
- # Foregound/History
45
- draw_rect(PADDING, PADDING, @width - (PADDING * 2), @height - (PADDING * 2), @foreground_color, Console::Z)
46
- # Text bar
47
- draw_rect(2, @input.y, @width - (PADDING * 2), @input.height, @input_color, Console::Z)
48
-
49
- @history.draw
50
- @input.draw
51
- # Caret
52
- if @show_caret
53
- draw_rect(@input.x + caret_from_left, @input.y, Console::PADDING, @input.height, @caret_color, Console::Z + 2)
54
- end
55
- # Caret selection
56
- if caret_start != caret_end
57
- if caret_start < @text_input.selection_start
58
- draw_rect(@input.x + caret_from_left, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
59
- else
60
- draw_rect((@input.x + caret_from_left) - caret_selection_width, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
61
- end
62
- end
63
- end
64
-
65
- def caret_from_left
66
- return 0 if @text_input.caret_pos.zero?
67
-
68
- @input.textobject.text_width(@text_input.text[0..@text_input.caret_pos - 1])
69
- end
70
-
71
- def caret_selection_width
72
- @input.textobject.text_width(@text_input.text[caret_start..(caret_end - 1)])
73
- end
74
-
75
- def caret_pos
76
- @text_input.caret_pos
77
- end
78
-
79
- def caret_start
80
- @text_input.selection_start < @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
81
- end
82
-
83
- def caret_end
84
- @text_input.selection_start > @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
85
- end
86
-
87
- def update
88
- if Gosu.milliseconds - @caret_last_change >= @caret_interval
89
- @caret_last_change = Gosu.milliseconds
90
- @show_caret = !@show_caret
91
- end
92
-
93
- if @width != window.width || @height != @height
94
- @width = window.width / 4 * 3
95
- @height = window.height / 4 * 3
96
-
97
- @input.y = @height - (PADDING * 2 + @input.height)
98
- update_history_y
99
- end
100
-
101
- @input.text = @text_input.text
102
- end
103
-
104
- def button_down(id)
105
- case id
106
- when Gosu::KbEnter, Gosu::KbReturn
107
- return unless @text_input.text.length.positive?
108
-
109
- @history.text += "\n<c=999999>> #{@text_input.text}</c>"
110
- @command_history << @text_input.text
111
- @command_history_index = @command_history.size
112
- update_history_y
113
- handle_command
114
- @text_input.text = ""
115
-
116
- when Gosu::KbUp
117
- @command_history_index -= 1
118
- @command_history_index = 0 if @command_history_index.negative?
119
- @text_input.text = @command_history[@command_history_index]
120
-
121
- when Gosu::KbDown
122
- @command_history_index += 1
123
- if @command_history_index > @command_history.size - 1
124
- @text_input.text = "" unless @command_history_index > @command_history.size
125
- @command_history_index = @command_history.size
126
- else
127
- @text_input.text = @command_history[@command_history_index]
128
- end
129
-
130
- when Gosu::KbTab
131
- split = @text_input.text.split(" ")
132
-
133
- if !@text_input.text.end_with?(" ") && split.size == 1
134
- list = abbrev_search(Console::Command.list_commands.map { |cmd| cmd.command.to_s }, @text_input.text)
135
-
136
- if list.size == 1
137
- @text_input.text = "#{list.first} "
138
- elsif list.size.positive?
139
- stdin("\n#{list.map { |cmd| Console::Style.highlight(cmd) }.join(', ')}")
140
- end
141
- elsif split.size.positive? && cmd = Console::Command.find(split.first)
142
- cmd.autocomplete(self)
143
- end
144
-
145
- when Gosu::KbBacktick
146
- # Remove backtick character from input
147
- @text_input.text = if @text_input.text.size > 1
148
- @text_input.text[0..@text_input.text.size - 2]
149
- else
150
- ""
151
- end
152
-
153
- # Copy
154
- when Gosu::KbC
155
- if control_down? && shift_down?
156
- @memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
157
- p @memory
158
- elsif control_down?
159
- @text_input.text = ""
160
- end
161
-
162
- # Paste
163
- when Gosu::KbV
164
- if control_down? && shift_down?
165
- string = @text_input.text.chars.insert(caret_pos, @memory).join
166
- _caret_pos = caret_pos
167
- @text_input.text = string
168
- @text_input.caret_pos = _caret_pos + @memory.length
169
- @text_input.selection_start = _caret_pos + @memory.length
170
- end
171
-
172
- # Cut
173
- when Gosu::KbX
174
- if control_down? && shift_down?
175
- @memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
176
- string = @text_input.text.chars
177
- Array(caret_start..caret_end - 1).each_with_index do |i, j|
178
- string.delete_at(i - j)
179
- end
180
-
181
- @text_input.text = string.join
182
- end
183
-
184
- # Delete word to left of caret
185
- when Gosu::KbW
186
- if control_down?
187
- split = @text_input.text.split(" ")
188
- split.delete(split.last)
189
- @text_input.text = split.join(" ")
190
- end
191
-
192
- # Clear history
193
- when Gosu::KbL
194
- @history.text = "" if control_down?
195
- end
196
- end
197
-
198
- def button_up(id)
199
- end
200
-
201
- def update_history_y
202
- @history.y = @height - (PADDING * 2) - @input.height - (@history.text.lines.count * @history.textobject.height)
203
- end
204
-
205
- def handle_command
206
- string = @text_input.text
207
- split = string.split(" ")
208
- command = split.first
209
- arguments = split.length.positive? ? split[1..split.length - 1] : []
210
-
211
- CyberarmEngine::Console::Command.use(command, arguments, self)
212
- end
213
-
214
- def abbrev_search(array, text)
215
- return [] unless text.length.positive?
216
-
217
- list = []
218
- Abbrev.abbrev(array).each do |abbrev, value|
219
- next unless abbrev&.start_with?(text)
220
-
221
- list << value
222
- end
223
-
224
- list.uniq
225
- end
226
-
227
- def stdin(string)
228
- @history.text += "\n#{string}"
229
- update_history_y
230
- end
231
-
232
- def focus
233
- @active_text_input = window.text_input
234
- window.text_input = @text_input
235
-
236
- @showing_cursor = window.needs_cursor
237
- window.needs_cursor = true
238
-
239
- @show_caret = true
240
- @caret_last_change = Gosu.milliseconds
241
- end
242
-
243
- def blur
244
- window.text_input = @active_text_input
245
- window.needs_cursor = @showing_cursor
246
- end
247
- end
248
- end
1
+ # frozen_string_literal: true
2
+
3
+ module CyberarmEngine
4
+ class Console
5
+ Z = 100_000
6
+ PADDING = 2
7
+ include Common
8
+
9
+ attr_reader :text_input
10
+
11
+ def initialize(font: Gosu.default_font_name)
12
+ @text_input = Gosu::TextInput.new
13
+ @width = window.width / 4 * 3
14
+ @height = window.height / 4 * 3
15
+
16
+ @input = Text.new("", x: 4, y: @height - (PADDING * 2), z: Console::Z + 1, font: font)
17
+ @input.y -= @input.height
18
+
19
+ @history = Text.new("", x: 4, z: Console::Z + 1, font: font, border: true, border_color: Gosu::Color::BLACK)
20
+ update_history_y
21
+
22
+ @command_history = []
23
+ @command_history_index = 0
24
+
25
+ @memory = ""
26
+
27
+ @background_color = Gosu::Color.rgba(0, 0, 0, 200)
28
+ @foreground_color = Gosu::Color.rgba(100, 100, 100, 100)
29
+ @input_color = Gosu::Color.rgba(100, 100, 100, 200)
30
+
31
+ @showing_cursor = false
32
+ @active_text_input = nil
33
+
34
+ @show_caret = true
35
+ @caret_last_change = Gosu.milliseconds
36
+ @caret_interval = 250
37
+ @caret_color = Gosu::Color::WHITE
38
+ @selection_color = Gosu::Color.new(0x5522ff22)
39
+ end
40
+
41
+ def draw
42
+ # Background/Border
43
+ draw_rect(0, 0, @width, @height, @background_color, Console::Z)
44
+ # Foregound/History
45
+ draw_rect(PADDING, PADDING, @width - (PADDING * 2), @height - (PADDING * 2), @foreground_color, Console::Z)
46
+ # Text bar
47
+ draw_rect(2, @input.y, @width - (PADDING * 2), @input.height, @input_color, Console::Z)
48
+
49
+ @history.draw
50
+ @input.draw
51
+ # Caret
52
+ if @show_caret
53
+ draw_rect(@input.x + caret_from_left, @input.y, Console::PADDING, @input.height, @caret_color, Console::Z + 2)
54
+ end
55
+ # Caret selection
56
+ if caret_start != caret_end
57
+ if caret_start < @text_input.selection_start
58
+ draw_rect(@input.x + caret_from_left, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
59
+ else
60
+ draw_rect((@input.x + caret_from_left) - caret_selection_width, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
61
+ end
62
+ end
63
+ end
64
+
65
+ def caret_from_left
66
+ return 0 if @text_input.caret_pos.zero?
67
+
68
+ @input.textobject.text_width(@text_input.text[0..@text_input.caret_pos - 1])
69
+ end
70
+
71
+ def caret_selection_width
72
+ @input.textobject.text_width(@text_input.text[caret_start..(caret_end - 1)])
73
+ end
74
+
75
+ def caret_pos
76
+ @text_input.caret_pos
77
+ end
78
+
79
+ def caret_start
80
+ @text_input.selection_start < @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
81
+ end
82
+
83
+ def caret_end
84
+ @text_input.selection_start > @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
85
+ end
86
+
87
+ def update
88
+ if Gosu.milliseconds - @caret_last_change >= @caret_interval
89
+ @caret_last_change = Gosu.milliseconds
90
+ @show_caret = !@show_caret
91
+ end
92
+
93
+ if @width != window.width || @height != @height
94
+ @width = window.width / 4 * 3
95
+ @height = window.height / 4 * 3
96
+
97
+ @input.y = @height - (PADDING * 2 + @input.height)
98
+ update_history_y
99
+ end
100
+
101
+ @input.text = @text_input.text
102
+ end
103
+
104
+ def button_down(id)
105
+ case id
106
+ when Gosu::KbEnter, Gosu::KbReturn
107
+ return unless @text_input.text.length.positive?
108
+
109
+ @history.text += "\n<c=999999>> #{@text_input.text}</c>"
110
+ @command_history << @text_input.text
111
+ @command_history_index = @command_history.size
112
+ update_history_y
113
+ handle_command
114
+ @text_input.text = ""
115
+
116
+ when Gosu::KbUp
117
+ @command_history_index -= 1
118
+ @command_history_index = 0 if @command_history_index.negative?
119
+ @text_input.text = @command_history[@command_history_index]
120
+
121
+ when Gosu::KbDown
122
+ @command_history_index += 1
123
+ if @command_history_index > @command_history.size - 1
124
+ @text_input.text = "" unless @command_history_index > @command_history.size
125
+ @command_history_index = @command_history.size
126
+ else
127
+ @text_input.text = @command_history[@command_history_index]
128
+ end
129
+
130
+ when Gosu::KbTab
131
+ split = @text_input.text.split(" ")
132
+
133
+ if !@text_input.text.end_with?(" ") && split.size == 1
134
+ list = abbrev_search(Console::Command.list_commands.map { |cmd| cmd.command.to_s }, @text_input.text)
135
+
136
+ if list.size == 1
137
+ @text_input.text = "#{list.first} "
138
+ elsif list.size.positive?
139
+ stdin("\n#{list.map { |cmd| Console::Style.highlight(cmd) }.join(', ')}")
140
+ end
141
+ elsif split.size.positive? && cmd = Console::Command.find(split.first)
142
+ cmd.autocomplete(self)
143
+ end
144
+
145
+ when Gosu::KbBacktick
146
+ # Remove backtick character from input
147
+ @text_input.text = if @text_input.text.size > 1
148
+ @text_input.text[0..@text_input.text.size - 2]
149
+ else
150
+ ""
151
+ end
152
+
153
+ # Copy
154
+ when Gosu::KbC
155
+ if control_down? && shift_down?
156
+ @memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
157
+ p @memory
158
+ elsif control_down?
159
+ @text_input.text = ""
160
+ end
161
+
162
+ # Paste
163
+ when Gosu::KbV
164
+ if control_down? && shift_down?
165
+ string = @text_input.text.chars.insert(caret_pos, @memory).join
166
+ _caret_pos = caret_pos
167
+ @text_input.text = string
168
+ @text_input.caret_pos = _caret_pos + @memory.length
169
+ @text_input.selection_start = _caret_pos + @memory.length
170
+ end
171
+
172
+ # Cut
173
+ when Gosu::KbX
174
+ if control_down? && shift_down?
175
+ @memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
176
+ string = @text_input.text.chars
177
+ Array(caret_start..caret_end - 1).each_with_index do |i, j|
178
+ string.delete_at(i - j)
179
+ end
180
+
181
+ @text_input.text = string.join
182
+ end
183
+
184
+ # Delete word to left of caret
185
+ when Gosu::KbW
186
+ if control_down?
187
+ split = @text_input.text.split(" ")
188
+ split.delete(split.last)
189
+ @text_input.text = split.join(" ")
190
+ end
191
+
192
+ # Clear history
193
+ when Gosu::KbL
194
+ @history.text = "" if control_down?
195
+ end
196
+ end
197
+
198
+ def button_up(id)
199
+ end
200
+
201
+ def update_history_y
202
+ @history.y = @height - (PADDING * 2) - @input.height - (@history.text.lines.count * @history.textobject.height)
203
+ end
204
+
205
+ def handle_command
206
+ string = @text_input.text
207
+ split = string.split(" ")
208
+ command = split.first
209
+ arguments = split.length.positive? ? split[1..split.length - 1] : []
210
+
211
+ CyberarmEngine::Console::Command.use(command, arguments, self)
212
+ end
213
+
214
+ def abbrev_search(array, text)
215
+ return [] unless text.length.positive?
216
+
217
+ list = []
218
+ Abbrev.abbrev(array).each do |abbrev, value|
219
+ next unless abbrev&.start_with?(text)
220
+
221
+ list << value
222
+ end
223
+
224
+ list.uniq
225
+ end
226
+
227
+ def stdin(string)
228
+ @history.text += "\n#{string}"
229
+ update_history_y
230
+ end
231
+
232
+ def focus
233
+ @active_text_input = window.text_input
234
+ window.text_input = @text_input
235
+
236
+ @showing_cursor = window.needs_cursor
237
+ window.needs_cursor = true
238
+
239
+ @show_caret = true
240
+ @caret_last_change = Gosu.milliseconds
241
+ end
242
+
243
+ def blur
244
+ window.text_input = @active_text_input
245
+ window.needs_cursor = @showing_cursor
246
+ end
247
+ end
248
+ end