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,197 +1,197 @@
1
- module CyberarmEngine
2
- class Text
3
- CACHE = {}
4
-
5
- attr_accessor :x, :y, :z, :size, :options
6
- attr_reader :text, :textobject, :factor_x, :factor_y, :color,
7
- :border, :border_size, :border_alpha, :border_color,
8
- :shadow, :shadow_size, :shadow_alpha, :shadow_color
9
-
10
- def initialize(text, options = {})
11
- @text = text.to_s || ""
12
- @options = options
13
- @size = options[:size] || 18
14
- @font = options[:font] || Gosu.default_font_name
15
- @x = options[:x] || 0
16
- @y = options[:y] || 0
17
- @z = options[:z] || 1025
18
- @factor_x = options[:factor_x] || 1
19
- @factor_y = options[:factor_y] || 1
20
- if options[:color]
21
- @color = options[:color].is_a?(Gosu::Color) ? options[:color] : Gosu::Color.new(options[:color])
22
- else
23
- @color = Gosu::Color::WHITE
24
- end
25
- @mode = options[:mode] || :default
26
- @alignment = options[:alignment] || nil
27
-
28
- @border = options[:border]
29
- @border = true if options[:border].nil?
30
- @border_size = options[:border_size] || 1
31
- @border_alpha = options[:border_alpha] || 30
32
- @border_color = options[:border_color]
33
-
34
- @shadow = options[:shadow]
35
- @shadow_size = options[:shadow_size] || 2
36
- @shadow_alpha = options[:shadow_alpha] || 30
37
- @shadow_color = options[:shadow_color]
38
-
39
- @textobject = check_cache(@size, @font)
40
-
41
- if @alignment
42
- case @alignment
43
- when :left
44
- @x = 0 + BUTTON_PADDING
45
- when :center
46
- @x = ($window.width / 2) - (@textobject.text_width(@text) / 2)
47
- when :right
48
- @x = $window.width - BUTTON_PADDING - @textobject.text_width(@text)
49
- end
50
- end
51
- end
52
-
53
- def check_cache(size, font_name)
54
- available = false
55
- font = nil
56
-
57
- if CACHE[size]
58
- if CACHE[size][font_name]
59
- font = CACHE[size][font_name]
60
- available = true
61
- else
62
- available = false
63
- end
64
- else
65
- available = false
66
- end
67
-
68
- unless available
69
- font = Gosu::Font.new(@size, name: @font)
70
- CACHE[@size] = {} unless CACHE[@size].is_a?(Hash)
71
- CACHE[@size][@font] = font
72
- end
73
-
74
- font
75
- end
76
-
77
- def swap_font(size, font_name = @font)
78
- if @size != size || @font != font_name
79
- @size = size
80
- @font = font_name
81
-
82
- @textobject = check_cache(size, font_name)
83
- end
84
- end
85
-
86
- def text=(string)
87
- @rendered_border = nil
88
- @text = string
89
- end
90
-
91
- def factor_x=(n)
92
- @rendered_border = nil
93
- @factor_x = n
94
- end
95
-
96
- def factor_y=(n)
97
- @rendered_border = nil
98
- @factor_y = n
99
- end
100
-
101
- def color=(color)
102
- @rendered_border = nil
103
- if color
104
- @color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
105
- else
106
- raise "color cannot be nil"
107
- end
108
- end
109
-
110
- def border=(boolean)
111
- @rendered_border = nil
112
- @border = boolean
113
- end
114
-
115
- def border_size=(n)
116
- @rendered_border = nil
117
- @border_size = n
118
- end
119
-
120
- def border_alpha=(n)
121
- @rendered_border = nil
122
- @border_alpha = n
123
- end
124
-
125
- def border_color=(n)
126
- @rendered_border = nil
127
- @border_color = n
128
- end
129
-
130
- def width(text = @text)
131
- markup_width(text)
132
- end
133
-
134
- def text_width(text = @text)
135
- textobject.text_width(text) + @border_size + @shadow_size
136
- end
137
-
138
- def markup_width(text = @text)
139
- textobject.markup_width(text) + @border_size + @shadow_size
140
- end
141
-
142
- def height(text = @text)
143
- if text.lines.count > 0
144
- text.lines.count * textobject.height + @border_size + @shadow_size
145
- else
146
- @textobject.height + @border_size + @shadow_size
147
- end
148
- end
149
-
150
- def draw(method = :draw_markup)
151
- if @border && !ARGV.join.include?("--no-border")
152
- border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
153
- border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
154
- border_alpha)
155
- white = Gosu::Color::WHITE
156
-
157
- _x = @border_size
158
- _y = @border_size
159
- _width = method == :draw_markup ? text_width : markup_width
160
-
161
- @rendered_border ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
162
- @textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
163
- @textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
164
-
165
- @textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
166
- @textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
167
-
168
- @textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
169
- @textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
170
-
171
- @textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
172
- @textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
173
- end
174
-
175
- @rendered_border.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
176
- end
177
-
178
- if @shadow
179
- shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
180
- @textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
181
- end
182
-
183
- @textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
184
- end
185
-
186
- def alpha=(n)
187
- @color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n)
188
- end
189
-
190
- def alpha
191
- @color.alpha
192
- end
193
-
194
- def update
195
- end
196
- end
197
- end
1
+ module CyberarmEngine
2
+ class Text
3
+ CACHE = {}
4
+
5
+ attr_accessor :x, :y, :z, :size, :options
6
+ attr_reader :text, :textobject, :factor_x, :factor_y, :color,
7
+ :border, :border_size, :border_alpha, :border_color,
8
+ :shadow, :shadow_size, :shadow_alpha, :shadow_color
9
+
10
+ def initialize(text, options = {})
11
+ @text = text.to_s || ""
12
+ @options = options
13
+ @size = options[:size] || 18
14
+ @font = options[:font] || Gosu.default_font_name
15
+ @x = options[:x] || 0
16
+ @y = options[:y] || 0
17
+ @z = options[:z] || 1025
18
+ @factor_x = options[:factor_x] || 1
19
+ @factor_y = options[:factor_y] || 1
20
+ if options[:color]
21
+ @color = options[:color].is_a?(Gosu::Color) ? options[:color] : Gosu::Color.new(options[:color])
22
+ else
23
+ @color = Gosu::Color::WHITE
24
+ end
25
+ @mode = options[:mode] || :default
26
+ @alignment = options[:alignment] || nil
27
+
28
+ @border = options[:border]
29
+ @border = true if options[:border].nil?
30
+ @border_size = options[:border_size] || 1
31
+ @border_alpha = options[:border_alpha] || 30
32
+ @border_color = options[:border_color]
33
+
34
+ @shadow = options[:shadow]
35
+ @shadow_size = options[:shadow_size] || 2
36
+ @shadow_alpha = options[:shadow_alpha] || 30
37
+ @shadow_color = options[:shadow_color]
38
+
39
+ @textobject = check_cache(@size, @font)
40
+
41
+ if @alignment
42
+ case @alignment
43
+ when :left
44
+ @x = 0 + BUTTON_PADDING
45
+ when :center
46
+ @x = ($window.width / 2) - (@textobject.text_width(@text) / 2)
47
+ when :right
48
+ @x = $window.width - BUTTON_PADDING - @textobject.text_width(@text)
49
+ end
50
+ end
51
+ end
52
+
53
+ def check_cache(size, font_name)
54
+ available = false
55
+ font = nil
56
+
57
+ if CACHE[size]
58
+ if CACHE[size][font_name]
59
+ font = CACHE[size][font_name]
60
+ available = true
61
+ else
62
+ available = false
63
+ end
64
+ else
65
+ available = false
66
+ end
67
+
68
+ unless available
69
+ font = Gosu::Font.new(@size, name: @font)
70
+ CACHE[@size] = {} unless CACHE[@size].is_a?(Hash)
71
+ CACHE[@size][@font] = font
72
+ end
73
+
74
+ font
75
+ end
76
+
77
+ def swap_font(size, font_name = @font)
78
+ if @size != size || @font != font_name
79
+ @size = size
80
+ @font = font_name
81
+
82
+ @textobject = check_cache(size, font_name)
83
+ end
84
+ end
85
+
86
+ def text=(string)
87
+ @rendered_border = nil
88
+ @text = string
89
+ end
90
+
91
+ def factor_x=(n)
92
+ @rendered_border = nil
93
+ @factor_x = n
94
+ end
95
+
96
+ def factor_y=(n)
97
+ @rendered_border = nil
98
+ @factor_y = n
99
+ end
100
+
101
+ def color=(color)
102
+ @rendered_border = nil
103
+ if color
104
+ @color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
105
+ else
106
+ raise "color cannot be nil"
107
+ end
108
+ end
109
+
110
+ def border=(boolean)
111
+ @rendered_border = nil
112
+ @border = boolean
113
+ end
114
+
115
+ def border_size=(n)
116
+ @rendered_border = nil
117
+ @border_size = n
118
+ end
119
+
120
+ def border_alpha=(n)
121
+ @rendered_border = nil
122
+ @border_alpha = n
123
+ end
124
+
125
+ def border_color=(n)
126
+ @rendered_border = nil
127
+ @border_color = n
128
+ end
129
+
130
+ def width(text = @text)
131
+ markup_width(text)
132
+ end
133
+
134
+ def text_width(text = @text)
135
+ textobject.text_width(text) + @border_size + @shadow_size
136
+ end
137
+
138
+ def markup_width(text = @text)
139
+ textobject.markup_width(text) + @border_size + @shadow_size
140
+ end
141
+
142
+ def height(text = @text)
143
+ if text.lines.count > 0
144
+ text.lines.count * textobject.height + @border_size + @shadow_size
145
+ else
146
+ @textobject.height + @border_size + @shadow_size
147
+ end
148
+ end
149
+
150
+ def draw(method = :draw_markup)
151
+ if @border && !ARGV.join.include?("--no-border")
152
+ border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
153
+ border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
154
+ border_alpha)
155
+ white = Gosu::Color::WHITE
156
+
157
+ _x = @border_size
158
+ _y = @border_size
159
+ _width = method == :draw_markup ? text_width : markup_width
160
+
161
+ @rendered_border ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
162
+ @textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
163
+ @textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
164
+
165
+ @textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
166
+ @textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
167
+
168
+ @textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
169
+ @textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
170
+
171
+ @textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
172
+ @textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
173
+ end
174
+
175
+ @rendered_border.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
176
+ end
177
+
178
+ if @shadow
179
+ shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
180
+ @textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
181
+ end
182
+
183
+ @textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
184
+ end
185
+
186
+ def alpha=(n)
187
+ @color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n)
188
+ end
189
+
190
+ def alpha
191
+ @color.alpha
192
+ end
193
+
194
+ def update
195
+ end
196
+ end
197
+ end
@@ -1,23 +1,23 @@
1
- module CyberarmEngine
2
- class Timer
3
- def initialize(interval, looping = true, &block)
4
- @interval = interval
5
- @looping = looping
6
- @block = block
7
-
8
- @last_interval = Gosu.milliseconds
9
- @triggered = false
10
- end
11
-
12
- def update
13
- return if !@looping && @triggered
14
-
15
- if Gosu.milliseconds >= @last_interval + @interval
16
- @last_interval = Gosu.milliseconds
17
- @triggered = true
18
-
19
- @block.call if @block
20
- end
21
- end
22
- end
23
- end
1
+ module CyberarmEngine
2
+ class Timer
3
+ def initialize(interval, looping = true, &block)
4
+ @interval = interval
5
+ @looping = looping
6
+ @block = block
7
+
8
+ @last_interval = Gosu.milliseconds
9
+ @triggered = false
10
+ end
11
+
12
+ def update
13
+ return if !@looping && @triggered
14
+
15
+ if Gosu.milliseconds >= @last_interval + @interval
16
+ @last_interval = Gosu.milliseconds
17
+ @triggered = true
18
+
19
+ @block.call if @block
20
+ end
21
+ end
22
+ end
23
+ end