cyberarm_engine 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cyberarm_engine.rb +7 -1
- data/lib/cyberarm_engine/background.rb +0 -2
- data/lib/cyberarm_engine/common.rb +13 -13
- data/lib/cyberarm_engine/engine.rb +5 -1
- data/lib/cyberarm_engine/game_object.rb +1 -1
- data/lib/cyberarm_engine/game_state.rb +0 -2
- data/lib/cyberarm_engine/lib/bounding_box.rb +12 -12
- data/lib/cyberarm_engine/lib/ray.rb +4 -3
- data/lib/cyberarm_engine/lib/vector.rb +28 -0
- data/lib/cyberarm_engine/ui/element.rb +3 -3
- data/lib/cyberarm_engine/ui/elements/button.rb +12 -0
- data/lib/cyberarm_engine/ui/elements/container.rb +3 -0
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +8 -0
- data/lib/cyberarm_engine/ui/elements/image.rb +2 -0
- data/lib/cyberarm_engine/ui/elements/label.rb +5 -0
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +2 -0
- data/lib/cyberarm_engine/ui/gui_state.rb +0 -2
- data/lib/cyberarm_engine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e15d8c26add752089d8bbb987a972eba0b31ab9d10d4be4ac099b31f9024f77
|
4
|
+
data.tar.gz: d0878961c7d198042628ef9bfeb70878e0126069ce5c7f090a7204d48a600769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5631aec0254e27e51dc112c6ca68b0f1cb29003e365835a1f75357d6944e4f6524aa751eeb4ad815b13c27272ae277c10c798fc89b5fb5712437528f2d5dbea
|
7
|
+
data.tar.gz: 5789b5600b6a14174416632ba11d23b97739dd813d74bb35d18b8d211490c7d87e572e3e1284e1facfc3ac3994f80b6db45f7abb7e4cf73ab3f3f48a407ee9c4
|
data/lib/cyberarm_engine.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
module CyberarmEngine
|
2
2
|
module Common
|
3
3
|
def push_state(klass, options={})
|
4
|
-
|
4
|
+
window.push_state(klass, options)
|
5
5
|
end
|
6
6
|
|
7
7
|
def current_state
|
8
|
-
|
8
|
+
window.current_state
|
9
9
|
end
|
10
10
|
|
11
11
|
def previous_state
|
12
|
-
|
12
|
+
window.previous_state
|
13
13
|
end
|
14
14
|
|
15
15
|
def pop_state
|
16
|
-
|
16
|
+
window.pop_state
|
17
17
|
end
|
18
18
|
|
19
19
|
def show_cursor
|
20
|
-
|
20
|
+
window.show_cursor
|
21
21
|
end
|
22
22
|
|
23
23
|
def show_cursor=boolean
|
24
|
-
|
24
|
+
window.show_cursor = boolean
|
25
25
|
end
|
26
26
|
|
27
27
|
def draw_rect(x, y, width, height, color, z = 0)
|
28
|
-
|
28
|
+
Gosu.draw_rect(x, y, width, height, color, z)
|
29
29
|
end
|
30
30
|
|
31
31
|
def fill(color, z = 0)
|
32
|
-
draw_rect(0, 0,
|
32
|
+
draw_rect(0, 0, window.width, window.height, color, z)
|
33
33
|
end
|
34
34
|
|
35
35
|
def lighten(color, amount = 25)
|
36
36
|
if defined?(color.alpha)
|
37
|
-
return Gosu::Color.rgba(color.red+amount, color.green+amount, color.blue+amount, color.alpha)
|
37
|
+
return Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
|
38
38
|
else
|
39
|
-
return Gosu::Color.rgb(color.red+amount, color.green+amount, color.blue+amount)
|
39
|
+
return Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def darken(color, amount = 25)
|
44
44
|
if defined?(color.alpha)
|
45
|
-
return Gosu::Color.rgba(color.red-amount, color.green-amount, color.blue-amount, color.alpha)
|
45
|
+
return Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
|
46
46
|
else
|
47
|
-
return Gosu::Color.rgb(color.red-amount, color.green-amount, color.blue-amount)
|
47
|
+
return Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -88,4 +88,4 @@ module CyberarmEngine
|
|
88
88
|
$window
|
89
89
|
end
|
90
90
|
end
|
91
|
-
end
|
91
|
+
end
|
@@ -58,11 +58,15 @@ module CyberarmEngine
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def push_state(klass, options={})
|
61
|
+
options = {setup: true}.merge(options)
|
62
|
+
|
61
63
|
if klass.instance_of?(klass.class) && defined?(klass.options)
|
62
64
|
@states << klass
|
65
|
+
klass.setup if options[:setup]
|
63
66
|
else
|
64
67
|
@states << klass.new(options) if child_of?(klass, GameState)
|
65
68
|
@states << klass.new if child_of?(klass, Element::Container)
|
69
|
+
current_state.setup if current_state.class == klass && options[:setup]
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
@@ -94,4 +98,4 @@ module CyberarmEngine
|
|
94
98
|
end
|
95
99
|
end
|
96
100
|
end
|
97
|
-
end
|
101
|
+
end
|
@@ -93,26 +93,26 @@ module CyberarmEngine
|
|
93
93
|
|
94
94
|
def normalize(entity)
|
95
95
|
temp = BoundingBox.new
|
96
|
-
temp.min.x = @min.x.to_f * entity.scale
|
97
|
-
temp.min.y = @min.y.to_f * entity.scale
|
98
|
-
temp.min.z = @min.z.to_f * entity.scale
|
96
|
+
temp.min.x = @min.x.to_f * entity.scale.x
|
97
|
+
temp.min.y = @min.y.to_f * entity.scale.y
|
98
|
+
temp.min.z = @min.z.to_f * entity.scale.z
|
99
99
|
|
100
|
-
temp.max.x = @max.x.to_f * entity.scale
|
101
|
-
temp.max.y = @max.y.to_f * entity.scale
|
102
|
-
temp.max.z = @max.z.to_f * entity.scale
|
100
|
+
temp.max.x = @max.x.to_f * entity.scale.x
|
101
|
+
temp.max.y = @max.y.to_f * entity.scale.y
|
102
|
+
temp.max.z = @max.z.to_f * entity.scale.z
|
103
103
|
|
104
104
|
return temp
|
105
105
|
end
|
106
106
|
|
107
107
|
def normalize_with_offset(entity)
|
108
108
|
temp = BoundingBox.new
|
109
|
-
temp.min.x = @min.x.to_f * entity.scale + entity.position.x
|
110
|
-
temp.min.y = @min.y.to_f * entity.scale + entity.position.y
|
111
|
-
temp.min.z = @min.z.to_f * entity.scale + entity.position.z
|
109
|
+
temp.min.x = @min.x.to_f * entity.scale.x + entity.position.x
|
110
|
+
temp.min.y = @min.y.to_f * entity.scale.y + entity.position.y
|
111
|
+
temp.min.z = @min.z.to_f * entity.scale.z + entity.position.z
|
112
112
|
|
113
|
-
temp.max.x = @max.x.to_f * entity.scale + entity.position.x
|
114
|
-
temp.max.y = @max.y.to_f * entity.scale + entity.position.y
|
115
|
-
temp.max.z = @max.z.to_f * entity.scale + entity.position.z
|
113
|
+
temp.max.x = @max.x.to_f * entity.scale.x + entity.position.x
|
114
|
+
temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
|
115
|
+
temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
|
116
116
|
|
117
117
|
return temp
|
118
118
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module CyberarmEngine
|
2
2
|
class Ray
|
3
|
-
def initialize(origin, direction)
|
3
|
+
def initialize(origin, direction, range = Float::INFINITY)
|
4
4
|
raise "Origin must be a Vector!" unless origin.is_a?(Vector)
|
5
5
|
raise "Direction must be a Vector!" unless direction.is_a?(Vector)
|
6
6
|
|
7
7
|
@origin = origin
|
8
8
|
@direction = direction
|
9
|
+
@range = range
|
9
10
|
|
10
11
|
@inverse_direction = @direction.inverse
|
11
12
|
end
|
@@ -20,8 +21,8 @@ module CyberarmEngine
|
|
20
21
|
|
21
22
|
# Based on: https://tavianator.com/fast-branchless-raybounding-box-intersections/
|
22
23
|
def intersect_bounding_box?(box)
|
23
|
-
tmin =
|
24
|
-
tmax =
|
24
|
+
tmin = -@range
|
25
|
+
tmax = @range
|
25
26
|
|
26
27
|
tx1 = (box.min.x - @origin.x) * @inverse_direction.x
|
27
28
|
tx2 = (box.max.x - @origin.x) * @inverse_direction.x
|
@@ -1,5 +1,29 @@
|
|
1
1
|
module CyberarmEngine
|
2
2
|
class Vector
|
3
|
+
def self.up
|
4
|
+
Vector.new(0, 1, 0)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
Vector.new(0, -1, 0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.left
|
12
|
+
Vector.new(-1, 0, 0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.right
|
16
|
+
Vector.new(1, 0, 0)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.forward
|
20
|
+
Vector.new(0, 0, 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.backward
|
24
|
+
Vector.new(0, 0, -1)
|
25
|
+
end
|
26
|
+
|
3
27
|
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
4
28
|
@x, @y, @z, @weight = x, y, z, weight
|
5
29
|
end
|
@@ -138,6 +162,10 @@ module CyberarmEngine
|
|
138
162
|
@x + @y + @z
|
139
163
|
end
|
140
164
|
|
165
|
+
def lerp(other, factor)
|
166
|
+
(self - other) * factor.clamp(0.0, 1.0)
|
167
|
+
end
|
168
|
+
|
141
169
|
# 2D distance using X and Y
|
142
170
|
def distance(other)
|
143
171
|
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2)
|
@@ -32,6 +32,9 @@ module CyberarmEngine
|
|
32
32
|
@style.width = default(:width) || nil
|
33
33
|
@style.height = default(:height) || nil
|
34
34
|
|
35
|
+
@style.background_canvas = Background.new
|
36
|
+
@style.border_canvas = BorderCanvas.new(element: self)
|
37
|
+
|
35
38
|
stylize
|
36
39
|
|
37
40
|
default_events
|
@@ -44,9 +47,6 @@ module CyberarmEngine
|
|
44
47
|
|
45
48
|
set_margin(@style.margin)
|
46
49
|
|
47
|
-
@style.background_canvas = Background.new
|
48
|
-
@style.border_canvas = BorderCanvas.new(element: self)
|
49
|
-
|
50
50
|
set_background(@style.background)
|
51
51
|
set_border_color(@style.border_color)
|
52
52
|
end
|
@@ -25,6 +25,8 @@ module CyberarmEngine
|
|
25
25
|
@style.background_canvas.background = default(:hover, :background)
|
26
26
|
@text.color = default(:hover, :color)
|
27
27
|
end
|
28
|
+
|
29
|
+
return :handled
|
28
30
|
end
|
29
31
|
|
30
32
|
def left_mouse_button(sender, x, y)
|
@@ -32,23 +34,33 @@ module CyberarmEngine
|
|
32
34
|
@style.background_canvas.background = default(:active, :background)
|
33
35
|
window.current_state.focus = self
|
34
36
|
@text.color = default(:active, :color)
|
37
|
+
|
38
|
+
return :handled
|
35
39
|
end
|
36
40
|
|
37
41
|
def released_left_mouse_button(sender,x, y)
|
38
42
|
enter(sender)
|
43
|
+
|
44
|
+
return :handled
|
39
45
|
end
|
40
46
|
|
41
47
|
def clicked_left_mouse_button(sender, x, y)
|
42
48
|
@block.call(self) if @block
|
49
|
+
|
50
|
+
return :handled
|
43
51
|
end
|
44
52
|
|
45
53
|
def leave(sender)
|
46
54
|
@style.background_canvas.background = default(:background)
|
47
55
|
@text.color = default(:color)
|
56
|
+
|
57
|
+
return :handled
|
48
58
|
end
|
49
59
|
|
50
60
|
def blur(sender)
|
51
61
|
@focus = false
|
62
|
+
|
63
|
+
return :handled
|
52
64
|
end
|
53
65
|
end
|
54
66
|
end
|
@@ -67,8 +67,11 @@ module CyberarmEngine
|
|
67
67
|
@width = @style.width = window.width
|
68
68
|
@height = @style.height = window.height
|
69
69
|
else
|
70
|
+
@width, @height = 0, 0
|
71
|
+
|
70
72
|
_width = dimensional_size(@style.width, :width)
|
71
73
|
_height= dimensional_size(@style.height,:height)
|
74
|
+
|
72
75
|
@width = _width ? _width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
|
73
76
|
@height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
|
74
77
|
end
|
@@ -46,6 +46,8 @@ module CyberarmEngine
|
|
46
46
|
|
47
47
|
@caret_last_interval = Gosu.milliseconds
|
48
48
|
@show_caret = true
|
49
|
+
|
50
|
+
return :handled
|
49
51
|
end
|
50
52
|
|
51
53
|
def enter(sender)
|
@@ -56,12 +58,16 @@ module CyberarmEngine
|
|
56
58
|
@style.background_canvas.background = default(:hover, :background)
|
57
59
|
@text.color = default(:hover, :color)
|
58
60
|
end
|
61
|
+
|
62
|
+
return :handled
|
59
63
|
end
|
60
64
|
|
61
65
|
def leave(sender)
|
62
66
|
unless @focus
|
63
67
|
super
|
64
68
|
end
|
69
|
+
|
70
|
+
return :handled
|
65
71
|
end
|
66
72
|
|
67
73
|
def blur(sender)
|
@@ -69,6 +75,8 @@ module CyberarmEngine
|
|
69
75
|
@style.background_canvas.background = default(:background)
|
70
76
|
@text.color = default(:color)
|
71
77
|
window.text_input = nil
|
78
|
+
|
79
|
+
return :handled
|
72
80
|
end
|
73
81
|
|
74
82
|
# TODO: Fix caret rendering in wrong position unless caret_pos is at end of text
|
@@ -13,11 +13,16 @@ module CyberarmEngine
|
|
13
13
|
|
14
14
|
def clicked_left_mouse_button(sender, x, y)
|
15
15
|
@block.call(self) if @block
|
16
|
+
|
17
|
+
return :handled
|
16
18
|
end
|
17
19
|
|
18
20
|
def recalculate
|
21
|
+
@width, @height = 0, 0
|
22
|
+
|
19
23
|
_width = dimensional_size(@style.width, :width)
|
20
24
|
_height= dimensional_size(@style.height,:height)
|
25
|
+
|
21
26
|
@width = _width ? _width : @text.width.round
|
22
27
|
@height= _height ? _height : @text.height.round
|
23
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyberarm_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyberarm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|