Class: OR2D::Console
- Inherits:
-
Object
- Object
- OR2D::Console
- Defined in:
- lib/or2d/console.rb
Overview
The Console class is used to construct Console objects that allow execution of Ruby code at runtime.
Defined Under Namespace
Classes: State
Instance Attribute Summary collapse
-
#boundary ⇒ Ruby2D::Rectangle
readonly
The boundary of the Console object.
-
#display ⇒ OR2D::Composites::Text
readonly
The display of the Console object.
Instance Method Summary collapse
-
#add_line(options) ⇒ Object
Add a line of text to the console.
-
#initialize(options = {}) ⇒ Console
constructor
Constructs a new Console object.
-
#pull_down ⇒ Object
Pulls the console into view.
-
#remove ⇒ Object
Remove the console text displays from the game instance window.
-
#retract ⇒ Object
Retracts the console from view.
-
#update ⇒ Object
Update the console.
Constructor Details
#initialize(options = {}) ⇒ Console
Constructs a new Console object.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/or2d/console.rb', line 15 def initialize( = {}) @boundary = Ruby2D::Rectangle.new(x: 0, y: -(OR2D.game.window.get(:height) / 2), z: 0, width: OR2D.game.window.get(:width), height: (OR2D.game.window.get(:height) / 2), color: 'green', opacity: 0.25) OR2D.game.window.add(@boundary) @properties = { input_size: (8 * OR2D.scale), output_size: (4 * OR2D.scale), max_length: [:max_length] || 24 } @properties[:max_lines] = (@boundary.height / (@properties[:output_size] * OR2D.scale)).to_i - @properties[:output_size] @prompt = [:prompt] || '>> ' @buffer = String.new @display = OR2D::Composites::Text.new @display.add_line(text: 'OR2D Console', color: 'yellow', size: @properties[:output_size], x: @boundary.x + 16, y: @boundary.y + (16 * OR2D.scale), z: @boundary.z + 1) @input = OR2D::Entity.new(:text, { text: @prompt, color: 'white', x: @boundary.x + 16, y: (@boundary.y + @boundary.height) - (16 * OR2D.scale), z: @boundary.z + 1, size: @properties[:input_size], show: true }) @state = State.new(:RETRACTED, false, false) setup_events end |
Instance Attribute Details
#boundary ⇒ Ruby2D::Rectangle (readonly)
Returns the boundary of the Console object.
11 12 13 |
# File 'lib/or2d/console.rb', line 11 def boundary @boundary end |
#display ⇒ OR2D::Composites::Text (readonly)
Returns the display of the Console object.
7 8 9 |
# File 'lib/or2d/console.rb', line 7 def display @display end |
Instance Method Details
#add_line(options) ⇒ Object
Add a line of text to the console.
40 41 42 |
# File 'lib/or2d/console.rb', line 40 def add_line() @display.add_line(.merge(size: @properties[:output_size])) end |
#pull_down ⇒ Object
Pulls the console into view.
87 88 89 |
# File 'lib/or2d/console.rb', line 87 def pull_down @state.animation = :PULL_DOWN end |
#remove ⇒ Object
Remove the console text displays from the game instance window.
45 46 47 48 49 50 |
# File 'lib/or2d/console.rb', line 45 def remove @input.destroy @display.destroy OR2D.game.window.remove(@boundary) @descriptors.each_value { |descriptor| OR2D.game.window.off(descriptor) } end |
#retract ⇒ Object
Retracts the console from view.
82 83 84 |
# File 'lib/or2d/console.rb', line 82 def retract @state.animation = :RETRACTED end |
#update ⇒ Object
Update the console.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/or2d/console.rb', line 53 def update case @state.animation when :RETRACTED if @boundary.y >= -@boundary.height @boundary.y -= 16 @input.y -= 16 @display.y -= 16 unless @display.empty? else @state.animation = :DRAWN @state.drawn = false end when :PULL_DOWN if @boundary.y <= -16 * OR2D.scale @boundary.y += 16 @input.y += 16 @display.y += 16 unless @display.empty? else @state.animation = :DRAWN @state.drawn = true end end @display.update @display.remove_layer(@display.layers.keys.first) if @display.layers.length > @properties[:max_lines] @input.resource.text = @prompt + @buffer if @state.drawn OR2D.game.window.add(@boundary) end |