Class: Alchemist::Curses::GeographyWindow
- Includes:
- FFI::NCurses
- Defined in:
- lib/alchemist-server/curses/geography_window.rb
Instance Method Summary collapse
- #avatar_at?(x, y) ⇒ Boolean
- #draw ⇒ Object
- #draw_colored_data(data) ⇒ Object
-
#initialize(line, col, avatar_color_num = nil) ⇒ GeographyWindow
constructor
A new instance of GeographyWindow.
- #move_to_avatar_position ⇒ Object
- #update(location, data) ⇒ Object
- #update_avatar(name, x, y) ⇒ Object
- #update_avatars(avatars) ⇒ Object
Constructor Details
#initialize(line, col, avatar_color_num = nil) ⇒ GeographyWindow
Returns a new instance of GeographyWindow.
6 7 8 9 10 11 12 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 6 def initialize(line, col, avatar_color_num = nil) @win = newwin 20, 43, line, col @avatar_color_num = avatar_color_num @avatars = {} @loc_x, @loc_y = nil @data = '' end |
Instance Method Details
#avatar_at?(x, y) ⇒ Boolean
35 36 37 38 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 35 def avatar_at?(x,y) @avatars.values.include? [x + (@loc_x - 10), y + (@loc_y - 10)] end |
#draw ⇒ Object
14 15 16 17 18 19 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 14 def draw wclear @win wmove @win, 0, 0 draw_colored_data @data.force_encoding Encoding::UTF_8 move_to_avatar_position end |
#draw_colored_data(data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 21 def draw_colored_data(data) data.each_line.with_index do |line, y| line.each_char.with_index do |c, x| if @avatar_color_num && avatar_at?(x, y) wattr_set @win, A_NORMAL, @avatar_color_num, nil else wattr_set @win, A_NORMAL, 0, nil end wprintw @win, c.pad_to_unicode_monospace end end end |
#move_to_avatar_position ⇒ Object
56 57 58 59 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 56 def move_to_avatar_position wmove @win, 10, 20 wrefresh @win end |
#update(location, data) ⇒ Object
40 41 42 43 44 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 40 def update(location, data) @loc_x, @loc_y = location @data = data draw end |
#update_avatar(name, x, y) ⇒ Object
46 47 48 49 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 46 def update_avatar(name, x, y) @avatars[name] = [x,y] draw end |
#update_avatars(avatars) ⇒ Object
51 52 53 54 |
# File 'lib/alchemist-server/curses/geography_window.rb', line 51 def update_avatars(avatars) @avatars = avatars.dup draw end |