Module: Mouse
- Extended by:
- ArgsUpdate, Location
- Defined in:
- tomes/conjurations/mouse/mouse.rb
Overview
Mouse.update must be called every tick you wish to use this class.
A module for handling mouse input.
Instance Attribute Summary
Attributes included from Location
Class Method Summary collapse
-
.binary_signals ⇒ String
Gives an abbreviated look at which Mouse button actions are being performed.
-
.click? ⇒ Boolean
Check if the left mouse button was clicked this frame.
-
.held? ⇒ Boolean
(also: hold?)
Check if the left mouse button is being held.
-
.on?(thing) ⇒ Boolean
Checks if the Mouse cursor is intersecting a given rectangle.
-
.on_something_in?(list) ⇒ Boolean
Cycles through the given list of Objects and sees if the Mouse intersects with any of them.
-
.sees(list) ⇒ Object
Checks the given list and returns the final object with which the Mouse intersects.
-
.sees_in_list(list) ⇒ Array<Objects>
(also: sees_in)
Checks the given list and returns all of the objects with which the Mouse intersects.
-
.to_h ⇒ Hash
A hash that shows the current state of the Mouse.
-
.to_i ⇒ Integer
The current mouse state as a combined decimal/binary integer.
-
.to_s ⇒ String
A line of text that shows the current state of the Mouse.
-
.up? ⇒ Boolean
Checks if the left mouse button was released this frame.
-
.update(args) ⇒ Object
see ArgsUpdate::update Updates mouse position too.
Methods included from Location
adjust_location, location, location=
Class Method Details
.binary_signals ⇒ String
Gives an abbreviated look at which Mouse button actions are being performed.
77 78 79 80 81 82 83 |
# File 'tomes/conjurations/mouse/mouse.rb', line 77 def binary_signals click = click? ? 1 : 0 hold = hold? ? 1 : 0 up = up? ? 1 : 0 format('%d%d%d', click, hold, up) end |
.click? ⇒ Boolean
Check if the left mouse button was clicked this frame.
21 22 23 |
# File 'tomes/conjurations/mouse/mouse.rb', line 21 def click? args.inputs.mouse.click ? true : false end |
.held? ⇒ Boolean Also known as: hold?
Check if the left mouse button is being held.
27 28 29 |
# File 'tomes/conjurations/mouse/mouse.rb', line 27 def held? args.inputs.mouse.held ? true : false end |
.on?(thing) ⇒ Boolean
I cant figure out how to resolve nil errors without a ‘rescue’ statement. DragonRuby is no help in this regard either.
Checks if the Mouse cursor is intersecting a given rectangle. This method uses ‘args` to do this calculation.
44 45 46 47 48 |
# File 'tomes/conjurations/mouse/mouse.rb', line 44 def on?(thing) args.inputs.mouse.intersect_rect? thing.rect rescue StandardError false end |
.on_something_in?(list) ⇒ Boolean
Cycles through the given list of Objects and sees if the Mouse intersects with any of them.
53 54 55 |
# File 'tomes/conjurations/mouse/mouse.rb', line 53 def on_something_in?(list) list.map { |thing| on?(thing) }.include? true end |
.sees(list) ⇒ Object
Checks the given list and returns the final object with which the Mouse intersects. This works in conjunction with .sees_in_list. For example, if the cursor is over a bunch of overlapping items, the topmost of them (the last one in the ‘.sees_in_list array’) will be the one returned in this method.
63 64 65 |
# File 'tomes/conjurations/mouse/mouse.rb', line 63 def sees(list) sees_in_list(list).last end |
.sees_in_list(list) ⇒ Array<Objects> Also known as: sees_in
Checks the given list and returns all of the objects with which the Mouse intersects.
70 71 72 |
# File 'tomes/conjurations/mouse/mouse.rb', line 70 def sees_in_list(list) list.map { |thing| thing if on?(thing) }.flatten.compact end |
.to_h ⇒ Hash
A hash that shows the current state of the Mouse.
93 94 95 96 97 98 99 100 101 |
# File 'tomes/conjurations/mouse/mouse.rb', line 93 def to_h { self: 'Mouse', location: location, click: click?, down: hold?, up: up? } end |
.to_i ⇒ Integer
The current mouse state as a combined decimal/binary integer.
105 106 107 |
# File 'tomes/conjurations/mouse/mouse.rb', line 105 def to_i format('%04d%04d%s', x, y, binary_signals).to_i end |
.to_s ⇒ String
A line of text that shows the current state of the Mouse.
87 88 89 |
# File 'tomes/conjurations/mouse/mouse.rb', line 87 def to_s format('Mouse: %04d-%03d-%s', x, y, binary_signals) end |
.up? ⇒ Boolean
Checks if the left mouse button was released this frame.
34 35 36 |
# File 'tomes/conjurations/mouse/mouse.rb', line 34 def up? args.inputs.mouse.up ? true : false end |
.update(args) ⇒ Object
see ArgsUpdate::update Updates mouse position too.
13 14 15 16 17 |
# File 'tomes/conjurations/mouse/mouse.rb', line 13 def update(args) super self.x = args.inputs.mouse.x.to_i self.y = args.inputs.mouse.y.to_i end |