Skip to content

Commit

Permalink
Moved system behaviour from Console to System.
Browse files Browse the repository at this point in the history
Moved several methods that had nothing to do with being a rectanlge of
cells from the console class to the system module.

Added some attribute accessors to the system module (e.g. title and
fullscreen).

Changed some of the formatting to be more compliant to the community
style guide.
  • Loading branch information
Remco Peereboom committed Jul 2, 2015
1 parent 66a1cd0 commit 205b188
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/libtcod/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,25 @@ def initialize(width, height)
@height = h
@ptr = TCOD.console_new(w, h)

# Note: We don't need to define a finalizer for the root console!
ObjectSpace.define_finalizer(self, self.class.finalize(ptr))
end

def root?
false
end

def set_fullscreen(bool); TCOD.console_set_fullscreen(bool); end
def is_fullscreen?; TCOD.console_is_fullscreen; end
def window_closed?; TCOD.console_is_window_closed; end
def set_custom_font(fontFile, flags, nb_char_horiz=0, nb_char_vertic=0)
TCOD.console_set_custom_font(fontFile, flags, nb_char_horiz, nb_char_vertic)
end
def map_ascii_code_to_font(asciiCode, fontCharX, fontCharY)
TCOD.console_map_ascii_code_to_font(asciiCode.ord, fontCharX, fontCharY)
end
def map_ascii_codes_to_font(asciiCode, nbCodes, fontCharX, fontCharY)
TCOD.console_map_ascii_code_to_font(asciiCode.ord, nbCodes, fontCharX, fontCharY)
def set_default_background(color)
TCOD.console_set_default_background(@ptr, color)
end

def set_default_foreground(color)
TCOD.console_set_default_foreground(@ptr, color)
end

def set_default_background(color); TCOD.console_set_default_background(@ptr, color); end
def set_default_foreground(color); TCOD.console_set_default_foreground(@ptr, color); end
def clear; TCOD.console_clear(@ptr); end
def clear
TCOD.console_clear(@ptr)
end

def set_char_background(x, y, col, flag=TCOD::BKGND_SET)
TCOD.console_set_char_background(@ptr, x, y, col, flag)
Expand All @@ -47,33 +42,38 @@ def set_char_foreground(x, y, col)
def put_char(x, y, c, flag=BKGND_DEFAULT)
TCOD.console_put_char(@ptr, x, y, c.ord, flag)
end

def put_char_ex(x, y, c, foreground, background)
TCOD.console_put_char_ex(@ptr, x, y, c.ord, foreground, background)
end

def set_background_flag(bkgnd_flag)
TCOD.console_set_background_flag(@ptr, bkgnd_flag)
end

def set_alignment(alignment)
TCOD.console_set_alignment(@ptr, alignment)
end

def print(x, y, fmt, *args)
TCOD.console_print(@ptr, x, y, fmt, *args)
end

def print_ex(x, y, bkgnd_flag, alignment, fmt, *args)
TCOD.console_print_ex(@ptr, x, y, bkgnd_flag, alignment, fmt, *args)
end

def print_rect(x, y, w, h, fmt, *args)
TCOD.console_print_rect(@ptr, x, y, w, h, fmt, *args)
end

def print_rect_ex(x, y, w, h, bkgnd_flag, alignment, fmt, *args)
TCOD.console_print_rect_ex(@ptr, x, y, w, h, bkgnf_flag, alignment, fmt, *args)
end

def flush; TCOD.console_flush; end

def check_for_keypress(flags=TCOD::KEY_PRESSED); TCOD.console_check_for_keypress(flags); end
def wait_for_keypress(flush=false); TCOD.console_wait_for_keypress(flush); end
def key_pressed?(keycode); TCOD.console_is_key_pressed(keycode); end
def flush
TCOD.console_flush
end

def blit(src, xSrc, ySrc, wSrc, hSrc, xDst, yDst, foregroundAlpha=1.0, backgroundAlpha=1.0)
TCOD.console_blit(src.ptr, xSrc, ySrc, wSrc, hSrc, @ptr, xDst, yDst, foregroundAlpha, backgroundAlpha)
Expand Down
46 changes: 46 additions & 0 deletions lib/libtcod/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,51 @@ def self.title=(new_title)
@title = new_title
TCOD.console_set_window_title(new_title)
end

def self.fullscreen?
@fullscreen
end

def self.to_fullscreen
@fullscreen = true
TCOD.console_set_fullscreen(true)
end

def self.to_windowed
@fullscreen = false
TCOD.console_set_fullscreen(false)
end

def self.window_closed?
TCOD.console_is_window_closed
end

def self.flush
TCOD.console_flush
end

def self.check_for_keypress(flags = TCOD::KEY_PRESSED)
TCOD.console_check_for_keypress(flags)
end

def self.wait_for_keypress(flush = false)
TCOD.console_wait_for_keypress(flush)
end

def self.key_pressed?(keycode)
TCOD.console_is_key_pressed(keycode)
end

def self.set_custom_font(font_file, flags, columns = 0, rows = 0)
TCOD.console_set_custom_font(font_file, flags, columns, rows)
end

def self.map_ascii_code_to_font(ascii_code, coord)
TCOD.console_map_ascii_code_to_font(ascii_code.ord, coord.x, coord.y)
end

def self.map_ascii_codes_to_font(ascii_code, n, offset)
TCOD.console_map_ascii_code_to_font(ascii_code.ord, n, offset.x, offset.y)
end
end
end

0 comments on commit 205b188

Please sign in to comment.