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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48b0f91fa28c566c872aa5fba6fcc3e34d68a1e6df80eb33ec9ae1d229780c91
4
- data.tar.gz: df059b7335fac48a38654ab85d271b096d010e2f6f0e6cb64a96d8b086883799
3
+ metadata.gz: 4e15d8c26add752089d8bbb987a972eba0b31ab9d10d4be4ac099b31f9024f77
4
+ data.tar.gz: d0878961c7d198042628ef9bfeb70878e0126069ce5c7f090a7204d48a600769
5
5
  SHA512:
6
- metadata.gz: '090c7d78a563a9d4c12ec886c6a42ecdef0feab89d98f5a395bdd7b03e9de0f837725e25aeeba03ff754194ed422bef1b732e391e6961d571e2688e035dbdabc'
7
- data.tar.gz: 845517dfb3f09c58b4787c3b71a901f95382cccf71c68fc59e7434f4a8e9430b61513413886fc98c9379a6170d66e577deaa5196cc67355a2495f732bd2ea295
6
+ metadata.gz: f5631aec0254e27e51dc112c6ca68b0f1cb29003e365835a1f75357d6944e4f6524aa751eeb4ad815b13c27272ae277c10c798fc89b5fb5712437528f2d5dbea
7
+ data.tar.gz: 5789b5600b6a14174416632ba11d23b97739dd813d74bb35d18b8d211490c7d87e572e3e1284e1facfc3ac3994f80b6db45f7abb7e4cf73ab3f3f48a407ee9c4
@@ -1,4 +1,10 @@
1
- require "gosu"
1
+ begin
2
+ require File.expand_path("../../ffi-gosu/lib/gosu", File.dirname(__FILE__))
3
+ rescue LoadError => e
4
+ pp e
5
+ require "gosu"
6
+ end
7
+
2
8
 
3
9
  require_relative "cyberarm_engine/version"
4
10
 
@@ -1,5 +1,3 @@
1
- require "gosu"
2
-
3
1
  module CyberarmEngine
4
2
  class Background
5
3
  attr_accessor :x, :y, :z, :width, :height, :angle, :debug
@@ -1,50 +1,50 @@
1
1
  module CyberarmEngine
2
2
  module Common
3
3
  def push_state(klass, options={})
4
- $window.push_state(klass, options)
4
+ window.push_state(klass, options)
5
5
  end
6
6
 
7
7
  def current_state
8
- $window.current_state
8
+ window.current_state
9
9
  end
10
10
 
11
11
  def previous_state
12
- $window.previous_state
12
+ window.previous_state
13
13
  end
14
14
 
15
15
  def pop_state
16
- $window.pop_state
16
+ window.pop_state
17
17
  end
18
18
 
19
19
  def show_cursor
20
- $window.show_cursor
20
+ window.show_cursor
21
21
  end
22
22
 
23
23
  def show_cursor=boolean
24
- $window.show_cursor = boolean
24
+ window.show_cursor = boolean
25
25
  end
26
26
 
27
27
  def draw_rect(x, y, width, height, color, z = 0)
28
- $window.draw_rect(x,y,width,height,color,z)
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, $window.width, $window.height, color, z)
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
@@ -155,7 +155,7 @@ module CyberarmEngine
155
155
  def button_up(id)
156
156
  end
157
157
 
158
- def button_down?(id)
158
+ def button_down(id)
159
159
  end
160
160
 
161
161
  def find_closest(game_object_class)
@@ -12,8 +12,6 @@ module CyberarmEngine
12
12
  $window.text_input = nil unless options[:preserve_text_input]
13
13
 
14
14
  @down_keys = {}
15
-
16
- setup
17
15
  end
18
16
 
19
17
  def setup
@@ -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 = -Float::INFINITY
24
- tmax = Float::INFINITY
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
@@ -19,6 +19,8 @@ module CyberarmEngine
19
19
 
20
20
  def clicked_left_mouse_button(sender, x, y)
21
21
  @block.call(self) if @block
22
+
23
+ return :handled
22
24
  end
23
25
 
24
26
  def recalculate
@@ -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
 
@@ -24,6 +24,8 @@ module CyberarmEngine
24
24
  toggle
25
25
 
26
26
  @block.call(self) if @block
27
+
28
+ return :handled
27
29
  end
28
30
 
29
31
  def toggle
@@ -22,8 +22,6 @@ module CyberarmEngine
22
22
  @mouse_down_on = {}
23
23
  @mouse_down_position = {}
24
24
  @pending_recalculate_request = false
25
-
26
- setup
27
25
  end
28
26
 
29
27
  # throws :blur event to focused element and sets GuiState focused element
@@ -1,4 +1,4 @@
1
1
  module CyberarmEngine
2
2
  NAME = "InDev"
3
- VERSION = "0.10.2"
3
+ VERSION = "0.11.0"
4
4
  end
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.10.2
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-08-13 00:00:00.000000000 Z
11
+ date: 2019-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu